123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // 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:self.phoneNo] && ![self.phoneNo isEqualToString:UserDefault(PHONEKEY)]) {
- _bodyView.phoneField.text = self.phoneNo;
- }
- else {
- 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 ks_stringValueForKey:@"phone"] password:[parm ks_stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- // 保存用户类型
- UserDefaultSet([parm ks_stringValueForKey:@"phone"], PHONEKEY);
- UserDefaultSet([parm ks_stringValueForKey:@"password"], PASSWORDKEY);
- NSDictionary *authentication = [result ks_dictionaryValueForKey:@"authentication"];
- UserDefaultSet([authentication ks_stringValueForKey:@"access_token"], TokenKey);
- UserDefaultSet([authentication ks_stringValueForKey:@"refresh_token"], RefreshToken);
- UserDefaultSet([authentication ks_stringValueForKey:@"token_type"], Token_type);
- [[NSUserDefaults standardUserDefaults] synchronize];
- [KSNetworkingManager configRequestHeader];
-
- // 获取用户信息并登录融云
- [USER_MANAGER queryUserInfoSendLoginUMCount];
- 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
|