|
//
// writeCommentViewModel.m
// ThePaperBase
//
// Created by scar1900 on 15/8/14.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "userSystemViewModel.h"
#import "shareUtil.h"
#define LoginTag 1000
#define thirdTag 1001
@interface userSystemViewModel()<RemoteDelegate> {
}
@end
@implementation userSystemViewModel
@synthesize delegate;
@synthesize userName,password,thirdLoginType;
- (id)init {
self = [super init];
if (self) {
}
return self;
}
- (void)customLogin {
if (!userName || isBlankString(userName) || !password || isBlankString(password)) {
ShowTextMessage(@"账号或密码不能为空!");
return;
}
NSDictionary *dic = @{@"loginName":userName,@"pwd":password};
[Remote doJsonAction:LoginTag
requestUrl:loginURL
parameter:dic
delegate:self];
thirdLoginType = @"-1";
}
- (void)wechatSocietyLogin{
[shareUtil weChatLogin:^(BOOL isSuccess,NSDictionary *dic) {
if (isSuccess) {
NSDictionary *tempDic = @{@"weiboType":@"WEIXIN",
@"otype":@"1",
@"uid":dic[@"unionid"],
@"token":[shareUtil getTokenWithType:weChatLoginType],
@"name":dic[@"nickname"],
@"pic":dic[@"headimgurl"]};
thirdLoginType = [NSString stringWithFormat:@"%d",weChatLoginType];
[self loginBySocietyAccount:tempDic];
}
}];
}
- (void)QQSocietyLogin{
[shareUtil qqLogin:^(BOOL isSuccess, NSDictionary *dic) {
if (isSuccess) {
NSDictionary *tempDic = @{@"weiboType":@"TENCENT",
@"otype":@"1",
@"uid":[[shareUtil instance].tencentOAuth openId],
@"token":[shareUtil getTokenWithType:QQLoginType],
@"name":dic[@"nickname"],
@"pic":dic[@"figureurl_qq_1"]};
thirdLoginType = [NSString stringWithFormat:@"%d",QQLoginType];
[self loginBySocietyAccount:tempDic];
}
}];
}
- (void)sinaSocietyLogin {
[shareUtil sinaLogin:^(BOOL isSuccess,NSDictionary *dic) {
if (isSuccess) {
NSDictionary *tempDic = @{@"weiboType":@"SINA",
@"otype":@"1",
@"uid":dic[@"id"],
@"token":[shareUtil getTokenWithType:sinaWeiBoLoginType],
@"name":dic[@"name"],
@"pic":dic[@"avatar_hd"]};
thirdLoginType = [NSString stringWithFormat:@"%d",sinaWeiBoLoginType];
[self loginBySocietyAccount:tempDic];
}
}];
}
//【需求】分享:豆瓣登录、绑定、分享(bug:4556)
- (void)doubanSocietyLogin{
[shareUtil doubanLogin:^(BOOL isSuccess,NSDictionary *dic) {
if (isSuccess) {
NSDictionary *tempDic = @{@"weiboType":@"DOUBAN",
@"otype":@"1",
@"uid":dic[@"id"],
@"token":[shareUtil getTokenWithType:doubanLoginType],
@"name":dic[@"name"],
@"pic":dic[@"avatar"]};
thirdLoginType = [NSString stringWithFormat:@"%d",doubanLoginType];
[self loginBySocietyAccount:tempDic];
}
}];
}
- (void)loginBySocietyAccount:(NSDictionary*)dic {
[Remote doJsonAction:thirdTag requestUrl:societyFromSDKURL parameter:dic delegate:self];
}
- (void)getInviteCode {
TPLOG(@"%@", [TPUserDefault instance].registerBO.mail);
if (![TPUserDefault instance].registerBO.mail || isBlankString([TPUserDefault instance].registerBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
NSDictionary *dic = @{@"verType":@"1",@"mail":[TPUserDefault instance].registerBO.mail};
[Remote doJsonActionWithBlock:0 requestUrl:getVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
ShowTextMessage(responseData[@"resultMsg"]);
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)confirmMobileAndEmail{
if (![TPUserDefault instance].registerBO.mail || isBlankString([TPUserDefault instance].registerBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
if (![TPUserDefault instance].registerBO.verCode || isBlankString([TPUserDefault instance].registerBO.verCode)) {
ShowTextMessage(@"请输入邀请码");
return;
}
NSDictionary *dic = @{@"verType":@"1",@"mail":[TPUserDefault instance].registerBO.mail,@"verCode":[TPUserDefault instance].registerBO.verCode};
__weak typeof(self) weakSelf = self;
[Remote doJsonActionWithBlock:0 requestUrl:checkVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
if ([weakSelf.delegate respondsToSelector:@selector(confirmInviteCodeSuccess)]) {
[weakSelf.delegate confirmInviteCodeSuccess];
}
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)confirmRegister:(UIButton*)selectBtn{
if (![TPUserDefault instance].registerBO.sname || isBlankString([TPUserDefault instance].registerBO.sname)) {
ShowTextMessage(@"请输入用户名");
return;
}
if (![TPUserDefault instance].registerBO.pwd || isBlankString([TPUserDefault instance].registerBO.pwd)) {
ShowTextMessage(@"请输入密码");
return;
}
if (!selectBtn.selected) {
ShowTextMessage(@"请同意相关注册协定");
return;
}
NSDictionary *dic = @{@"mail":[TPUserDefault instance].registerBO.mail,@"verCode":[TPUserDefault instance].registerBO.verCode
,@"sname":[TPUserDefault instance].registerBO.sname,@"pwd":[TPUserDefault instance].registerBO.pwd};
__weak typeof(self) weakSelf = self;
[Remote doJsonActionWithBlock:0
requestUrl:registerURL
parameter:dic
withWaitCursor:YES
completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSDictionary *userInfo = responseData[@"userInfo"];
[TPUserDefault instance].userBO = setJsonDicToDataModel(userInfo, [userBO class]);
/**
* 修复bug:0003598
*/
[TPUserDefault instance].registerBO = nil;
if ([weakSelf.delegate respondsToSelector:@selector(registerSuccess)]) {
[weakSelf.delegate registerSuccess];
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)getVerifyCode {
if (![TPUserDefault instance].fogetPwdInfoBO.mail || isBlankString([TPUserDefault instance].fogetPwdInfoBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
NSDictionary *dic = @{@"verType":@"3",@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail};
[Remote doJsonActionWithBlock:0 requestUrl:getVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
ShowTextMessage(responseData[@"resultMsg"]);
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)confirmVerifyCode {
if (![TPUserDefault instance].fogetPwdInfoBO.mail || isBlankString([TPUserDefault instance].fogetPwdInfoBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
if (![TPUserDefault instance].fogetPwdInfoBO.verCode || isBlankString([TPUserDefault instance].fogetPwdInfoBO.verCode)) {
ShowTextMessage(@"请输入验证码");
return;
}
NSDictionary *dic = @{@"verType":@"3",@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail,@"verCode":[TPUserDefault instance].fogetPwdInfoBO.verCode};
__weak typeof(self) weakSelf = self;
[Remote doJsonActionWithBlock:0 requestUrl:checkVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
if ([weakSelf.delegate respondsToSelector:@selector(confirmVerifyCodeSuccess)]) {
[weakSelf.delegate confirmVerifyCodeSuccess];
}
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)confirmModifyPassword {
if (![TPUserDefault instance].fogetPwdInfoBO.pwd || isBlankString([TPUserDefault instance].fogetPwdInfoBO.pwd)) {
ShowTextMessage(@"请输入密码");
return;
}
NSDictionary *dic = @{@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail,@"verCode":[TPUserDefault instance].fogetPwdInfoBO.verCode
,@"pwd":[TPUserDefault instance].fogetPwdInfoBO.pwd};
__weak typeof(self) weakSelf = self;
[Remote doJsonActionWithBlock:0
requestUrl:resetPwdURL
parameter:dic
withWaitCursor:YES
completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSDictionary *userInfo = responseData[@"userInfo"];
[TPUserDefault instance].userBO = setJsonDicToDataModel(userInfo, [userBO class]);
/**
* 修复bug:0003598
*/
[TPUserDefault instance].fogetPwdInfoBO= nil;
if ([weakSelf.delegate respondsToSelector:@selector(modifyPasswordSuccess)]) {
[weakSelf.delegate modifyPasswordSuccess];
}
}else {
ShowTextMessage(message);
}
}];
}
#pragma mark - remote delgate
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
userBO *user = setJsonDicToDataModel(responsData[@"userInfo"], [userBO class]);
user.loginType = thirdLoginType;
[TPUserDefault instance].userBO = user;
[[TPUserDefault instance] checkMsgMarkStatus];
if ([self.delegate respondsToSelector:@selector(customLoginSuccess)]) {
[self.delegate customLoginSuccess];
}
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{
ShowTextMessage(message);
}
@end
|