This commit is contained in:
2025-12-03 15:46:26 +08:00
parent a50d18b486
commit 6556689c8f
3 changed files with 612 additions and 75 deletions

View File

@@ -6,6 +6,10 @@
//
#import "KBEmailRegistVC.h"
#import "KBEmailLoginVC.h"
#import <AuthenticationServices/AuthenticationServices.h>
#import "KBLoginVM.h"
#import "AppDelegate.h"
@interface KBEmailRegistVC () <UITextViewDelegate, UITextFieldDelegate>
@@ -40,13 +44,13 @@
@property (nonatomic, strong) UIButton *submitButton; // 绿 Login
//
@property (nonatomic, strong) UIButton *appleLoginButton; // Continue Through Apple
@property (nonatomic, strong) UIControl *appleLoginButton; // Continue Through AppleASAuthorizationAppleIDButton
@property (nonatomic, strong) UIButton *emailLoginButton; // Continue Via Email
// &
@property (nonatomic, strong) UITextView *agreementTextView; //
@property (nonatomic, strong) UILabel *accountTipLabel; // Already Have An Account?
@property (nonatomic, strong) UIButton *switchAccountButton; // Sign In
//@property (nonatomic, strong) UILabel *accountTipLabel; // Already Have An Account?
//@property (nonatomic, strong) UIButton *switchAccountButton; // Sign In
@end
@@ -212,32 +216,32 @@
//
[self.scrollContentView addSubview:self.agreementTextView];
[self.agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.emailLoginButton.mas_bottom).offset(16);
make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16);
make.left.equalTo(self.scrollContentView).offset(30);
make.right.equalTo(self.scrollContentView).offset(-30);
}];
//
UIView *accountLine = [UIView new];
[self.scrollContentView addSubview:accountLine];
[accountLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.agreementTextView.mas_bottom).offset(16);
make.centerX.equalTo(self.scrollContentView);
make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16);
}];
// UIView *accountLine = [UIView new];
// [self.scrollContentView addSubview:accountLine];
// [accountLine mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(self.agreementTextView.mas_bottom).offset(16);
// make.centerX.equalTo(self.scrollContentView);
// make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16);
// }];
[accountLine addSubview:self.accountTipLabel];
[accountLine addSubview:self.switchAccountButton];
[self.accountTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.equalTo(accountLine);
}];
[self.switchAccountButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.accountTipLabel.mas_right).offset(4);
make.right.equalTo(accountLine);
make.centerY.equalTo(self.accountTipLabel);
}];
// [accountLine addSubview:self.accountTipLabel];
// [accountLine addSubview:self.switchAccountButton];
//
// [self.accountTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.left.bottom.equalTo(accountLine);
// }];
//
// [self.switchAccountButton mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.accountTipLabel.mas_right).offset(4);
// make.right.equalTo(accountLine);
// make.centerY.equalTo(self.accountTipLabel);
// }];
}
#pragma mark - Actions
@@ -265,6 +269,8 @@
- (void)onTapSwitchAccount {
// /
KBLOG(@"onTapSwitchAccount");
KBEmailLoginVC *vc = [[KBEmailLoginVC alloc] init];
[KB_CURRENT_NAV pushViewController:vc animated:true];
}
- (void)onTapTogglePassword:(UIButton *)sender {
@@ -279,11 +285,44 @@
}
- (void)onTapAppleLogin {
KBLOG(@"onTapAppleLogin in KBEmailRegistVC");
//
NSString *email = [self.emailTextField.text ?: @"" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *pwd = self.passwordTextField.text ?: @"";
NSString *repeat = self.repeatPasswordTextField.text ?: @"";
if (email.length == 0 || pwd.length == 0 || repeat.length == 0) {
[KBHUD showInfo:KBLocalized(@"Please complete all fields")];
return;
}
if (![pwd isEqualToString:repeat]) {
[KBHUD showInfo:KBLocalized(@"The two passwords do not match")];
return;
}
KBLOG(@"onTapAppleLogin in KBEmailRegistVC - form validated");
// Apple
[[KBLoginVM shared] signInWithAppleFromViewController:KB_CURRENT_NAV completion:^(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];
}
}];
}
- (void)onTapEmailLogin {
KBLOG(@"onTapEmailLogin in KBEmailRegistVC");
}
#pragma mark - Agreement Tap
@@ -314,6 +353,11 @@
if (hitTerms || hitPrivacy) {
KBLOG(@"tap policy in KBEmailRegistVC");
//
if (hitTerms == true) {
[KBHUD showInfo:@"hitTerms"];
}else{
[KBHUD showInfo:@"hitPrivacy"];
}
}
}
@@ -535,7 +579,7 @@
[_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_submitButton.titleLabel.font = [KBFont medium:16];
_submitButton.backgroundColor = [UIColor colorWithHex:KBColorValue];
_submitButton.layer.cornerRadius = 28.0;
_submitButton.layer.cornerRadius = 11.0;
_submitButton.layer.masksToBounds = YES;
[_submitButton addTarget:self
action:@selector(onTapSubmit)
@@ -544,22 +588,17 @@
return _submitButton;
}
- (UIButton *)appleLoginButton {
- (UIControl *)appleLoginButton {
if (!_appleLoginButton) {
_appleLoginButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_appleLoginButton setTitle:KBLocalized(@"Continue Through Apple") forState:UIControlStateNormal];
[_appleLoginButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal];
_appleLoginButton.titleLabel.font = [KBFont medium:16];
_appleLoginButton.backgroundColor = [UIColor whiteColor];
_appleLoginButton.layer.cornerRadius = 10.0;
_appleLoginButton.layer.masksToBounds = YES;
_appleLoginButton.layer.borderColor = [UIColor colorWithHex:0xE5E5E5].CGColor;
_appleLoginButton.layer.borderWidth = 1;
_appleLoginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
// Apple imageEdgeInsets
[_appleLoginButton addTarget:self
action:@selector(onTapAppleLogin)
forControlEvents:UIControlEventTouchUpInside];
ASAuthorizationAppleIDButton *btn = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeSignIn
style:ASAuthorizationAppleIDButtonStyleWhite];
[btn addTarget:self action:@selector(onTapAppleLogin) forControlEvents:UIControlEventTouchUpInside];
btn.cornerRadius = 10.0;
btn.layer.borderColor = [UIColor colorWithHex:0xE5E5E5].CGColor;
btn.layer.borderWidth = 1;
btn.layer.cornerRadius = 10.0;
btn.layer.masksToBounds = true;
_appleLoginButton = btn;
}
return _appleLoginButton;
}
@@ -569,7 +608,7 @@
_emailLoginButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_emailLoginButton setTitle:KBLocalized(@"Continue Via Email") forState:UIControlStateNormal];
[_emailLoginButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal];
_emailLoginButton.titleLabel.font = [KBFont medium:16];
_emailLoginButton.titleLabel.font = [KBFont medium:19];
_emailLoginButton.backgroundColor = [UIColor whiteColor];
_emailLoginButton.layer.cornerRadius = 10.0;
_emailLoginButton.layer.masksToBounds = YES;
@@ -656,27 +695,27 @@
return _agreementTextView;
}
- (UILabel *)accountTipLabel {
if (!_accountTipLabel) {
_accountTipLabel = [UILabel new];
_accountTipLabel.text = KBLocalized(@"Already Have An Account?");
_accountTipLabel.font = [KBFont regular:10];
_accountTipLabel.textColor = [UIColor colorWithHex:KBBlackValue];
}
return _accountTipLabel;
}
- (UIButton *)switchAccountButton {
if (!_switchAccountButton) {
_switchAccountButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_switchAccountButton setTitle:KBLocalized(@"Sign In") forState:UIControlStateNormal];
[_switchAccountButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal];
_switchAccountButton.titleLabel.font = [KBFont medium:10];
[_switchAccountButton addTarget:self
action:@selector(onTapSwitchAccount)
forControlEvents:UIControlEventTouchUpInside];
}
return _switchAccountButton;
}
//- (UILabel *)accountTipLabel {
// if (!_accountTipLabel) {
// _accountTipLabel = [UILabel new];
// _accountTipLabel.text = KBLocalized(@"Already Have An Account?");
// _accountTipLabel.font = [KBFont regular:10];
// _accountTipLabel.textColor = [UIColor colorWithHex:KBBlackValue];
// }
// return _accountTipLabel;
//}
//
//- (UIButton *)switchAccountButton {
// if (!_switchAccountButton) {
// _switchAccountButton = [UIButton buttonWithType:UIButtonTypeCustom];
// [_switchAccountButton setTitle:KBLocalized(@"Sign In") forState:UIControlStateNormal];
// [_switchAccountButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal];
// _switchAccountButton.titleLabel.font = [KBFont medium:10];
// [_switchAccountButton addTarget:self
// action:@selector(onTapSwitchAccount)
// forControlEvents:UIControlEventTouchUpInside];
// }
// return _switchAccountButton;
//}
@end