// // PasswordLoginController.m // KulexiuForTeacher // // Created by Kyle on 2022/3/18. // #import "PasswordLoginController.h" #import "PasswordBodyView.h" #import "AppDelegate.h" #import "UserInfoManager.h" @interface PasswordLoginController () @property (nonatomic, strong) PasswordBodyView *bodyView; @end @implementation PasswordLoginController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.ks_prefersNavigationBarHidden = YES; [self configUI]; } - (void)configUI { CGFloat height = KPortraitHeight; _bodyView = [PasswordBodyView shareInstance]; if (![NSString isEmptyString:UserDefault(PHONEKEY)]) { _bodyView.phoneField.text = UserDefault(PHONEKEY); } if (![NSString isEmptyString:UserDefault(PASSWORDKEY)]) { _bodyView.passwordField.text = UserDefault(PASSWORDKEY); } [self.scrollView addSubview:_bodyView]; [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.scrollView.mas_top); make.right.left.mas_equalTo(self.view); make.height.mas_equalTo(height); }]; MJWeakSelf; [_bodyView passwordLoginActionCallback:^(PWDLOGIN action, NSDictionary * _Nonnull parm) { [weakSelf operationAction:action parm:parm]; }]; if (@available(iOS 11.0, *)) { self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions self.automaticallyAdjustsScrollViewInsets = NO; } } - (void)operationAction:(PWDLOGIN)action parm:(NSDictionary *)parm { if (action == PWDLOGIN_BACK) { [self backAction]; } else if (action == PWDLOGIN_LOGIN) { [self showhud]; [KSNetworkingManager LoginRequest:KS_POST phone:[parm stringValueForKey:@"phone"] password:[parm stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) { [self removehub]; if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSDictionary *result = [dic dictionaryValueForKey:@"data"]; // 保存用户类型 UserDefaultSet([parm stringValueForKey:@"phone"], PHONEKEY); UserDefaultSet([parm stringValueForKey:@"password"], PASSWORDKEY); NSDictionary *authentication = [result dictionaryValueForKey:@"authentication"]; UserDefaultSet([authentication stringValueForKey:@"access_token"], TokenKey); UserDefaultSet([authentication stringValueForKey:@"refresh_token"], RefreshToken); UserDefaultSet([authentication stringValueForKey:@"token_type"], Token_type); [[NSUserDefaults standardUserDefaults] synchronize]; [KSNetworkingManager configRequestHeader]; // 获取用户信息并登录融云 [USER_MANAGER queryUserInfoConnectRongCloud:YES]; MJWeakSelf; [self KSShowMsg:@"登录成功" promptCompletion:^{ [weakSelf toHomeView]; }]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { [self removehub]; }]; } } - (void)toHomeView { AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate initTableBar]; UITabBarController *tabBarController = appDelegate.tabBarController; [tabBarController setSelectedIndex:0]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end