PasswordLoginController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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:self.phoneNo] && ![self.phoneNo isEqualToString:UserDefault(PHONEKEY)]) {
  25. _bodyView.phoneField.text = self.phoneNo;
  26. }
  27. else {
  28. if (![NSString isEmptyString:UserDefault(PHONEKEY)]) {
  29. _bodyView.phoneField.text = UserDefault(PHONEKEY);
  30. }
  31. if (![NSString isEmptyString:UserDefault(PASSWORDKEY)]) {
  32. _bodyView.passwordField.text = UserDefault(PASSWORDKEY);
  33. }
  34. }
  35. [self.scrollView addSubview:_bodyView];
  36. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(self.scrollView.mas_top);
  38. make.right.left.mas_equalTo(self.view);
  39. make.height.mas_equalTo(height);
  40. }];
  41. MJWeakSelf;
  42. [_bodyView passwordLoginActionCallback:^(PWDLOGIN action, NSDictionary * _Nonnull parm) {
  43. [weakSelf operationAction:action parm:parm];
  44. }];
  45. if (@available(iOS 11.0, *)) {
  46. self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  47. } else {
  48. // Fallback on earlier versions
  49. self.automaticallyAdjustsScrollViewInsets = NO;
  50. }
  51. }
  52. - (void)operationAction:(PWDLOGIN)action parm:(NSDictionary *)parm {
  53. if (action == PWDLOGIN_BACK) {
  54. [self backAction];
  55. }
  56. else if (action == PWDLOGIN_LOGIN) {
  57. [self showhud];
  58. [KSNetworkingManager LoginRequest:KS_POST phone:[parm ks_stringValueForKey:@"phone"] password:[parm ks_stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
  59. [self removehub];
  60. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  61. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  62. // 保存用户类型
  63. UserDefaultSet([parm ks_stringValueForKey:@"phone"], PHONEKEY);
  64. UserDefaultSet([parm ks_stringValueForKey:@"password"], PASSWORDKEY);
  65. NSDictionary *authentication = [result ks_dictionaryValueForKey:@"authentication"];
  66. UserDefaultSet([authentication ks_stringValueForKey:@"access_token"], TokenKey);
  67. UserDefaultSet([authentication ks_stringValueForKey:@"refresh_token"], RefreshToken);
  68. UserDefaultSet([authentication ks_stringValueForKey:@"token_type"], Token_type);
  69. [[NSUserDefaults standardUserDefaults] synchronize];
  70. [KSNetworkingManager configRequestHeader];
  71. // 获取用户信息并登录融云
  72. [USER_MANAGER queryUserInfoSendLoginUMCount];
  73. MJWeakSelf;
  74. [self KSShowMsg:@"登录成功" promptCompletion:^{
  75. [weakSelf toHomeView];
  76. }];
  77. }
  78. else {
  79. [self MBPShow:MESSAGEKEY];
  80. }
  81. } faliure:^(NSError * _Nonnull error) {
  82. [self removehub];
  83. }];
  84. }
  85. }
  86. - (void)toHomeView {
  87. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  88. [appDelegate initTableBar];
  89. UITabBarController *tabBarController = appDelegate.tabBarController;
  90. [tabBarController setSelectedIndex:0];
  91. }
  92. /*
  93. #pragma mark - Navigation
  94. // In a storyboard-based application, you will often want to do a little preparation before navigation
  95. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  96. // Get the new view controller using [segue destinationViewController].
  97. // Pass the selected object to the new view controller.
  98. }
  99. */
  100. @end