SKBaseAccountViewController+user.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // SKBaseAccountViewController+user.m
  3. // sikey comm
  4. //
  5. // Created by 刘振兴 on 2024/2/28.
  6. // Copyright © 2024 BaH Cy. All rights reserved.
  7. //
  8. #import "SKBaseAccountViewController+user.h"
  9. @implementation SKBaseAccountViewController (user)
  10. - (void)requestRegister:(BOOL)isEmail areaCode:(NSString*)areaCode phone:(NSString*)phone email:(NSString*)email password:(NSString*)password captcha:(NSString*)captcha callback:(void(^)(BOOL isOK))callback {
  11. NSDictionary *params = @{
  12. @"email" : email,
  13. @"areaCode" : areaCode,
  14. @"phoneNumber" : phone,
  15. @"password" :password,
  16. @"captcha" : captcha,
  17. };
  18. [ERequest httpRequest:params httpURL:URL_REGISTER httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
  19. if ([ERequest isSuccessWithResult:result]) {
  20. [EasyTextView showSuccessText:NSLocalizedString(@"Register.Account.Success", nil)];//[NSString
  21. callback(YES);
  22. } else {
  23. [EasyTextView showErrorText:result[@"message"]];
  24. callback(NO);
  25. }
  26. } onFailure:^(NSError *error) {
  27. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
  28. callback(NO);
  29. }];
  30. }
  31. - (void)requestLogin:(BOOL)isEmail areaCode:(NSString*)areaCode phone:(NSString*)phone email:(NSString*)email password:(NSString*)password captcha:(NSString*)captcha callback:(void(^)(BOOL isOK, BOOL isChildExist))callback {
  32. NSDictionary *params = @{
  33. @"email" : email,
  34. @"phoneNumber" : phone,
  35. @"password" :password,
  36. @"areaCode" : areaCode,
  37. @"captcha" : @"0000",
  38. };
  39. [ERequest httpRequest:params httpURL:URL_LOGIN httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
  40. if ([ERequest isSuccessWithResult:result]) {
  41. NSMutableDictionary* dic = [NSMutableDictionary dictionaryWithDictionary:result[@"data"]];
  42. dic[@"phone"] = phone;
  43. dic[@"areaCode"] = areaCode;
  44. [self saveLoginInfo:dic phone:(isEmail? email:phone) password:password];
  45. NSArray* childList = result[@"data"][@"childList"];
  46. callback(YES, childList.count > 0);
  47. } else {
  48. [EasyTextView showErrorText:result[@"message"]];
  49. callback(NO, NO);
  50. }
  51. } onFailure:^(NSError *error) {
  52. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
  53. callback(NO, NO);
  54. }];
  55. }
  56. - (void)requestLoginWithType:(NSInteger)type thirdPartyId:(NSString*)thirdPartyId thirdPartyToken:(NSString*)token callback:(void(^)(BOOL isOK))callback {
  57. NSDictionary *inforDic = [NSBundle mainBundle].infoDictionary;
  58. NSString *buildVersion = inforDic[@"CFBundleVersion"];
  59. if (buildVersion == nil)
  60. buildVersion = @"1.0.0";
  61. NSDictionary *params = @{
  62. @"userType":[NSNumber numberWithInteger:type],
  63. @"platform":@"0", //0:ios 1:android
  64. @"appVersion":buildVersion,
  65. @"ip":@"",
  66. @"thirdPartyId":thirdPartyId,
  67. @"token":token,
  68. @"systemLanguage":[EUtil getSystemLanguage],
  69. };
  70. [ERequest httpRequest:params httpURL:URL_REGISTER httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
  71. if ([ERequest isSuccessWithResult:result]) {
  72. [self saveLoginInfo:result[@"data"] phone:thirdPartyId password:@""];
  73. callback(YES);
  74. } else {
  75. [EasyTextView showErrorText:result[@"message"]];
  76. callback(NO);
  77. }
  78. } onFailure:^(NSError *error) {
  79. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
  80. callback(NO);
  81. }];
  82. }
  83. - (void)saveLoginInfo:(NSDictionary*)dic phone:(NSString*)account password:(NSString*)password {
  84. //token
  85. NSString* token = dic[@"token"];
  86. [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"sk_token"];
  87. [[NSUserDefaults standardUserDefaults] synchronize];
  88. [UserDataHelper setLastLoginInfo:dic];
  89. LogInModel *loginModel = [LogInModel mj_objectWithKeyValues:dic];
  90. [DataManager shared].loginModel = loginModel;
  91. //保存账号
  92. [UserDataHelper setUserName:account];
  93. [UserDataHelper setUserPassword:password ForUser:account];
  94. [UserDataHelper setHasLogin:YES];
  95. }
  96. @end