123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // SKBaseAccountViewController+user.m
- // sikey comm
- //
- // Created by 刘振兴 on 2024/2/28.
- // Copyright © 2024 BaH Cy. All rights reserved.
- //
- #import "SKBaseAccountViewController+user.h"
- @implementation SKBaseAccountViewController (user)
- - (void)requestRegister:(BOOL)isEmail areaCode:(NSString*)areaCode phone:(NSString*)phone email:(NSString*)email password:(NSString*)password captcha:(NSString*)captcha callback:(void(^)(BOOL isOK))callback {
- NSDictionary *params = @{
- @"email" : email,
- @"areaCode" : areaCode,
- @"phoneNumber" : phone,
- @"password" :password,
- @"captcha" : captcha,
- };
-
- [ERequest httpRequest:params httpURL:URL_REGISTER httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
- if ([ERequest isSuccessWithResult:result]) {
- [EasyTextView showSuccessText:NSLocalizedString(@"Register.Account.Success", nil)];//[NSString
- callback(YES);
- } else {
- [EasyTextView showErrorText:result[@"message"]];
- callback(NO);
- }
- } onFailure:^(NSError *error) {
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
- callback(NO);
- }];
- }
- - (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 {
- NSDictionary *params = @{
- @"email" : email,
- @"phoneNumber" : phone,
- @"password" :password,
- @"areaCode" : areaCode,
- @"captcha" : @"0000",
- };
-
- [ERequest httpRequest:params httpURL:URL_LOGIN httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
- if ([ERequest isSuccessWithResult:result]) {
- NSMutableDictionary* dic = [NSMutableDictionary dictionaryWithDictionary:result[@"data"]];
- dic[@"phone"] = phone;
- dic[@"areaCode"] = areaCode;
- [self saveLoginInfo:dic phone:(isEmail? email:phone) password:password];
-
- NSArray* childList = result[@"data"][@"childList"];
- callback(YES, childList.count > 0);
- } else {
- [EasyTextView showErrorText:result[@"message"]];
- callback(NO, NO);
- }
- } onFailure:^(NSError *error) {
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
- callback(NO, NO);
- }];
- }
- - (void)requestLoginWithType:(NSInteger)type thirdPartyId:(NSString*)thirdPartyId thirdPartyToken:(NSString*)token callback:(void(^)(BOOL isOK))callback {
- NSDictionary *inforDic = [NSBundle mainBundle].infoDictionary;
- NSString *buildVersion = inforDic[@"CFBundleVersion"];
- if (buildVersion == nil)
- buildVersion = @"1.0.0";
-
- NSDictionary *params = @{
- @"userType":[NSNumber numberWithInteger:type],
- @"platform":@"0", //0:ios 1:android
- @"appVersion":buildVersion,
- @"ip":@"",
- @"thirdPartyId":thirdPartyId,
- @"token":token,
- @"systemLanguage":[EUtil getSystemLanguage],
- };
-
- [ERequest httpRequest:params httpURL:URL_REGISTER httpMethod:@"POST" httpEncrypt:NO onSuccess:^(NSDictionary *result) {
- if ([ERequest isSuccessWithResult:result]) {
- [self saveLoginInfo:result[@"data"] phone:thirdPartyId password:@""];
- callback(YES);
- } else {
- [EasyTextView showErrorText:result[@"message"]];
- callback(NO);
- }
- } onFailure:^(NSError *error) {
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
- callback(NO);
- }];
- }
- - (void)saveLoginInfo:(NSDictionary*)dic phone:(NSString*)account password:(NSString*)password {
- //token
- NSString* token = dic[@"token"];
- [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"sk_token"];
- [[NSUserDefaults standardUserDefaults] synchronize];
-
- [UserDataHelper setLastLoginInfo:dic];
- LogInModel *loginModel = [LogInModel mj_objectWithKeyValues:dic];
- [DataManager shared].loginModel = loginModel;
-
- //保存账号
- [UserDataHelper setUserName:account];
- [UserDataHelper setUserPassword:password ForUser:account];
- [UserDataHelper setHasLogin:YES];
- }
- @end
|