PasswordLoginController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // PasswordLoginController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/18.
  6. //
  7. #import "PasswordLoginController.h"
  8. #import "PasswordBodyView.h"
  9. #import "AppDelegate.h"
  10. #import "UserInfoManager.h"
  11. @interface PasswordLoginController ()
  12. @property (nonatomic, strong) PasswordBodyView *bodyView;
  13. @end
  14. @implementation PasswordLoginController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. self.ks_prefersNavigationBarHidden = YES;
  19. [self configUI];
  20. }
  21. - (void)configUI {
  22. CGFloat height = KPortraitHeight;
  23. _bodyView = [PasswordBodyView shareInstance];
  24. if (![NSString isEmptyString:UserDefault(PHONEKEY)]) {
  25. _bodyView.phoneField.text = UserDefault(PHONEKEY);
  26. }
  27. if (![NSString isEmptyString:UserDefault(PASSWORDKEY)]) {
  28. _bodyView.passwordField.text = UserDefault(PASSWORDKEY);
  29. }
  30. [self.scrollView addSubview:_bodyView];
  31. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.mas_equalTo(self.scrollView.mas_top);
  33. make.right.left.mas_equalTo(self.view);
  34. make.height.mas_equalTo(height);
  35. }];
  36. MJWeakSelf;
  37. [_bodyView passwordLoginActionCallback:^(PWDLOGIN action, NSDictionary * _Nonnull parm) {
  38. [weakSelf operationAction:action parm:parm];
  39. }];
  40. if (@available(iOS 11.0, *)) {
  41. self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  42. } else {
  43. // Fallback on earlier versions
  44. self.automaticallyAdjustsScrollViewInsets = NO;
  45. }
  46. }
  47. - (void)operationAction:(PWDLOGIN)action parm:(NSDictionary *)parm {
  48. if (action == PWDLOGIN_BACK) {
  49. [self backAction];
  50. }
  51. else if (action == PWDLOGIN_LOGIN) {
  52. [self showhud];
  53. [KSNetworkingManager LoginRequest:KS_POST phone:[parm stringValueForKey:@"phone"] password:[parm stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
  54. [self removehub];
  55. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  56. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  57. // 保存用户类型
  58. UserDefaultSet([parm stringValueForKey:@"phone"], PHONEKEY);
  59. UserDefaultSet([parm stringValueForKey:@"password"], PASSWORDKEY);
  60. NSDictionary *authentication = [result dictionaryValueForKey:@"authentication"];
  61. UserDefaultSet([authentication stringValueForKey:@"access_token"], TokenKey);
  62. UserDefaultSet([authentication stringValueForKey:@"refresh_token"], RefreshToken);
  63. UserDefaultSet([authentication stringValueForKey:@"token_type"], Token_type);
  64. [[NSUserDefaults standardUserDefaults] synchronize];
  65. [KSNetworkingManager configRequestHeader];
  66. // 获取用户信息并登录融云
  67. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  68. MJWeakSelf;
  69. [self KSShowMsg:@"登录成功" promptCompletion:^{
  70. [weakSelf toHomeView];
  71. }];
  72. }
  73. else {
  74. [self MBPShow:MESSAGEKEY];
  75. }
  76. } faliure:^(NSError * _Nonnull error) {
  77. [self removehub];
  78. }];
  79. }
  80. }
  81. - (void)toHomeView {
  82. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  83. [appDelegate initTableBar];
  84. UITabBarController *tabBarController = appDelegate.tabBarController;
  85. [tabBarController setSelectedIndex:0];
  86. }
  87. /*
  88. #pragma mark - Navigation
  89. // In a storyboard-based application, you will often want to do a little preparation before navigation
  90. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  91. // Get the new view controller using [segue destinationViewController].
  92. // Pass the selected object to the new view controller.
  93. }
  94. */
  95. @end