This commit is contained in:
2025-12-08 16:39:47 +08:00
parent 0a1c30f669
commit fd8c08316b
30 changed files with 306 additions and 85 deletions

View File

@@ -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;

View File

@@ -10,6 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface KBForgetPwdNewPwdVC : BaseViewController
@property (nonatomic, copy) NSString *email;
@end

View File

@@ -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

View File

@@ -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];

View File

@@ -10,6 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface KBForgetVerPwdVC : BaseViewController
@property (nonatomic, copy) NSString *email;
@end

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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