Files
real-e-party-iOS/YuMi/Modules/YMLogin/Presenter/LoginPresenter.m
edwinQQQ 7b88912b37 refactor: 移除分享相关代码以简化项目结构
主要变更:
1. 从 Podfile 中移除 FBSDKShareKit 和 mob_sharesdk 相关依赖,减少项目依赖。
2. 从 AppDelegate 和相关文件中删除 ShareSDK 初始化及相关逻辑,清理未使用的代码。
3. 删除与分享功能相关的 XPShareView 及其模型文件,简化项目结构。

此更新旨在提升项目的可维护性,减少冗余依赖,确保代码结构更加清晰。
2025-10-20 15:10:45 +08:00

371 lines
16 KiB
Objective-C

//
// LoginPresenter.m
// YUMI
//
// Created by zu on 2021/9/1.
//
#import "LoginPresenter.h"
///Third
#import <ReactiveObjC/ReactiveObjC.h>
///APi
#import "Api+Login.h"
///Tool
#import "AccountInfoStorage.h"
#import "XNDJTDDLoadingTool.h"
#import "YUMIMacroUitls.h"
///P
#import "LoginProtocol.h"
///Model
#import "ThirdUserInfo.h"
#import "AccountModel.h"
#import "DESEncrypt.h"
#import "YuMi-swift.h"
#import "FeedBackConfigModel.h"
static NSString *clinet_s = @"uyzjdhds";
@implementation LoginPresenter
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (instancetype)init{
self = [super init];
if(self){
}
return self;
}
- (id<LoginProtocol>)getView {
return ((id<LoginProtocol>) [super getView]);
}
- (void)phoneQuickLogin:(NSString *)accessToken
token:(NSString *)token {
@kWeakify(self);
[Api phoneQuickLogin:[self createHttpCompletion:^(BaseModel *data) {
@kStrongify(self);
[[AccountInfoStorage instance] saveAccountInfo:[AccountModel modelWithDictionary:data.data]];
[[self getView] loginSuccess];
} showLoading:YES] accessToken:accessToken token:token];
}
/// 第三方登录
/// @param type 登录的类型
- (void)thirdLoginWithType:(ThirdLoginType)type{
// TODO: 后续补充 Apple Login
}
-(void)loginWithThirdPartWithType:(ThirdLoginType)type{
[XNDJTDDLoadingTool showOnlyView:kWindow];
NSString * openid = [AccountInfoStorage instance].thirdUserInfo.openid;
NSString * access_token = [AccountInfoStorage instance].thirdUserInfo.access_token;
NSString * unionid = [AccountInfoStorage instance].thirdUserInfo.unionid;
@kWeakify(self);
[Api loginWithThirdPart:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
AccountModel * model = [AccountModel modelWithDictionary:data.data];
if (model != nil) {
[[AccountInfoStorage instance] saveAccountInfo:model];
[XNDJTDDLoadingTool hideOnlyView:kWindow];
[[self getView] loginThirdPartSuccess];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[XNDJTDDLoadingTool hideOnlyView:kWindow];
if (msg.length == 0) {
[[self getView] showErrorToast:YMLocalizedString(@"LoginPresenter1")];
}
} showLoading:YES errorToast:YES]
openid:openid
unionid:unionid
access_token:access_token
type:[NSString stringWithFormat:@"%lu", (unsigned long)type]];
}
-(void)thirdLoginByLine:(UIViewController *)presentingViewController {
}
-(void)thirdLoginByFBWithPresentingViewController:(UIViewController *)presentingViewController {
}
-(void)thirdLoginByGoogleWithPresentingViewController:(UIViewController *)presentingViewController configuration:(GIDConfiguration *)configuration{
@kWeakify(self);
[GIDSignIn sharedInstance].configuration = configuration;
[GIDSignIn.sharedInstance signInWithPresentingViewController:presentingViewController
completion:^(GIDSignInResult * _Nullable signInResult, NSError * _Nullable error) {
@kStrongify(self);
if (error) {
if (error.code == kGIDSignInErrorCodeCanceled){
[[self getView] showErrorToast:YMLocalizedString(@"LoginPresenter0")];
}else{
[[self getView] showErrorToast:YMLocalizedString(@"LoginPresenter1")];
}
} else {
ThirdUserInfo * userInfo = [[ThirdUserInfo alloc] init];
NSString * openid = signInResult.user.userID;
NSString * access_token = signInResult.user.idToken.tokenString.length > 0 ? signInResult.user.idToken.tokenString : @"";
NSString * unionid = signInResult.user.userID;
userInfo.userName = signInResult.user.profile.name;
userInfo.avatarUrl = [[signInResult.user.profile imageURLWithDimension:60] absoluteString];
userInfo.openid = openid;
userInfo.access_token = access_token;
userInfo.unionid = unionid;
///保存一下第三方的值
[AccountInfoStorage instance].thirdUserInfo = userInfo;
[self loginWithThirdGoogle];
}
}];
}
-(void)loginWithThirdGoogle{
[XNDJTDDLoadingTool showOnlyView:kWindow];
NSString * openid = [AccountInfoStorage instance].thirdUserInfo.openid;
NSString * access_token = [AccountInfoStorage instance].thirdUserInfo.access_token;
NSString * unionid = [AccountInfoStorage instance].thirdUserInfo.unionid;
@kWeakify(self);
[Api loginWithThirdPart:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
[XNDJTDDLoadingTool hideOnlyView:kWindow];
AccountModel * model = [AccountModel modelWithDictionary:data.data];
if (model != nil) {
[[AccountInfoStorage instance] saveAccountInfo:model];
[[self getView] loginThirdPartSuccess];
}
}fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[XNDJTDDLoadingTool hideOnlyView:kWindow];
if (msg.length == 0) {
[[self getView] showErrorToast:YMLocalizedString(@"LoginPresenter1")];
}
} showLoading:YES errorToast:YES]
openid:openid
unionid:unionid
access_token:access_token
type:[NSString stringWithFormat:@"%lu", (unsigned long)ThirdLoginType_Gmail]];
}
/// 获取手机的验证码
/// @param phone 手机号
/// @param type 类型
- (void)phoneSmsCode:(NSString *)phone type:(GetSmsType)type phoneAreaCode:(NSString *)phoneAreaCode {
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api phoneSmsCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(phoneSmsCodeSuccess:type:)]) {
NSString *message = data.message;
[[self getView] phoneSmsCodeSuccess:message type:type];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(phoneSmsCodeFailure)]) {
[[self getView] phoneSmsCodeFailure];
}
} showLoading:YES errorToast:YES] mobile:desPhone type:[NSString stringWithFormat:@"%lu", (unsigned long)type] phoneAreaCode:phoneAreaCode];
}
/// 使用手机号和验证码登录
/// @param phone 手机号
/// @param code 验证码
- (void)loginWithPhone:(NSString *)phone code:(NSString *)code phoneAreaCode:(NSString *)phoneAreaCode{
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api loginWithCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
AccountModel * accountModel = [AccountModel modelWithDictionary:data.data];
if (accountModel && accountModel.access_token.length > 0) {
[[AccountInfoStorage instance] saveAccountInfo:accountModel];
}
[[self getView] loginWithPhoenSuccess];
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[[self getView] loginFailWithMsg:msg];
} errorToast:NO] phone:desPhone code:code client_secret:clinet_s version:@"1" client_id:@"erban-client" grant_type:@"password" phoneAreaCode:phoneAreaCode];
}
/// 使用手机号和密码登录
/// @param phone 手机号
/// @param password 验证码
- (void)loginWithPhone:(NSString *)phone password:(NSString *)password {
NSString * desPassword = [DESEncrypt encryptUseDES:password key:KeyWithType(KeyType_PasswordEncode)];
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api loginWithPassword:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
AccountModel * accountModel = [AccountModel modelWithDictionary:data.data];
if (accountModel && accountModel.access_token.length > 0) {
[[AccountInfoStorage instance] saveAccountInfo:accountModel];
}
[[self getView] loginSuccess];
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[[self getView] loginFailWithMsg:msg];
} showLoading:YES errorToast:YES] phone:desPhone password:desPassword client_secret:clinet_s version:@"1" client_id:@"erban-client" grant_type:@"password"];
}
///反馈
- (void)loadFeedbackConfig:(void(^)(FeedBackConfigModel *model))success
failure:(void(^)(NSString *errorMessage))failure {
[Api loadFeedbackConfig:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
FeedBackConfigModel *model =[FeedBackConfigModel modelWithDictionary:data.data];
if (success) {
success(model);
}
} else {
if (failure) {
failure(msg);
}
}
}];
}
- (void)submitFeedback:(void(^)(void))success
failure:(void(^)(NSString *errorMessage))failure
type:(NSString *)type
desc:(NSString *)desc
photoURLString:(nullable NSString *)photoURLString
contact:(nullable NSString *)contact {
[Api commitFeedback:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
if (success) {
success();
}
} else {
if (failure) {
failure(msg);
}
}
}
type:type
desc:desc
screenUrl:photoURLString ? photoURLString : @""
contact:contact ? contact : @""];
}
- (void)sendMailVerificationCode:(NSString *)emailAddress type:(NSInteger)type {
NSString * desEmail = [DESEncrypt encryptUseDES:emailAddress key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api emailGetCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(emailCodeSucess:type:)]) {
[[self getView] emailCodeSucess:@"" type:type];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(emailCodeFailure)]) {
[[self getView] emailCodeFailure];
}
} showLoading:YES errorToast:YES]
emailAddress:desEmail type:@(type)];
}
- (void)loginWithEmail:(NSString *)email code:(NSString *)code {
NSString * desMail = [DESEncrypt encryptUseDES:email key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api loginWithCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
AccountModel * accountModel = [AccountModel modelWithDictionary:data.data];
if (accountModel && accountModel.access_token.length > 0) {
[[AccountInfoStorage instance] saveAccountInfo:accountModel];
}
if ([[self getView] respondsToSelector:@selector(loginSuccess)]) {
[[self getView] loginSuccess];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[[self getView] loginFailWithMsg:msg];
} errorToast:NO]
email:desMail
code:code
client_secret:clinet_s
version:@"1"
client_id:@"erban-client"
grant_type:@"email"];
}
- (void)bindingNewEmail:(NSString *)email code:(NSString *)code {
NSString *desMail = [DESEncrypt encryptUseDES:email key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api userBoundEmail:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(bindingNewEmailSuccess:)]) {
[[self getView] bindingNewEmailSuccess:@""];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(bindingNewEmailFailure:)]) {
[[self getView] bindingNewEmailFailure:msg];
}
} showLoading:YES errorToast:NO] email:desMail code:code];
}
- (void)bindingNewPhone:(NSString *)phone code:(NSString *)code areaCode:(NSString *)areaCode {
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api userBoundPhone:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(bindingNewPhoneSuccess:)]) {
[[self getView] bindingNewPhoneSuccess:@""];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(bindingNewPhoneFailure:)]) {
[[self getView] bindingNewPhoneFailure:msg];
}
} showLoading:YES errorToast:YES] phone:desPhone code:code phoneAreaCode:areaCode];
}
- (void)resetEmailPassword:(NSString *)email code:(NSString *)code newPassword:(NSString *)newPwd {
NSString *desMail = [DESEncrypt encryptUseDES:email key:KeyWithType(KeyType_PasswordEncode)];
NSString *desPassword = [DESEncrypt encryptUseDES:newPwd key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api resetPasswordWithEmail:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(resetEmailPasswordSuccess)]) {
[[self getView] resetEmailPasswordSuccess];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES errorToast:YES] email:desMail newPwd:desPassword code:code];
}
- (void)resetPhonePassword:(NSString *)phone code:(NSString *)code newPassword:(NSString *)newPwd areaCode:(NSString *)areaCode {
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
NSString *desPassword = [DESEncrypt encryptUseDES:newPwd key:KeyWithType(KeyType_PasswordEncode)];
@kWeakify(self);
[Api resetPasswordWithPhone:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
@kStrongify(self);
if ([[self getView] respondsToSelector:@selector(resetPhonePasswordSuccess)]) {
[[self getView] resetPhonePasswordSuccess];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES errorToast:YES] phone:desPhone newPwd:desPassword smsCode:code phoneAreaCode:areaCode];
}
- (void)checkEmailCode:(NSString *)email code:(NSString *)code {
NSString *desMail = [DESEncrypt encryptUseDES:email key:KeyWithType(KeyType_PasswordEncode)];
[Api emailVerify:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] checkEmailSuccess];
} fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES errorToast:YES] emailAddress:desMail code:code];
}
- (void)checkPhoneCode:(NSString *)phone code:(NSString *)code areaCode:(NSString *)areaCode {
NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)];
NSString * uid = [[AccountInfoStorage instance] getUid];
NSString * ticket = [[AccountInfoStorage instance] getTicket];
[Api checkMoblieCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] checkPhoneSuccess];
} fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES errorToast:YES] mobile:desPhone code:desPhone uid:uid ticket:ticket phoneAreaCode:areaCode];
}
@end