MOLoginPasswordVC.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. //
  2. // MOLoginPasswordVC.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/6/4.
  6. //
  7. #import "MOLoginPasswordVC.h"
  8. #import "UIImage+YYAdd.h"
  9. #import "MOSelectPartitionVC.h"
  10. #import "MOThirdPartyLoginView.h"
  11. #import "NSString+YYAdd.h"
  12. #import "MOLoginManager.h"
  13. #import "MOBingMobileVC.h"
  14. #import "UITextField+CustomClearButton.h"
  15. @interface MOLoginPasswordVC ()
  16. @property (nonatomic, strong) UIImageView *bgImgView;
  17. @property (nonatomic, strong) BigBtn *backButton;
  18. @property (nonatomic, strong) UILabel *titleLabel;
  19. @property (nonatomic, strong) UILabel *subTitleLabel;
  20. @property (nonatomic, strong) UIImageView *phoneView;
  21. @property (nonatomic, strong) UIButton *chooseCountryBtn;
  22. @property (nonatomic, strong) UITextField *phoneField;
  23. @property (nonatomic, strong) UIImageView *passwordView;
  24. @property (nonatomic, strong) UITextField *passwordField;
  25. @property (nonatomic, strong) UIButton *eyeButton;
  26. @property (nonatomic, strong) UIButton *loginButton;
  27. @property (nonatomic, strong) UIButton *codeLoginButton;
  28. @property (nonatomic, strong) UIButton *forgetButton;
  29. @property (nonatomic, strong) UILabel *loginTypeLabel;
  30. @property (nonatomic, strong) MOThirdPartyLoginView *loginTypeView;
  31. /** 是否越狱 */
  32. @property (nonatomic, assign) BOOL isRootMobile;
  33. /** 是否虚拟设备 */
  34. @property (nonatomic, assign) BOOL isVirtual;
  35. @end
  36. @implementation MOLoginPasswordVC
  37. - (void)viewWillAppear:(BOOL)animated {
  38. [super viewWillAppear:animated];
  39. [self.navigationController setNavigationBarHidden:YES animated:animated];
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. [self setupUI];
  44. self.isRootMobile = [SecurityBridge isJailbroken];//是否越狱
  45. self.isVirtual = [SecurityBridge isRunningInEmulator];//是否虚拟机
  46. }
  47. - (void)setupUI {
  48. [self.view addSubview:self.bgImgView];
  49. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.edges.mas_equalTo(0);
  51. }];
  52. [self.view addSubview:self.backButton];
  53. [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(kTopSafeAreaInset + 10);
  55. make.left.mas_equalTo(12);
  56. make.size.mas_equalTo(CGSizeMake(30, 30));
  57. }];
  58. [self.view addSubview:self.titleLabel];
  59. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.backButton.mas_bottom).offset(36);
  61. make.left.mas_equalTo(24);
  62. make.right.mas_equalTo(-15);
  63. }];
  64. [self.view addSubview:self.subTitleLabel];
  65. [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
  67. make.left.mas_equalTo(24);
  68. make.right.mas_equalTo(-15);
  69. }];
  70. [self.view addSubview:self.phoneView];
  71. [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.equalTo(self.subTitleLabel.mas_bottom).offset(24);
  73. make.left.mas_equalTo(24);
  74. make.right.mas_equalTo(-24);
  75. make.height.mas_equalTo(52);
  76. }];
  77. [self.view addSubview:self.passwordView];
  78. [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self.phoneView.mas_bottom).offset(16);
  80. make.left.mas_equalTo(24);
  81. make.right.mas_equalTo(-24);
  82. make.height.mas_equalTo(52);
  83. }];
  84. [self.view addSubview:self.loginButton];
  85. [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(self.phoneView.mas_bottom).offset(92);
  87. make.left.mas_equalTo(24);
  88. make.right.mas_equalTo(-24);
  89. }];
  90. [self.view addSubview:self.codeLoginButton];
  91. [self.codeLoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(self.loginButton.mas_bottom).offset(10);
  93. make.left.mas_equalTo(24);
  94. }];
  95. [self.view addSubview:self.forgetButton];
  96. [self.forgetButton mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.equalTo(self.loginButton.mas_bottom).offset(10);
  98. make.right.mas_equalTo(-24);
  99. }];
  100. [self.view addSubview:self.loginTypeView];
  101. [self.loginTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.bottom.mas_equalTo(-kBottomSafeAreaInset - 16);
  103. make.centerX.mas_equalTo(0);
  104. make.height.mas_equalTo(42);
  105. }];
  106. [self.view addSubview:self.loginTypeLabel];
  107. [self.loginTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.centerX.mas_equalTo(0);
  109. make.bottom.equalTo(self.loginTypeView.mas_top).offset(-20);
  110. }];
  111. }
  112. #pragma mark - Actions
  113. - (void)phoneFieldDidChange:(UITextField *)textField {
  114. [self updateLoginButtonState];
  115. }
  116. - (void)passwordFieldDidChange:(UITextField *)textField {
  117. [self updateLoginButtonState];
  118. }
  119. /// 根据手机号和密码内容更新登录按钮状态
  120. - (void)updateLoginButtonState {
  121. BOOL phoneNotEmpty = self.phoneField.text.length > 0;
  122. BOOL passwordNotEmpty = self.passwordField.text.length > 0;
  123. // self.loginButton.enabled = phoneNotEmpty && passwordNotEmpty;
  124. self.loginButton.alpha = phoneNotEmpty && passwordNotEmpty ? 1.0 : 0.5;
  125. }
  126. - (void)forgetButtonAction {
  127. MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
  128. vc.forgetPwd = YES;
  129. [self.navigationController pushViewController:vc animated:YES];
  130. // if(self.phoneField.text.length == 0) {
  131. // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  132. // return;
  133. // }
  134. //
  135. // MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
  136. // vc.code = self.chooseCountryBtn.titleLabel.text;
  137. // vc.num = self.phoneField.text;
  138. // vc.vcType = MOEnterCodePasswordType;
  139. // [self.navigationController pushViewController:vc animated:YES];
  140. }
  141. - (void)backButtonAction {
  142. [self.navigationController popViewControllerAnimated:YES];
  143. }
  144. - (void)codeLoginButtonAction {
  145. [self.navigationController popViewControllerAnimated:YES];
  146. }
  147. - (void)chooseCountryBtnAction {
  148. MOSelectPartitionVC *vc = [[MOSelectPartitionVC alloc] init];
  149. //MARK: 选择区号回调
  150. WEAKSELF
  151. vc.selectCellBlock = ^(MOCountryList * _Nonnull model) {
  152. CGFloat textWidth = model.num.length * 15 + 8;
  153. [self.chooseCountryBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  154. make.width.mas_equalTo(textWidth);
  155. }];
  156. [weakSelf.chooseCountryBtn setTitle:model.num forState:UIControlStateNormal];
  157. if (weakSelf.chooseBlock) {
  158. weakSelf.chooseBlock(model.num);
  159. }
  160. };
  161. [self.navigationController pushViewController:vc animated:YES];
  162. }
  163. - (void)eyeButtonAction {
  164. self.eyeButton.selected = !self.eyeButton.isSelected;
  165. if (self.eyeButton.isSelected) {//密码可见
  166. self.passwordField.secureTextEntry = NO;
  167. } else {//不可见
  168. self.passwordField.secureTextEntry = YES;
  169. }
  170. }
  171. - (void)loginButtonAction {
  172. if(self.phoneField.text.length == 0) {
  173. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  174. return;
  175. }
  176. if(self.passwordField.text.length == 0) {
  177. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_password")];
  178. return;
  179. }
  180. [MBProgressHUD showActivityMessageInView:@""];
  181. WEAKSELF
  182. NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
  183. @"num":self.phoneField.text};
  184. NSString *pswStr = [self.passwordField.text md5String];
  185. NSDictionary *dict = @{@"mobile":mobileDict,
  186. @"pwd":pswStr,
  187. @"root":@(weakSelf.isRootMobile),
  188. @"virtual":@(weakSelf.isVirtual)};
  189. [[MOLoginManager shareManager] loginByPasswordWithDict:dict];
  190. }
  191. - (UIImageView *)bgImgView {
  192. if (!_bgImgView) {
  193. _bgImgView = [[UIImageView alloc] init];
  194. _bgImgView.image = [UIImage imageNamed:@"img_login_bg"];
  195. }
  196. return _bgImgView;
  197. }
  198. - (BigBtn *)backButton {
  199. if (!_backButton) {
  200. _backButton = [[BigBtn alloc] init];
  201. [_backButton setImage:[UIImage imageNamed:@"icon_login_back_white"] forState:UIControlStateNormal];
  202. [_backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
  203. }
  204. return _backButton;
  205. }
  206. - (UILabel *)titleLabel {
  207. if (!_titleLabel) {
  208. _titleLabel = [[UILabel alloc] init];
  209. _titleLabel.text = NSLocalString(@"mimo_login_title");
  210. _titleLabel.font = [MOTextTools poppinsBoldFont:24];
  211. _titleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  212. _titleLabel.numberOfLines = 1;
  213. _titleLabel.adjustsFontSizeToFitWidth = YES;
  214. }
  215. return _titleLabel;
  216. }
  217. - (UILabel *)subTitleLabel {
  218. if (!_subTitleLabel) {
  219. _subTitleLabel = [[UILabel alloc] init];
  220. _subTitleLabel.text = NSLocalString(@"mimo_login_subtitle");
  221. _subTitleLabel.font = [MOTextTools poppinsBoldFont:24];
  222. _subTitleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  223. _subTitleLabel.numberOfLines = 1;
  224. _subTitleLabel.adjustsFontSizeToFitWidth = YES;
  225. }
  226. return _subTitleLabel;
  227. }
  228. - (UIImageView *)phoneView {
  229. if (!_phoneView) {
  230. _phoneView = [[UIImageView alloc] init];
  231. _phoneView.image = [[UIImage imageNamed:@"img_login_tf_bg"] resizeImageByCenter];
  232. _phoneView.userInteractionEnabled = YES;
  233. [_phoneView addSubview:self.chooseCountryBtn];
  234. CGFloat textWidth = self.countryIp.length * 15 + 8;
  235. if (textWidth < 55) {
  236. textWidth = 55;
  237. }
  238. [self.chooseCountryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  239. make.left.mas_equalTo(12);
  240. make.centerY.mas_equalTo(0);
  241. make.width.mas_equalTo(textWidth);
  242. }];
  243. [_phoneView addSubview:self.phoneField];
  244. [self.phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
  245. make.left.equalTo(self.chooseCountryBtn.mas_right).offset(5);
  246. make.right.mas_equalTo(-12);
  247. make.centerY.mas_equalTo(0);
  248. }];
  249. }
  250. return _phoneView;
  251. }
  252. - (UIButton *)chooseCountryBtn {
  253. if (!_chooseCountryBtn) {
  254. _chooseCountryBtn = [[UIButton alloc] init];
  255. _chooseCountryBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  256. _chooseCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
  257. _chooseCountryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 4);
  258. [_chooseCountryBtn setImage:[UIImage imageNamed:@"icon_login_arrow_down"] forState:UIControlStateNormal];
  259. _chooseCountryBtn.titleLabel.font = [MOTextTools poppinsMediumFont:18];
  260. [_chooseCountryBtn setTitleColor:[MOTools colorWithHexString:@"#111111"] forState:UIControlStateNormal];
  261. [_chooseCountryBtn addTarget:self action:@selector(chooseCountryBtnAction) forControlEvents:UIControlEventTouchUpInside];
  262. [_chooseCountryBtn setTitle:self.countryIp forState:UIControlStateNormal];
  263. }
  264. return _chooseCountryBtn;
  265. }
  266. - (UITextField *)phoneField {
  267. if (!_phoneField) {
  268. _phoneField = [[UITextField alloc] init];
  269. _phoneField.keyboardType = UIKeyboardTypeNumberPad;
  270. _phoneField.textColor = [MOTools colorWithHexString:@"#111111"];
  271. _phoneField.font = [MOTextTools poppinsMediumFont:18];
  272. // _phoneField.clearButtonMode = UITextFieldViewModeWhileEditing;
  273. _phoneField.clearButtonMode = UITextFieldViewModeNever;
  274. UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
  275. [_phoneField enableCustomClearButtonWithImage:clearIcon];
  276. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_phone") attributes:@{
  277. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
  278. NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
  279. }];
  280. _phoneField.attributedPlaceholder = placeholderString;
  281. [_phoneField addTarget:self action:@selector(phoneFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  282. }
  283. return _phoneField;
  284. }
  285. - (UIImageView *)passwordView {
  286. if (!_passwordView) {
  287. _passwordView = [[UIImageView alloc] init];
  288. _passwordView.image = [[UIImage imageNamed:@"img_login_tf_bg"] resizeImageByCenter];
  289. _passwordView.userInteractionEnabled = YES;
  290. [_passwordView addSubview:self.passwordField];
  291. [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
  292. make.left.mas_equalTo(12);
  293. make.right.mas_equalTo(-44);
  294. make.centerY.mas_equalTo(0);
  295. }];
  296. [_passwordView addSubview:self.eyeButton];
  297. [self.eyeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  298. make.right.mas_equalTo(-12);
  299. make.centerY.mas_equalTo(0);
  300. make.width.height.mas_equalTo(24);
  301. }];
  302. }
  303. return _passwordView;
  304. }
  305. - (UITextField *)passwordField {
  306. if (!_passwordField) {
  307. _passwordField = [[UITextField alloc] init];
  308. _passwordField.textColor = [MOTools colorWithHexString:@"#111111"];
  309. _passwordField.font = [MOTextTools poppinsMediumFont:18];
  310. // _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
  311. _passwordField.clearButtonMode = UITextFieldViewModeNever;
  312. UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
  313. [_passwordField enableCustomClearButtonWithImage:clearIcon];
  314. _passwordField.secureTextEntry = YES;
  315. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_password") attributes:@{
  316. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
  317. NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
  318. }];
  319. _passwordField.attributedPlaceholder = placeholderString;
  320. [_passwordField addTarget:self action:@selector(passwordFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  321. }
  322. return _passwordField;
  323. }
  324. - (UIButton *)eyeButton {
  325. if (!_eyeButton) {
  326. _eyeButton = [[UIButton alloc] init];
  327. [_eyeButton setImage:[UIImage imageNamed:@"icon_login_eye_close"] forState:UIControlStateNormal];
  328. [_eyeButton setImage:[UIImage imageNamed:@"icon_login_eye_open"] forState:UIControlStateSelected];
  329. [_eyeButton addTarget:self action:@selector(eyeButtonAction) forControlEvents:UIControlEventTouchUpInside];
  330. }
  331. return _eyeButton;
  332. }
  333. - (UIButton *)loginButton {
  334. if (!_loginButton) {
  335. _loginButton = [[UIButton alloc] init];
  336. NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
  337. UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 24.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
  338. [_loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
  339. _loginButton.layer.cornerRadius = 12;
  340. _loginButton.layer.masksToBounds = YES;
  341. [_loginButton setTitle:NSLocalString(@"mimo_login_continue") forState:UIControlStateNormal];
  342. [_loginButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  343. _loginButton.titleLabel.font = [MOTextTools poppinsSemiBoldFont:16];
  344. [_loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
  345. _loginButton.alpha = 0.5;
  346. }
  347. return _loginButton;
  348. }
  349. - (UIButton *)codeLoginButton {
  350. if (!_codeLoginButton) {
  351. _codeLoginButton = [[UIButton alloc] init];
  352. _codeLoginButton.titleLabel.font = [MOTextTools regularFont:14];
  353. [_codeLoginButton setTitleColor:kBaseTextColor_3 forState:UIControlStateNormal];
  354. [_codeLoginButton setTitle:NSLocalString(@"mimo_login_sms") forState:UIControlStateNormal];
  355. [_codeLoginButton addTarget:self action:@selector(codeLoginButtonAction) forControlEvents:UIControlEventTouchUpInside];
  356. }
  357. return _codeLoginButton;
  358. }
  359. - (UIButton *)forgetButton {
  360. if (!_forgetButton) {
  361. _forgetButton = [[UIButton alloc] init];
  362. _forgetButton.titleLabel.font = [MOTextTools regularFont:14];
  363. [_forgetButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateNormal];
  364. [_forgetButton setTitle:NSLocalString(@"mimo_forget_password") forState:UIControlStateNormal];
  365. [_forgetButton addTarget:self action:@selector(forgetButtonAction) forControlEvents:UIControlEventTouchUpInside];
  366. }
  367. return _forgetButton;
  368. }
  369. - (UILabel *)loginTypeLabel {
  370. if (!_loginTypeLabel) {
  371. _loginTypeLabel = [[UILabel alloc] init];
  372. _loginTypeLabel.text = NSLocalString(@"mimo_login_third_party");
  373. _loginTypeLabel.font = [MOTextTools regularFont:14];
  374. _loginTypeLabel.textColor = kBaseTextColor_3;
  375. }
  376. return _loginTypeLabel;
  377. }
  378. - (MOThirdPartyLoginView *)loginTypeView {
  379. if (!_loginTypeView) {
  380. _loginTypeView = [[MOThirdPartyLoginView alloc] init];
  381. _loginTypeView.loginChooseBlock = ^(MOThirdPartyType type) {
  382. if (type == MOThirdPartyTypeAp) {
  383. [[MOLoginManager shareManager] loginWithApple];
  384. } else if (type == MOThirdPartyTypeFb) {
  385. [[MOLoginManager shareManager] loginWithFacebook];
  386. } else if (type == MOThirdPartyTypeGg) {
  387. [[MOLoginManager shareManager] loginWithGoogle];
  388. }
  389. };
  390. }
  391. return _loginTypeView;
  392. }
  393. @end