Files
real-e-party-iOS/YuMi/Modules/YMLogin/View/LoginViewController.m
edwinQQQ a35a711be6 chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
2025-10-09 16:19:14 +08:00

510 lines
19 KiB
Objective-C

//
// LoginViewController.m
// YuMi
//
// Created by P on 2025/3/10.
//
#import "LoginViewController.h"
#import "XPWebViewController.h"
#import "LoginPresenter.h"
#import "AESUtils.h"
#import "LoginTypesViewController.h"
#import "LoginProtocol.h"
#import "PILoginManager.h"
#import "PISwitchingEnvironmentVC.h"
#import "FeedBackViewController.h"
#import "FirstRechargeManager.h"
NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
typedef NS_ENUM(NSUInteger, LoginType) {
LoginType_ID = 101,
LoginType_Email = 102,
LoginType_Google = 103,
LoginType_Apple = 104
};
@interface LoginViewController () <LoginProtocol>
@property(nonatomic, strong) UIImageView *logoImageView;
@property(nonatomic, assign) BOOL lastPolicySelectedStatus;
@property(nonatomic, strong) UIButton *agreeButton;
@property(nonatomic, strong) YYLabel *policyLabel;
@property(nonatomic, strong) UIView *policyTips;
///谷歌登录配置
@property (nonatomic,strong) GIDConfiguration *configuration;
@end
@implementation LoginViewController
- (LoginPresenter *)createPresenter {
return [[LoginPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadPolicySelectedStatus];
[self setupUI];
// 进入登录页面时停止首充监控
[[FirstRechargeManager sharedManager] stopMonitoring];
}
- (void)setupUI {
[self setupBackground];
[self setupNavigationBar];
[self setupBottomPolicy];
[self setupSMSLoginEntrcy];
[self setupEntrcyButtons];
}
- (void)setupBackground {
[self.view addGradientBackgroundWithColors:@[
UIColorFromRGB(0xfcf4df),
UIColorFromRGB(0xffd374)
]
startPoint:CGPointMake(0.5, 0)
endPoint:CGPointMake(0.5, 1)
cornerRadius:0];
UIImageView *topImageView = [[UIImageView alloc] initWithImage:kImage(@"login_page_top")];
topImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:topImageView];
[topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(326));
}];
[self.view addSubview:self.logoImageView];
if (iPhoneXSeries) {
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.centerY.mas_equalTo(topImageView.mas_bottom);
make.size.mas_equalTo(CGSizeMake(124, 48));
}];
} else {
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(160);
make.size.mas_equalTo(CGSizeMake(124, 48));
}];
}
}
- (void)setupNavigationBar {
#if DEBUG
UIButton *debugButton = [self debugButton];
[self.view addSubview:debugButton];
[debugButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.view).offset(16);
make.top.mas_equalTo(self.view).offset(kStatusBarHeight);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(84);
}];
#endif
UIButton *feedBackButton = [self feedBackButton];
[self.view addSubview:feedBackButton];
[feedBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.view).offset(-16);
make.top.mas_equalTo(self.view).offset(kStatusBarHeight);
make.height.mas_equalTo(22);
// make.width.mas_lessThanOrEqualTo(200); // 设置最大宽度防止过长
}];
[self.view setNeedsLayout];
}
- (void)setupBottomPolicy {
UIView *view_1 = [[UIView alloc] init];
UIView *view_2 = [[UIView alloc] init];
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
view_1,
self.agreeButton,
self.policyLabel,
view_2
]];
stackView.spacing = 8;
stackView.alignment = UIStackViewAlignmentCenter;
stackView.distribution = UIStackViewDistributionFill;
[self.view addSubview:stackView];
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view).offset(-44);
make.width.mas_lessThanOrEqualTo(self.view).offset(-32);
// make.height.mas_equalTo(60);
}];
[self.agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(18,18));
}];
}
- (void)setupSMSLoginEntrcy {
UIButton *smsLogin = [UIButton buttonWithType:UIButtonTypeCustom];
[smsLogin setBackgroundImage:kImage(@"login_page_phone") forState:UIControlStateNormal];
[smsLogin addTarget:self action:@selector(didTapSMS) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:smsLogin];
[smsLogin mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view).offset(-124);
make.size.mas_equalTo(CGSizeMake(48, 48));
}];
}
- (void)setupEntrcyButtons {
UIButton *idBUtton = [self entrcyButton:LoginType_ID tapSelector:@selector(didTapEntrcyButton:)];
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
idBUtton,
[self entrcyButton:LoginType_Email tapSelector:@selector(didTapEntrcyButton:)],
[self entrcyButton:LoginType_Google tapSelector:@selector(didTapEntrcyButton:)],
[self entrcyButton:LoginType_Apple tapSelector:@selector(didTapEntrcyButton:)],
]];
stackView.axis = UILayoutConstraintAxisVertical;
stackView.distribution = UIStackViewDistributionFillEqually;
stackView.spacing = 14;
[self.view addSubview:stackView];
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(34);
}];
[idBUtton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(294, 46));
}];
}
- (UIButton *)entrcyButton:(LoginType)type tapSelector:(SEL)selector {
UIImageView *icon = [[UIImageView alloc] init];
icon.contentMode = UIViewContentModeScaleAspectFill;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 294, 46);
button.tag = type;
[button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
[button setCornerRadius:23];
[button setBackgroundColor:[UIColor whiteColor]];
[button.titleLabel setFont:kFontSemibold(14)];
[button.titleLabel setAdjustsFontSizeToFitWidth:YES];
[button setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal];
switch (type) {
case LoginType_ID:{
[button setTitle:YMLocalizedString(@"1.0.37_text_26") forState:UIControlStateNormal];
[icon setImage:kImage(@"login_page_id")];
}
break;
case LoginType_Email:{
[button setTitle:YMLocalizedString(@"20.20.51_text_1") forState:UIControlStateNormal];
[icon setImage:kImage(@"login_page_mail")];
}
break;
case LoginType_Google:{
[button setTitle:YMLocalizedString(@"XPLoginViewController13") forState:UIControlStateNormal];
[icon setImage:kImage(@"login_gmail")];
}
break;
case LoginType_Apple:{
[button setTitle:YMLocalizedString(@"XPLoginViewController12") forState:UIControlStateNormal];
[icon setImage:kImage(@"mine_noble_center_apple")];
}
break;
default:
break;
}
[button addSubview:icon];
[icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(button);
make.leading.mas_equalTo(15);
make.size.mas_equalTo(CGSizeMake(24, 24));
}];
return button;
}
#pragma mark -
- (void)didTapPolice:(NSString *)url {
XPWebViewController * webVC = [[XPWebViewController alloc] initWithRoomUID:nil];
webVC.url = url;
[self.navigationController pushViewController:webVC animated:YES];
}
- (void)didTapAgreeButton {
self.agreeButton.selected = !self.agreeButton.isSelected;
[self updatePolicySelectedStatus:self.agreeButton.isSelected];
[self hidePolicyTips];
}
- (void)didTapSMS {
if (self.lastPolicySelectedStatus == NO) {
[self displayPolicyTips];
return;
}
LoginTypesViewController *vc = [[LoginTypesViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc updateLoginType:LoginDisplayType_phoneNum];
}
- (void)didTapEntrcyButton:(UIButton *)sender {
if (self.lastPolicySelectedStatus == NO) {
[self displayPolicyTips];
return;
}
switch (sender.tag) {
case LoginType_ID:{
LoginTypesViewController *vc = [[LoginTypesViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc updateLoginType:LoginDisplayType_id];
}
break;
case LoginType_Email: {
LoginTypesViewController *vc = [[LoginTypesViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc updateLoginType:LoginDisplayType_email];
}
break;
case LoginType_Google:
[self.presenter thirdLoginByGoogleWithPresentingViewController:self
configuration:self.configuration];
break;
case LoginType_Apple:
[self.presenter thirdLoginWithType:ThirdLoginType_Apple];
break;
default:
break;
}
}
- (void)didTapFeedback {
FeedBackViewController *vc = [[FeedBackViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
#ifdef DEBUG
- (void)switchEnvironments {
PISwitchingEnvironmentVC *vc = [PISwitchingEnvironmentVC new];
[self.navigationController pushViewController:vc animated:YES];
}
#endif
#pragma mark - LoginProtocol
- (void)loginThirdPartSuccess {
[self showSuccessToast:YMLocalizedString(@"XPLoginViewController4")];
[PILoginManager loginWithVC:self isLoginPhone:NO];
// 登录成功后重新启动首充监控
[[FirstRechargeManager sharedManager] startMonitoring];
}
- (void)loginSuccess {
// 登录成功后重新启动首充监控
[[FirstRechargeManager sharedManager] startMonitoring];
}
#pragma mark - Polisy Status
- (void)loadPolicySelectedStatus {
// 默认 YES
[self updatePolicySelectedStatus:YES];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.lastPolicySelectedStatus = [defaults boolForKey:HadAgreePrivacy];
self.agreeButton.selected = self.lastPolicySelectedStatus;
}
- (void)updatePolicySelectedStatus:(BOOL)isSelected {
self.lastPolicySelectedStatus = isSelected;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:isSelected forKey:HadAgreePrivacy];
}
- (void)displayPolicyTips {
[self.view addSubview:self.policyTips];
[self.policyTips mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.view).offset(-82);
make.leading.trailing.mas_equalTo(self.view).inset(22);
make.height.mas_equalTo(64);
}];
}
- (void)hidePolicyTips {
[self.policyTips removeFromSuperview];
}
#pragma mark - Lazy init
- (UIButton *)agreeButton {
if(!_agreeButton) {
_agreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_agreeButton setImage:[UIImage imageNamed:@"login_page_privacy_selected"] forState:UIControlStateSelected];
[_agreeButton setImage:[UIImage imageNamed:@"login_page_privacy_unselected"] forState:UIControlStateNormal];
[_agreeButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_agreeButton addTarget:self action:@selector(didTapAgreeButton) forControlEvents:UIControlEventTouchUpInside];
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// NSString *hadAgree = [defaults objectForKey:HadAgreePrivacy];
// if (hadAgree.length > 0) {
// _agreeBtn.selected = YES;
// }
_agreeButton.selected = YES;
}
return _agreeButton;
}
- (YYLabel *)policyLabel {
if (!_policyLabel) {
_policyLabel = [[YYLabel alloc] init];
_policyLabel.font = kFontRegular(12);
_policyLabel.numberOfLines = 0;
_policyLabel.preferredMaxLayoutWidth = KScreenWidth-40;
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginViewController6")];
if ([[UIScreen mainScreen] bounds].size.width < 450 && (isMSPT() || isMSTR())) {
attString = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginViewController6.1")];
}
attString.yy_color = UIColorFromRGB(0x7B7B7D);
NSRange userRange = [attString.string rangeOfString:YMLocalizedString(@"XPLoginViewController7")];
[attString addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x313131)} range:userRange];
@kWeakify(self);
[attString yy_setTextHighlightRange:userRange color:nil backgroundColor:nil userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
// 跳转用户协议
[self didTapPolice:URLWithType(kUserProtocalURL)];
} longPressAction:nil];
NSRange andRange = [attString.string rangeOfString:YMLocalizedString(@"XPLoginViewController8")];
[attString addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x7B7B7D)} range:andRange];
NSRange protocolRange = [attString.string rangeOfString:YMLocalizedString(@"XPLoginViewController9")];
[attString addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x313131)} range:protocolRange];
[attString yy_setTextHighlightRange:protocolRange color:nil backgroundColor:nil userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
// 跳转隐私政策
[self didTapPolice:URLWithType(kPrivacyURL)];
} longPressAction:nil];
_policyLabel.attributedText = attString;
}
return _policyLabel;
}
- (UIView *)policyTips {
if (!_policyTips) {
_policyTips = [[UIView alloc] init];
[_policyTips setCornerRadius:8];
[_policyTips setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.5]];
UILabel *_policyTipsLabel = [[UILabel alloc] init];
_policyTipsLabel.text = YMLocalizedString(@"XPLoginViewController11");
_policyTipsLabel.font = kFontRegular(12);
_policyTipsLabel.textColor = UIColor.whiteColor;
_policyTipsLabel.numberOfLines = 0;
_policyTipsLabel.textAlignment = NSTextAlignmentCenter;
[_policyTips addSubview:_policyTipsLabel];
[_policyTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(_policyTips).insets(UIEdgeInsetsMake(8, 12, 8, 12));
}];
}
return _policyTips;
}
- (GIDConfiguration *)configuration{
if (!_configuration){
static dispatch_once_t onceToken;
static NSString *decryptedNumber;
dispatch_once(&onceToken, ^{
decryptedNumber = [AESUtils aesDecrypt:@"ScLBu7ctIiyGCKPro3Jj6XMdsdCCpNT9L4wyjHEF+bguqubkXNSayFBGMKmoDwe1hjfAc958XSaBdMyEaFXLO38Bwq3xURYVNpgEM4b14zg="];
});
_configuration = [[GIDConfiguration alloc] initWithClientID:decryptedNumber];
}
return _configuration;
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] initWithImage:kImage(@"login_page_logo")];
}
return _logoImageView;
}
- (UIButton *)feedBackButton {
UIButton *feedBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
[feedBackButton setTitle:YMLocalizedString(@"XPMineFeedbackViewController0") forState:UIControlStateNormal];
[feedBackButton setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal];
[feedBackButton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
feedBackButton.titleLabel.font = kFontRegular(12);
// 设置文本自适应,防止截断
// feedBackButton.titleLabel.adjustsFontSizeToFitWidth = YES;
// feedBackButton.titleLabel.minimumScaleFactor = 0.8;
// feedBackButton.titleLabel.numberOfLines = 1;
[feedBackButton setBackgroundImage:[[UIImage imageWithColor:[UIColor whiteColor]] imageByApplyingAlpha:0.5]
forState:UIControlStateNormal];
[feedBackButton setCornerRadius:10.5];
[feedBackButton addTarget:self
action:@selector(didTapFeedback)
forControlEvents:UIControlEventTouchUpInside];
[feedBackButton sizeToFit];
// [feedBackButton enlargeTouchArea:UIEdgeInsetsMake(10, 10, 10, 10)];
return feedBackButton;
}
#if DEBUG
- (UIButton *)debugButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(0, 0, 84, 22);
[b setTitle:@"切换环境" forState:UIControlStateNormal];
[b setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.view addSubview:b];
[b addTarget:self action:@selector(switchEnvironments) forControlEvents:UIControlEventTouchUpInside];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = b.bounds;
gradientLayer.colors = @[
(id)[UIColor redColor].CGColor,
(id)[UIColor blueColor].CGColor,
(id)[UIColor greenColor].CGColor
];
gradientLayer.startPoint = CGPointMake(0, 0.5);
gradientLayer.endPoint = CGPointMake(1, 0.5);
[b.layer addSublayer:gradientLayer];
@kWeakify(self);
[NSTimer scheduledTimerWithTimeInterval:0.1
repeats:YES
block:^(NSTimer * _Nonnull timer) {
@kStrongify(self);
if (!self) {
return;
}
NSArray *fromColors = gradientLayer.colors;
NSArray *toColors = [self shiftedColorsFromColors:fromColors];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"colors"];
animation.fromValue = fromColors;
animation.toValue = toColors;
animation.duration = 0.1;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
[gradientLayer addAnimation:animation forKey:@"colorChange"];
gradientLayer.colors = toColors;
}];
return b;
}
- (NSArray *)shiftedColorsFromColors:(NSArray *)colors {
NSMutableArray *mutableColors = [colors mutableCopy];
id firstColor = [mutableColors firstObject];
[mutableColors xpSafeRemoveObjectAtIndex:0];
[mutableColors addObject:firstColor];
return [mutableColors copy];
}
#endif
@end