1
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
// 兼容旧命名(如有使用 API_APPLE_LOGIN 的位置,映射到统一命名)
|
// 兼容旧命名(如有使用 API_APPLE_LOGIN 的位置,映射到统一命名)
|
||||||
#define API_APPLE_LOGIN @"/user/appleLogin" // Apple 登录
|
#define API_APPLE_LOGIN @"/user/appleLogin" // Apple 登录
|
||||||
#define API_EMAIL_LOGIN @"/user/login" // email 登录
|
#define API_EMAIL_LOGIN @"/user/login" // email 登录
|
||||||
|
#define API_EMAIL_REGISTER @"/user/register" // email 注册
|
||||||
|
|
||||||
#define API_LOGOUT @"/user/logout" // 退出登录
|
#define API_LOGOUT @"/user/logout" // 退出登录
|
||||||
|
|
||||||
#define API_UPDATA_INFO @"/user/updateInfo" // 更新用户
|
#define API_UPDATA_INFO @"/user/updateInfo" // 更新用户
|
||||||
|
|||||||
@@ -276,8 +276,14 @@
|
|||||||
|
|
||||||
KBLOG(@"onTapSubmit email=%@, password length=%zd", email, pwd.length);
|
KBLOG(@"onTapSubmit email=%@, password length=%zd", email, pwd.length);
|
||||||
|
|
||||||
|
|
||||||
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||||
|
params[@"mailAddress"] = email;
|
||||||
|
params[@"password"] = pwd;
|
||||||
|
params[@"passwordConfirm"] = repeat;
|
||||||
|
|
||||||
KBRegistVerEmailVC *vc = [[KBRegistVerEmailVC alloc] init];
|
KBRegistVerEmailVC *vc = [[KBRegistVerEmailVC alloc] init];
|
||||||
vc.email = email;
|
vc.params = params;
|
||||||
UINavigationController *nav = KB_CURRENT_NAV;
|
UINavigationController *nav = KB_CURRENT_NAV;
|
||||||
if ([nav isKindOfClass:[BaseNavigationController class]]) {
|
if ([nav isKindOfClass:[BaseNavigationController class]]) {
|
||||||
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
|
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface KBRegistVerEmailVC : BaseViewController
|
@interface KBRegistVerEmailVC : BaseViewController
|
||||||
|
|
||||||
/// 注册时用于邮箱验证的邮箱地址,由上一个页面(KBEmailRegistVC)传入。
|
/// 注册时用于邮箱验证的邮箱地址,由上一个页面(KBEmailRegistVC)传入。
|
||||||
@property (nonatomic, copy) NSString *email;
|
//@property (nonatomic, copy) NSString *email;
|
||||||
|
@property (nonatomic, strong) NSMutableDictionary *params;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#import "KBRegistVerEmailVC.h"
|
#import "KBRegistVerEmailVC.h"
|
||||||
#import "CRBoxInputView.h"
|
#import "CRBoxInputView.h"
|
||||||
|
#import "KBLoginVM.h"
|
||||||
|
#import "KBUser.h"
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
@interface KBRegistVerEmailVC ()
|
@interface KBRegistVerEmailVC ()
|
||||||
|
|
||||||
@@ -15,6 +18,7 @@
|
|||||||
@property (nonatomic, strong) CRBoxInputView *codeInputView;
|
@property (nonatomic, strong) CRBoxInputView *codeInputView;
|
||||||
@property (nonatomic, strong) UILabel *descLabel; // 多行提示文案
|
@property (nonatomic, strong) UILabel *descLabel; // 多行提示文案
|
||||||
@property (nonatomic, strong) UIButton *confirmButton; // Confirm
|
@property (nonatomic, strong) UIButton *confirmButton; // Confirm
|
||||||
|
@property (nonatomic, strong) KBLoginVM *loginVM; // Confirm
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -23,6 +27,7 @@
|
|||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
self.view.backgroundColor = [UIColor whiteColor];
|
self.view.backgroundColor = [UIColor whiteColor];
|
||||||
|
self.loginVM = [[KBLoginVM alloc] init];
|
||||||
self.kb_titleLabel.text = KBLocalized(@"Verify Email");
|
self.kb_titleLabel.text = KBLocalized(@"Verify Email");
|
||||||
[self kb_addTapToDismissKeyboard];
|
[self kb_addTapToDismissKeyboard];
|
||||||
|
|
||||||
@@ -83,8 +88,42 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KBLOG(@"KBRegistVerEmailVC confirm with code=%@", code);
|
KBLOG(@"KBRegistVerEmailVC confirm with code=%@", code);
|
||||||
// TODO: 注册流程中验证邮箱验证码的逻辑
|
self.params[@"code"] = code;
|
||||||
[KBHUD showInfo:@"验证通过后跳转邮箱登录页面"];
|
NSNumber *genderNumber = [self kb_localGenderParamIfAvailable];
|
||||||
|
if (genderNumber != nil) {
|
||||||
|
self.params[@"gender"] = genderNumber;
|
||||||
|
}
|
||||||
|
[self.loginVM emailRegisterParams:self.params withCompletion:^(BOOL success, NSError * _Nullable error) {
|
||||||
|
if (success) {
|
||||||
|
[KBHUD showInfo:KBLocalized(@"Signed in successfully")];
|
||||||
|
// 登录成功后切换到主 TabBar
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||||
|
if ([appDelegate respondsToSelector:@selector(setupRootVC)]) {
|
||||||
|
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||||
|
[delegate toMainTabbarVC];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
NSString *msg = error.localizedDescription ?: KBLocalized(@"Sign-in failed");
|
||||||
|
[KBHUD showInfo:msg];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSNumber *)kb_localGenderParamIfAvailable {
|
||||||
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||||
|
// 只有在用户真正看过性别选择页后,才认为本地的性别有效
|
||||||
|
BOOL hasShownSexVC = [ud boolForKey:KBSexSelectShownKey];
|
||||||
|
if (!hasShownSexVC) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSInteger value = [ud integerForKey:KBSexSelectedGenderKey];
|
||||||
|
if (value < UserSexMan || value > UserSexTwoSex) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
return @(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Lazy UI
|
#pragma mark - Lazy UI
|
||||||
@@ -152,8 +191,9 @@
|
|||||||
// 这里用 %@ 预留邮箱地址占位
|
// 这里用 %@ 预留邮箱地址占位
|
||||||
NSString *template = KBLocalized(@"We have already sent it to the email address %@. Please enter the 6-digit verification code from the email to verify your mailbox.");
|
NSString *template = KBLocalized(@"We have already sent it to the email address %@. Please enter the 6-digit verification code from the email to verify your mailbox.");
|
||||||
// 使用上个页面传入的邮箱;若为空则使用占位邮箱
|
// 使用上个页面传入的邮箱;若为空则使用占位邮箱
|
||||||
NSString *email = self.email.length > 0 ? self.email : @"example@mail.com";
|
NSString *email = self.params[@"mailAddress"];
|
||||||
_descLabel.text = [NSString stringWithFormat:template, email];
|
NSString *reEmail = email.length > 0 ? email : @"example@mail.com";
|
||||||
|
_descLabel.text = [NSString stringWithFormat:template, reEmail];
|
||||||
}
|
}
|
||||||
return _descLabel;
|
return _descLabel;
|
||||||
}
|
}
|
||||||
@@ -173,4 +213,10 @@
|
|||||||
return _confirmButton;
|
return _confirmButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSMutableDictionary *)params{
|
||||||
|
if (!_params) {
|
||||||
|
_params = [NSMutableDictionary dictionary];
|
||||||
|
}
|
||||||
|
return _params;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
/// 登录完成回调
|
/// 登录完成回调
|
||||||
typedef void(^KBLoginCompletion)(BOOL success, NSError * _Nullable error);
|
typedef void(^KBLoginCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
|
typedef void(^KBRegisterCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
|
|
||||||
@interface KBLoginVM : NSObject
|
@interface KBLoginVM : NSObject
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ typedef void(^KBLoginCompletion)(BOOL success, NSError * _Nullable error);
|
|||||||
|
|
||||||
/// 邮箱登录
|
/// 邮箱登录
|
||||||
- (void)emailLoginEmail:(NSString *)email password:(NSString *)password WithCompletion:(KBLoginCompletion)completion;
|
- (void)emailLoginEmail:(NSString *)email password:(NSString *)password WithCompletion:(KBLoginCompletion)completion;
|
||||||
|
/// 邮箱注册
|
||||||
|
- (void)emailRegisterParams:(NSDictionary *)params withCompletion:(KBRegisterCompletion)completion;
|
||||||
|
|
||||||
/// 是否已登录:由 KBAuthManager 判断(是否存在有效 token)
|
/// 是否已登录:由 KBAuthManager 判断(是否存在有效 token)
|
||||||
- (BOOL)isLoggedIn;
|
- (BOOL)isLoggedIn;
|
||||||
|
|||||||
@@ -100,12 +100,35 @@
|
|||||||
}
|
}
|
||||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||||
completion(true,nil);
|
completion(true,nil);
|
||||||
// 保存登录态到共享钥匙串;供 App 与扩展共享
|
}];
|
||||||
// BOOL ok = [[KBAuthManager shared] saveAccessToken:user.token
|
}
|
||||||
// refreshToken:nil
|
|
||||||
// expiryDate:nil
|
/// 邮箱注册
|
||||||
// userIdentifier:cred.user];
|
- (void)emailRegisterParams:(NSDictionary *)params withCompletion:(KBRegisterCompletion)completion{
|
||||||
// if (completion) completion(ok, ok ? nil : [NSError errorWithDomain:@"KBLogin" code:-3 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Failed to save login state")}]);
|
[KBHUD show];
|
||||||
|
// NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||||
|
// if (mailAddress.length) params[@"mailAddress"] = mailAddress;
|
||||||
|
// if (password.length) params[@"password"] = password;
|
||||||
|
// if (passwordConfirm.length) params[@"passwordConfirm"] = passwordConfirm;
|
||||||
|
//
|
||||||
|
// // 如有本地缓存的性别(首次进入首页时选择),一并上传给后端
|
||||||
|
// NSNumber *genderNumber = [self kb_localGenderParamIfAvailable];
|
||||||
|
// if (genderNumber != nil) {
|
||||||
|
// params[@"gender"] = genderNumber;
|
||||||
|
// }
|
||||||
|
// 向服务端发起校验
|
||||||
|
[[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];
|
||||||
|
completion(true,nil);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user