1
This commit is contained in:
@@ -138,6 +138,8 @@
|
||||
}];
|
||||
|
||||
[self.emailFieldContainer addSubview:self.emailTextField];
|
||||
NSString *email = [[NSUserDefaults standardUserDefaults] objectForKey:KBUserEmailKey];
|
||||
self.emailTextField.text = email;
|
||||
[self.emailTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.emailFieldContainer).insets(UIEdgeInsetsMake(0, 16, 0, 16));
|
||||
}];
|
||||
@@ -229,6 +231,8 @@
|
||||
|
||||
[self.loginVM emailLoginEmail:email password:password WithCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:email forKey:KBUserEmailKey];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
if ([appDelegate respondsToSelector:@selector(setupRootVC)]) {
|
||||
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBForgetPwdNewPwdVC : BaseViewController
|
||||
@property (nonatomic, copy) NSString *email;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
//
|
||||
|
||||
#import "KBForgetPwdNewPwdVC.h"
|
||||
|
||||
#import "KBLoginVM.h"
|
||||
#import "KBEmailRegistVC.h"
|
||||
@interface KBForgetPwdNewPwdVC () <UITextFieldDelegate>
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel; // Reset Password
|
||||
@@ -124,6 +125,25 @@
|
||||
|
||||
KBLOG(@"KBForgetPwdNewPwdVC next step, pwdLen=%zd", pwd.length);
|
||||
// TODO: 提交新密码逻辑
|
||||
NSString *rEmail = self.email ? self.email : @"";
|
||||
[[KBLoginVM shared] resetPassWord:rEmail password:pwd confirmPassword:pwd withCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||
/// 成功后删除栈内忘记密码的页面
|
||||
if (success) {
|
||||
UIViewController *targetVC = nil;
|
||||
for (UIViewController *vc in KB_CURRENT_NAV.viewControllers) {
|
||||
if ([vc isKindOfClass:[KBEmailRegistVC class]]) {
|
||||
targetVC = vc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetVC) {
|
||||
[KB_CURRENT_NAV popToViewController:targetVC animated:YES];
|
||||
} else {
|
||||
// 如果没找到,可以选择 popToRootViewController 或自定义逻辑
|
||||
[KB_CURRENT_NAV popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UITextFieldDelegate
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
KBLOG(@"KBForgetPwdVC next step with email=%@", email);
|
||||
// TODO: 接 forgot password 接口
|
||||
KBForgetVerPwdVC *vc = [[KBForgetVerPwdVC alloc] init];
|
||||
vc.email = email;
|
||||
UINavigationController *nav = KB_CURRENT_NAV;
|
||||
if ([nav isKindOfClass:[BaseNavigationController class]]) {
|
||||
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBForgetVerPwdVC : BaseViewController
|
||||
@property (nonatomic, copy) NSString *email;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
[self kb_addTapToDismissKeyboard];
|
||||
|
||||
[self setupUI];
|
||||
NSString *reEmail = self.email ? self.email : @"";
|
||||
[[KBLoginVM shared] sendVerifyMailWithEmail:reEmail withCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UI
|
||||
@@ -75,14 +81,20 @@
|
||||
return;
|
||||
}
|
||||
KBLOG(@"KBVerPwdVC next step with code=%@", code);
|
||||
// TODO: 接后续重置密码的下一步逻辑
|
||||
KBForgetPwdNewPwdVC *vc = [[KBForgetPwdNewPwdVC alloc] init];
|
||||
UINavigationController *nav = KB_CURRENT_NAV;
|
||||
if ([nav isKindOfClass:[BaseNavigationController class]]) {
|
||||
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
|
||||
} else {
|
||||
[nav pushViewController:vc animated:YES];
|
||||
}
|
||||
[[KBLoginVM shared] verifyEMailCode:self.email verifyCode:code withCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
KBForgetPwdNewPwdVC *vc = [[KBForgetPwdNewPwdVC alloc] init];
|
||||
vc.email = self.email;
|
||||
UINavigationController *nav = KB_CURRENT_NAV;
|
||||
if ([nav isKindOfClass:[BaseNavigationController class]]) {
|
||||
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
|
||||
} else {
|
||||
[nav pushViewController:vc animated:YES];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - Lazy UI
|
||||
|
||||
@@ -99,11 +99,14 @@
|
||||
if (genderNumber != nil) {
|
||||
self.params[@"gender"] = genderNumber;
|
||||
}
|
||||
NSString *email = self.params[@"mailAddress"] ? self.params[@"mailAddress"] : @"";
|
||||
[self.loginVM emailRegisterParams:self.params withCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
[KBHUD showInfo:KBLocalized(@"Signed in successfully")];
|
||||
// 登录成功后切换到主 TabBar
|
||||
//注册成功后切换到主 TabBar
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSUserDefaults standardUserDefaults] setValue:email forKey:KBUserEmailKey];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
KBEmailLoginVC *vc = [[KBEmailLoginVC alloc] init];
|
||||
[KB_CURRENT_NAV pushViewController:vc animated:true];
|
||||
// id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
|
||||
@@ -33,6 +33,10 @@ typedef void(^KBVerifyMailCompletion)(BOOL success, NSError * _Nullable error);
|
||||
- (void)emailRegisterParams:(NSDictionary *)params withCompletion:(KBRegisterCompletion)completion;
|
||||
/// 发送验证码
|
||||
- (void)sendVerifyMailWithEmail:(NSString *)email withCompletion:(KBVerifyMailCompletion)completion;
|
||||
/// 验证验证码
|
||||
- (void)verifyEMailCode:(NSString *)email verifyCode:(NSString *)verifyCode withCompletion:(KBVerifyMailCompletion)completion;
|
||||
/// 重置密码
|
||||
- (void)resetPassWord:(NSString *)email password:(NSString *)password confirmPassword:(NSString *)confirmPassword withCompletion:(KBVerifyMailCompletion)completion;
|
||||
|
||||
|
||||
/// 是否已登录:由 KBAuthManager 判断(是否存在有效 token)
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
{
|
||||
[KBHUD show];
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (email.length) params[@"email"] = email;
|
||||
if (email.length) params[@"mail"] = email;
|
||||
if (password.length) params[@"password"] = password;
|
||||
// 如有本地缓存的性别(首次进入首页时选择),一并上传给后端
|
||||
NSNumber *genderNumber = [self kb_localGenderParamIfAvailable];
|
||||
@@ -132,15 +132,6 @@
|
||||
[[KBNetworkManager shared] POST:API_EMAIL_REGISTER jsonBody:params headers:nil completion:^(NSDictionary * _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
if (error) { if (completion) completion(NO, error); return; }
|
||||
NSDictionary *dict = jsonOrData[@"data"];
|
||||
KBUser *user = [KBUser mj_objectWithKeyValues:dict];
|
||||
self.currentUser = user;
|
||||
if (user.token.length == 0) {
|
||||
if (completion) completion(NO, [NSError errorWithDomain:@"KBLogin" code:-2 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"No token returned")}]);
|
||||
return;
|
||||
}
|
||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||
[KBLoginVM kb_configureIAPIfNeeded];
|
||||
if (completion) completion(YES, nil);
|
||||
}];
|
||||
}
|
||||
@@ -149,16 +140,38 @@
|
||||
- (void)sendVerifyMailWithEmail:(NSString *)email withCompletion:(KBVerifyMailCompletion)completion{
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (email.length) params[@"mailAddress"] = email;
|
||||
// [[KBNetworkManager shared] POST:API_EMAIL_REGISTER jsonBody:params headers:nil completion:^(NSDictionary * _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
// if (error) { if (completion) completion(NO, error); return; }
|
||||
// [];
|
||||
// completion(true,nil);
|
||||
// }];
|
||||
[[KBNetworkManager shared] POST:API_EMAIL_REGISTER jsonBody:params headers:nil autoShowBusinessError:true completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[[KBNetworkManager shared] POST:API_SEND_EMAIL_VERIFYMAIL jsonBody:params headers:nil autoShowBusinessError:true completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
/// 验证验证码
|
||||
- (void)verifyEMailCode:(NSString *)email verifyCode:(NSString *)verifyCode withCompletion:(KBVerifyMailCompletion)completion{
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (email.length){
|
||||
params[@"mailAddress"] = email;
|
||||
params[@"verifyCode"] = verifyCode;
|
||||
|
||||
}
|
||||
[[KBNetworkManager shared] POST:API_VERIFY_EMAIL_CODE jsonBody:params headers:nil autoShowBusinessError:true completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error) { if (completion) completion(NO, error); return; }
|
||||
if (completion) completion(YES, nil);
|
||||
}];
|
||||
|
||||
}
|
||||
/// 重置密码
|
||||
- (void)resetPassWord:(NSString *)email password:(NSString *)password confirmPassword:(NSString *)confirmPassword withCompletion:(KBVerifyMailCompletion)completion;{
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
params[@"mailAddress"] = email ? email : @"";
|
||||
params[@"password"] = password ? password : @"";
|
||||
params[@"confirmPassword"] = confirmPassword;
|
||||
|
||||
[[KBNetworkManager shared] POST:API_RESET_PWD jsonBody:params headers:nil autoShowBusinessError:true completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error) { if (completion) completion(NO, error); return; }
|
||||
if (completion) completion(YES, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
// 宽松解析:token / access_token / accessToken,支持顶层或 data/user 层
|
||||
|
||||
Reference in New Issue
Block a user