Skip to content

Commit cbdb4d2

Browse files
committed
找回密码方式改版
1 parent 1e3693e commit cbdb4d2

11 files changed

Lines changed: 308 additions & 101 deletions

Coding_iOS/Controllers/Login/CannotLoginViewController.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
//
88

99
#import "BaseViewController.h"
10-
typedef NS_ENUM(NSInteger, CannotLoginType) {
11-
CannotLoginTypeResetPassword = 0,
12-
CannotLoginTypeActivate,
13-
};
10+
#import "Coding_NetAPIManager.h"
1411

12+
typedef NS_ENUM(NSInteger, CannotLoginMethodType) {
13+
CannotLoginMethodEamil = 0,
14+
CannotLoginMethodPhone
15+
};
1516

1617
@interface CannotLoginViewController : BaseViewController
17-
@property (nonatomic, assign) CannotLoginType type;
1818

19-
@property (strong, nonatomic) NSString *email, *j_captcha;
19+
+ (instancetype)vcWithPurposeType:(PurposeType)purposeType methodType:(CannotLoginMethodType)methodType stepIndex:(NSUInteger)stepIndex userStr:(NSString *)userStr;
2020

2121
@end

Coding_iOS/Controllers/Login/CannotLoginViewController.m

Lines changed: 191 additions & 70 deletions
Large diffs are not rendered by default.

Coding_iOS/Controllers/Login/LoginViewController.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,15 @@ - (void)sendLogin{
430430
}
431431

432432
- (IBAction)cannotLoginBtnClicked:(id)sender {
433-
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"找回密码", @"重发激活邮件"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
433+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"忘记密码?", @"已注册,未设置密码?"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
434434
if (index <= 1) {
435435
[self goToCannotLoginWithIndex:index];
436436
}
437437
}] showInView:self.view];
438438
}
439439

440440
- (void)goToCannotLoginWithIndex:(NSInteger)index{
441-
CannotLoginViewController *vc = [[CannotLoginViewController alloc] init];
442-
vc.type = index;
441+
CannotLoginViewController *vc = [CannotLoginViewController vcWithPurposeType:(index == 0? PurposeToPasswordReset: PurposeToPasswordActivate) methodType:0 stepIndex:0 userStr:self.myLogin.email];
443442
[self.navigationController pushViewController:vc animated:YES];
444443
}
445444

Coding_iOS/Controllers/Login/RegisterViewController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ - (void)gotoServiceTermsVC{
285285
}
286286

287287
- (void)gotoCannotLoginVC{
288-
CannotLoginViewController *vc = [[CannotLoginViewController alloc] init];
289-
vc.type = CannotLoginTypeActivate;
288+
CannotLoginViewController *vc = [CannotLoginViewController vcWithPurposeType:PurposeToPasswordActivate methodType:0 stepIndex:0 userStr:self.myRegister.email];
290289
[self.navigationController pushViewController:vc animated:YES];
291290
}
292291

Coding_iOS/Models/Register.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
//请求
1313
@property (readwrite, nonatomic, strong) NSString *email, *global_key, *j_captcha;
1414

15+
+ (NSString *)channel;
16+
1517
- (NSDictionary *)toParams;
1618
@end

Coding_iOS/Models/Register.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2014年 Coding. All rights reserved.
77
//
88

9-
#define kRegisterChannel @"coding-ios"
10-
119
#import "Register.h"
1210

1311
@implementation Register
@@ -25,6 +23,10 @@ - (NSDictionary *)toParams{
2523
return @{@"email" : self.email,
2624
@"global_key" : self.global_key,
2725
@"j_captcha" : _j_captcha? _j_captcha: @"",
28-
@"channel" : kRegisterChannel};
26+
@"channel" : [Register channel]};
27+
}
28+
29+
+ (NSString *)channel{
30+
return @"coding-ios";
2931
}
3032
@end

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ typedef NS_ENUM(NSUInteger, VerifyType){
4646
VerifyTypeTotp,
4747
};
4848

49+
typedef NS_ENUM(NSInteger, PurposeType) {
50+
PurposeToRegister = 0,
51+
PurposeToPasswordActivate,
52+
PurposeToPasswordReset
53+
};
54+
4955
@interface Coding_NetAPIManager : NSObject
5056
+ (instancetype)sharedManager;
5157

@@ -59,8 +65,10 @@ typedef NS_ENUM(NSUInteger, VerifyType){
5965
- (void)request_Login_WithPath:(NSString *)path Params:(id)params andBlock:(void (^)(id data, NSError *error))block;
6066
- (void)request_Register_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block;
6167
- (void)request_CaptchaNeededWithPath:(NSString *)path andBlock:(void (^)(id data, NSError *error))block;
62-
- (void)request_SendMailToPath:(NSString *)path email:(NSString *)email j_captcha:(NSString *)j_captcha andBlock:(void (^)(id data, NSError *error))block;
6368
- (void)request_SetPasswordToPath:(NSString *)path params:(NSDictionary *)params andBlock:(void (^)(id data, NSError *error))block;
69+
- (void)request_GeneratePhoneCodeWithPhone:(NSString *)phone type:(PurposeType)type block:(void (^)(id data, NSError *error))block;
70+
- (void)request_SetPasswordWithPhone:(NSString *)phone code:(NSString *)code password:(NSString *)password captcha:(NSString *)captcha type:(PurposeType)type block:(void (^)(id data, NSError *error))block;
71+
- (void)request_SetPasswordWithEmail:(NSString *)email captcha:(NSString *)captcha type:(PurposeType)type block:(void (^)(id data, NSError *error))block;
6472

6573
//Project
6674
- (void)request_Projects_WithObj:(Projects *)projects andBlock:(void (^)(Projects *data, NSError *error))block;

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <NYXImagesKit/NYXImagesKit.h>
1313
#import <MMMarkdown/MMMarkdown.h>
1414
#import "MBProgressHUD+Add.h"
15+
#import "Register.h"
1516

1617
@implementation Coding_NetAPIManager
1718
+ (instancetype)sharedManager {
@@ -131,27 +132,87 @@ - (void)request_CaptchaNeededWithPath:(NSString *)path andBlock:(void (^)(id dat
131132
}];
132133
}
133134

134-
- (void)request_SendMailToPath:(NSString *)path email:(NSString *)email j_captcha:(NSString *)j_captcha andBlock:(void (^)(id data, NSError *error))block{
135-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:@{@"email": email, @"j_captcha": j_captcha} withMethodType:Get andBlock:^(id data, NSError *error) {
135+
- (void)request_SetPasswordToPath:(NSString *)path params:(NSDictionary *)params andBlock:(void (^)(id data, NSError *error))block{
136+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
136137
if (data) {
137-
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"发激活or重置密码邮件"];
138+
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"激活or重置密码"];
138139

139140
block(data, nil);
140141
}else{
141142
block(nil, error);
142143
}
143144
}];
144145
}
145-
146-
- (void)request_SetPasswordToPath:(NSString *)path params:(NSDictionary *)params andBlock:(void (^)(id data, NSError *error))block{
146+
- (void)request_GeneratePhoneCodeWithPhone:(NSString *)phone type:(PurposeType)type block:(void (^)(id data, NSError *error))block{
147+
NSString *path;
148+
NSDictionary *params = @{@"phone": phone};
149+
switch (type) {
150+
case PurposeToRegister:
151+
path = @"api/account/register/generate_phone_code";
152+
break;
153+
case PurposeToPasswordActivate:
154+
path = @"api/account/activate/generate_phone_code";
155+
break;
156+
case PurposeToPasswordReset:
157+
path = @"api/account/reset_password/generate_phone_code";
158+
break;
159+
}
160+
147161
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
148162
if (data) {
149-
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"激活or重置密码"];
150-
151-
block(data, nil);
152-
}else{
153-
block(nil, error);
163+
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"生成手机验证码"];
164+
}
165+
block(data, error);
166+
}];
167+
}
168+
- (void)request_SetPasswordWithPhone:(NSString *)phone code:(NSString *)code password:(NSString *)password captcha:(NSString *)captcha type:(PurposeType)type block:(void (^)(id data, NSError *error))block{
169+
NSString *path = @"api/account/register/phone";
170+
NSMutableDictionary *params = @{@"phone": phone,
171+
@"code": code,
172+
@"password": [password sha1Str]}.mutableCopy;
173+
switch (type) {
174+
case PurposeToRegister:{
175+
path = @"api/account/register/phone";
176+
params[@"channel"] = [Register channel];
177+
break;
178+
}
179+
case PurposeToPasswordActivate:
180+
path = @"api/account/activate/phone/set_password";
181+
break;
182+
case PurposeToPasswordReset:
183+
path = @"api/phone/resetPassword";
184+
break;
185+
}
186+
if (captcha.length > 0) {
187+
params[@"j_captcha"] = captcha;
188+
}
189+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
190+
if (data) {
191+
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"设置or重置密码"];
192+
}
193+
block(data, error);
194+
}];
195+
}
196+
- (void)request_SetPasswordWithEmail:(NSString *)email captcha:(NSString *)captcha type:(PurposeType)type block:(void (^)(id data, NSError *error))block{
197+
NSString *path;
198+
NSDictionary *params = @{@"email": email,
199+
@"j_captcha": captcha};
200+
switch (type) {
201+
case PurposeToPasswordActivate:
202+
path = @"api/activate";
203+
break;
204+
case PurposeToPasswordReset:
205+
path = @"api/resetPassword";
206+
break;
207+
default:
208+
path = nil;
209+
break;
210+
}
211+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Get andBlock:^(id data, NSError *error) {
212+
if (data) {
213+
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"发激活or重置密码邮件"];
154214
}
215+
block(data, nil);
155216
}];
156217
}
157218
#pragma mark Project

Coding_iOS/Views/Cell/Input_OnlyText_Cell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
@property (nonatomic,copy) void(^editDidEndBlock)(NSString*);
2626

2727
- (void)setPlaceholder:(NSString *)phStr value:(NSString *)valueStr;
28-
28+
+ (NSString *)randomCellIdentifierOfPhoneCodeType;
2929
@end

Coding_iOS/Views/Cell/Input_OnlyText_Cell.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ @interface Input_OnlyText_Cell ()
2121
@end
2222

2323
@implementation Input_OnlyText_Cell
24+
+ (NSString *)randomCellIdentifierOfPhoneCodeType{
25+
return [NSString stringWithFormat:@"%@_%ld", kCellIdentifier_Input_OnlyText_Cell_PhoneCode, random()];
26+
}
2427

2528
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
2629
{
@@ -64,8 +67,8 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
6467
make.center.equalTo(self.captchaView);
6568
}];
6669
}
67-
}else if ([reuseIdentifier isEqualToString:kCellIdentifier_Input_OnlyText_Cell_PhoneCode]){
68-
if (_verify_codeBtn) {
70+
}else if ([reuseIdentifier rangeOfString:kCellIdentifier_Input_OnlyText_Cell_PhoneCode].location != NSNotFound){
71+
if (!_verify_codeBtn) {
6972
_verify_codeBtn = [[PhoneCodeButton alloc] initWithFrame:CGRectMake(kScreen_Width - 80 - kLoginPaddingLeftWidth, (44-25)/2, 80, 25)];
7073
[self.contentView addSubview:_verify_codeBtn];
7174
}
@@ -133,7 +136,7 @@ - (void)layoutSubviews {
133136
}else if ([self.reuseIdentifier isEqualToString:kCellIdentifier_Input_OnlyText_Cell_Captcha]){
134137
rightElement = _captchaView;
135138
[self refreshCaptchaImage];
136-
}else if ([self.reuseIdentifier isEqualToString:kCellIdentifier_Input_OnlyText_Cell_PhoneCode]){
139+
}else if ([self.reuseIdentifier rangeOfString:kCellIdentifier_Input_OnlyText_Cell_PhoneCode].location != NSNotFound){
137140
rightElement = _verify_codeBtn;
138141
}
139142

@@ -143,7 +146,8 @@ - (void)layoutSubviews {
143146
}];
144147

145148
[_textField mas_updateConstraints:^(MASConstraintMaker *make) {
146-
CGFloat offset = self.isForLoginVC? (CGRectGetMinX(self.clearBtn.frame) - kScreen_Width) : rightElement? (CGRectGetMinX(rightElement.frame) - kScreen_Width - 10): -kLoginPaddingLeftWidth;
149+
CGFloat offset = rightElement? (CGRectGetMinX(rightElement.frame) - kScreen_Width - 10): -kLoginPaddingLeftWidth;
150+
offset -= self.isForLoginVC? 30: 0;
147151
make.right.equalTo(self.contentView).offset(offset);
148152
}];
149153
}

0 commit comments

Comments
 (0)