| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- //
- // MOLoginPasswordVC.m
- // MiMoLive
- //
- // Created by MiMo on 2025/6/4.
- //
- #import "MOLoginPasswordVC.h"
- #import "UIImage+YYAdd.h"
- #import "MOSelectPartitionVC.h"
- #import "MOThirdPartyLoginView.h"
- #import "NSString+YYAdd.h"
- #import "MOLoginManager.h"
- #import "MOBingMobileVC.h"
- #import "UITextField+CustomClearButton.h"
- @interface MOLoginPasswordVC ()
- @property (nonatomic, strong) UIImageView *bgImgView;
- @property (nonatomic, strong) BigBtn *backButton;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *subTitleLabel;
- @property (nonatomic, strong) UIImageView *phoneView;
- @property (nonatomic, strong) UIButton *chooseCountryBtn;
- @property (nonatomic, strong) UITextField *phoneField;
- @property (nonatomic, strong) UIImageView *passwordView;
- @property (nonatomic, strong) UITextField *passwordField;
- @property (nonatomic, strong) UIButton *eyeButton;
- @property (nonatomic, strong) UIButton *loginButton;
- @property (nonatomic, strong) UIButton *codeLoginButton;
- @property (nonatomic, strong) UIButton *forgetButton;
- @property (nonatomic, strong) UILabel *loginTypeLabel;
- @property (nonatomic, strong) MOThirdPartyLoginView *loginTypeView;
- /** 是否越狱 */
- @property (nonatomic, assign) BOOL isRootMobile;
- /** 是否虚拟设备 */
- @property (nonatomic, assign) BOOL isVirtual;
- @end
- @implementation MOLoginPasswordVC
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self setupUI];
-
- self.isRootMobile = [SecurityBridge isJailbroken];//是否越狱
- self.isVirtual = [SecurityBridge isRunningInEmulator];//是否虚拟机
- }
- - (void)setupUI {
- [self.view addSubview:self.bgImgView];
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self.view addSubview:self.backButton];
- [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(kTopSafeAreaInset + 10);
- make.left.mas_equalTo(12);
- make.size.mas_equalTo(CGSizeMake(30, 30));
- }];
-
- [self.view addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.backButton.mas_bottom).offset(36);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-15);
- }];
-
- [self.view addSubview:self.subTitleLabel];
- [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-15);
- }];
-
- [self.view addSubview:self.phoneView];
- [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.subTitleLabel.mas_bottom).offset(24);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- make.height.mas_equalTo(52);
- }];
-
- [self.view addSubview:self.passwordView];
- [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.phoneView.mas_bottom).offset(16);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- make.height.mas_equalTo(52);
- }];
-
- [self.view addSubview:self.loginButton];
- [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.phoneView.mas_bottom).offset(92);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- }];
-
- [self.view addSubview:self.codeLoginButton];
- [self.codeLoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.loginButton.mas_bottom).offset(10);
- make.left.mas_equalTo(24);
- }];
-
- [self.view addSubview:self.forgetButton];
- [self.forgetButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.loginButton.mas_bottom).offset(10);
- make.right.mas_equalTo(-24);
- }];
-
- [self.view addSubview:self.loginTypeView];
- [self.loginTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-kBottomSafeAreaInset - 16);
- make.centerX.mas_equalTo(0);
- make.height.mas_equalTo(42);
- }];
-
- [self.view addSubview:self.loginTypeLabel];
- [self.loginTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.bottom.equalTo(self.loginTypeView.mas_top).offset(-20);
- }];
- }
- #pragma mark - Actions
- - (void)phoneFieldDidChange:(UITextField *)textField {
- [self updateLoginButtonState];
- }
- - (void)passwordFieldDidChange:(UITextField *)textField {
- [self updateLoginButtonState];
- }
- /// 根据手机号和密码内容更新登录按钮状态
- - (void)updateLoginButtonState {
- BOOL phoneNotEmpty = self.phoneField.text.length > 0;
- BOOL passwordNotEmpty = self.passwordField.text.length > 0;
- // self.loginButton.enabled = phoneNotEmpty && passwordNotEmpty;
- self.loginButton.alpha = phoneNotEmpty && passwordNotEmpty ? 1.0 : 0.5;
- }
- - (void)forgetButtonAction {
-
- MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
- vc.forgetPwd = YES;
- [self.navigationController pushViewController:vc animated:YES];
-
-
- // if(self.phoneField.text.length == 0) {
- // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- // return;
- // }
- //
- // MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
- // vc.code = self.chooseCountryBtn.titleLabel.text;
- // vc.num = self.phoneField.text;
- // vc.vcType = MOEnterCodePasswordType;
- // [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)backButtonAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)codeLoginButtonAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)chooseCountryBtnAction {
- MOSelectPartitionVC *vc = [[MOSelectPartitionVC alloc] init];
-
- //MARK: 选择区号回调
- WEAKSELF
- vc.selectCellBlock = ^(MOCountryList * _Nonnull model) {
- CGFloat textWidth = model.num.length * 15 + 8;
- [self.chooseCountryBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(textWidth);
- }];
- [weakSelf.chooseCountryBtn setTitle:model.num forState:UIControlStateNormal];
- if (weakSelf.chooseBlock) {
- weakSelf.chooseBlock(model.num);
- }
- };
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)eyeButtonAction {
- self.eyeButton.selected = !self.eyeButton.isSelected;
-
- if (self.eyeButton.isSelected) {//密码可见
- self.passwordField.secureTextEntry = NO;
- } else {//不可见
- self.passwordField.secureTextEntry = YES;
- }
- }
- - (void)loginButtonAction {
- if(self.phoneField.text.length == 0) {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- if(self.passwordField.text.length == 0) {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_password")];
- return;
- }
-
- [MBProgressHUD showActivityMessageInView:@""];
- WEAKSELF
- NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
- @"num":self.phoneField.text};
-
- NSString *pswStr = [self.passwordField.text md5String];
-
- NSDictionary *dict = @{@"mobile":mobileDict,
- @"pwd":pswStr,
- @"root":@(weakSelf.isRootMobile),
- @"virtual":@(weakSelf.isVirtual)};
- [[MOLoginManager shareManager] loginByPasswordWithDict:dict];
- }
- - (UIImageView *)bgImgView {
- if (!_bgImgView) {
- _bgImgView = [[UIImageView alloc] init];
- _bgImgView.image = [UIImage imageNamed:@"img_login_bg"];
- }
- return _bgImgView;
- }
- - (BigBtn *)backButton {
- if (!_backButton) {
- _backButton = [[BigBtn alloc] init];
- [_backButton setImage:[UIImage imageNamed:@"icon_login_back_white"] forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.text = NSLocalString(@"mimo_login_title");
- _titleLabel.font = [MOTextTools poppinsBoldFont:24];
- _titleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _titleLabel.numberOfLines = 1;
- _titleLabel.adjustsFontSizeToFitWidth = YES;
- }
- return _titleLabel;
- }
- - (UILabel *)subTitleLabel {
- if (!_subTitleLabel) {
- _subTitleLabel = [[UILabel alloc] init];
- _subTitleLabel.text = NSLocalString(@"mimo_login_subtitle");
- _subTitleLabel.font = [MOTextTools poppinsBoldFont:24];
- _subTitleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _subTitleLabel.numberOfLines = 1;
- _subTitleLabel.adjustsFontSizeToFitWidth = YES;
- }
- return _subTitleLabel;
- }
- - (UIImageView *)phoneView {
- if (!_phoneView) {
- _phoneView = [[UIImageView alloc] init];
- _phoneView.image = [[UIImage imageNamed:@"img_login_tf_bg"] resizeImageByCenter];
- _phoneView.userInteractionEnabled = YES;
-
- [_phoneView addSubview:self.chooseCountryBtn];
-
- CGFloat textWidth = self.countryIp.length * 15 + 8;
- if (textWidth < 55) {
- textWidth = 55;
- }
- [self.chooseCountryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(12);
- make.centerY.mas_equalTo(0);
- make.width.mas_equalTo(textWidth);
- }];
-
- [_phoneView addSubview:self.phoneField];
- [self.phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.chooseCountryBtn.mas_right).offset(5);
- make.right.mas_equalTo(-12);
- make.centerY.mas_equalTo(0);
- }];
- }
- return _phoneView;
- }
- - (UIButton *)chooseCountryBtn {
- if (!_chooseCountryBtn) {
- _chooseCountryBtn = [[UIButton alloc] init];
- _chooseCountryBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
- _chooseCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
- _chooseCountryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 4);
- [_chooseCountryBtn setImage:[UIImage imageNamed:@"icon_login_arrow_down"] forState:UIControlStateNormal];
- _chooseCountryBtn.titleLabel.font = [MOTextTools poppinsMediumFont:18];
- [_chooseCountryBtn setTitleColor:[MOTools colorWithHexString:@"#111111"] forState:UIControlStateNormal];
- [_chooseCountryBtn addTarget:self action:@selector(chooseCountryBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [_chooseCountryBtn setTitle:self.countryIp forState:UIControlStateNormal];
- }
- return _chooseCountryBtn;
- }
- - (UITextField *)phoneField {
- if (!_phoneField) {
- _phoneField = [[UITextField alloc] init];
- _phoneField.keyboardType = UIKeyboardTypeNumberPad;
- _phoneField.textColor = [MOTools colorWithHexString:@"#111111"];
- _phoneField.font = [MOTextTools poppinsMediumFont:18];
- // _phoneField.clearButtonMode = UITextFieldViewModeWhileEditing;
- _phoneField.clearButtonMode = UITextFieldViewModeNever;
- UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
- [_phoneField enableCustomClearButtonWithImage:clearIcon];
-
- NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_phone") attributes:@{
- NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
- NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
- }];
-
- _phoneField.attributedPlaceholder = placeholderString;
-
- [_phoneField addTarget:self action:@selector(phoneFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }
- return _phoneField;
- }
- - (UIImageView *)passwordView {
- if (!_passwordView) {
- _passwordView = [[UIImageView alloc] init];
- _passwordView.image = [[UIImage imageNamed:@"img_login_tf_bg"] resizeImageByCenter];
- _passwordView.userInteractionEnabled = YES;
-
- [_passwordView addSubview:self.passwordField];
- [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(12);
- make.right.mas_equalTo(-44);
- make.centerY.mas_equalTo(0);
- }];
-
- [_passwordView addSubview:self.eyeButton];
- [self.eyeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-12);
- make.centerY.mas_equalTo(0);
- make.width.height.mas_equalTo(24);
- }];
-
- }
- return _passwordView;
- }
- - (UITextField *)passwordField {
- if (!_passwordField) {
- _passwordField = [[UITextField alloc] init];
- _passwordField.textColor = [MOTools colorWithHexString:@"#111111"];
- _passwordField.font = [MOTextTools poppinsMediumFont:18];
- // _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
- _passwordField.clearButtonMode = UITextFieldViewModeNever;
- UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
- [_passwordField enableCustomClearButtonWithImage:clearIcon];
- _passwordField.secureTextEntry = YES;
-
- NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_password") attributes:@{
- NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
- NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
- }];
-
- _passwordField.attributedPlaceholder = placeholderString;
-
- [_passwordField addTarget:self action:@selector(passwordFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }
- return _passwordField;
- }
- - (UIButton *)eyeButton {
- if (!_eyeButton) {
- _eyeButton = [[UIButton alloc] init];
- [_eyeButton setImage:[UIImage imageNamed:@"icon_login_eye_close"] forState:UIControlStateNormal];
- [_eyeButton setImage:[UIImage imageNamed:@"icon_login_eye_open"] forState:UIControlStateSelected];
- [_eyeButton addTarget:self action:@selector(eyeButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _eyeButton;
- }
- - (UIButton *)loginButton {
- if (!_loginButton) {
- _loginButton = [[UIButton alloc] init];
-
- NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 24.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
- [_loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
- _loginButton.layer.cornerRadius = 12;
- _loginButton.layer.masksToBounds = YES;
- [_loginButton setTitle:NSLocalString(@"mimo_login_continue") forState:UIControlStateNormal];
- [_loginButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- _loginButton.titleLabel.font = [MOTextTools poppinsSemiBoldFont:16];
- [_loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
-
- _loginButton.alpha = 0.5;
- }
- return _loginButton;
- }
- - (UIButton *)codeLoginButton {
- if (!_codeLoginButton) {
- _codeLoginButton = [[UIButton alloc] init];
- _codeLoginButton.titleLabel.font = [MOTextTools regularFont:14];
- [_codeLoginButton setTitleColor:kBaseTextColor_3 forState:UIControlStateNormal];
- [_codeLoginButton setTitle:NSLocalString(@"mimo_login_sms") forState:UIControlStateNormal];
- [_codeLoginButton addTarget:self action:@selector(codeLoginButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _codeLoginButton;
- }
- - (UIButton *)forgetButton {
- if (!_forgetButton) {
- _forgetButton = [[UIButton alloc] init];
- _forgetButton.titleLabel.font = [MOTextTools regularFont:14];
- [_forgetButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateNormal];
- [_forgetButton setTitle:NSLocalString(@"mimo_forget_password") forState:UIControlStateNormal];
- [_forgetButton addTarget:self action:@selector(forgetButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _forgetButton;
- }
- - (UILabel *)loginTypeLabel {
- if (!_loginTypeLabel) {
- _loginTypeLabel = [[UILabel alloc] init];
- _loginTypeLabel.text = NSLocalString(@"mimo_login_third_party");
- _loginTypeLabel.font = [MOTextTools regularFont:14];
- _loginTypeLabel.textColor = kBaseTextColor_3;
- }
- return _loginTypeLabel;
- }
- - (MOThirdPartyLoginView *)loginTypeView {
- if (!_loginTypeView) {
- _loginTypeView = [[MOThirdPartyLoginView alloc] init];
- _loginTypeView.loginChooseBlock = ^(MOThirdPartyType type) {
- if (type == MOThirdPartyTypeAp) {
- [[MOLoginManager shareManager] loginWithApple];
- } else if (type == MOThirdPartyTypeFb) {
- [[MOLoginManager shareManager] loginWithFacebook];
- } else if (type == MOThirdPartyTypeGg) {
- [[MOLoginManager shareManager] loginWithGoogle];
- }
- };
- }
- return _loginTypeView;
- }
- @end
|