Skip to content

Commit

Permalink
master:合并dev,完成手机验证码的功能,同时同一个手机号不能进行重复注册,一个手机号表示一个用户名
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyufeng1991 committed Nov 17, 2015
2 parents 1cf2503 + 43c5bac commit 833f297
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Oncenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@
71A793741BF5B5F000410FFC /* LoginViewController.m */,
71A793761BF5CDCA00410FFC /* RegisterViewController.h */,
71A793771BF5CDCA00410FFC /* RegisterViewController.m */,
717902EF1BF48FC100428756 /* MainViewController.m */,
718FF3A11BF623B7009A3F6D /* AddNoteViewController.h */,
718FF3A21BF623B7009A3F6D /* AddNoteViewController.m */,
717902EE1BF48FC100428756 /* MainViewController.h */,
717902EF1BF48FC100428756 /* MainViewController.m */,
71BEC27F1BF753080003F173 /* NoteDetailViewController.h */,
71BEC2801BF753080003F173 /* NoteDetailViewController.m */,
71BEC2821BF76C6F0003F173 /* AllNotesViewController.h */,
Expand Down
1 change: 1 addition & 0 deletions Oncenote/BmobOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@implementation BmobOperation

#pragma mark - 往数据库中插入一条笔记
//插入一条笔记到Note表,包括,userId(用户ID),username(用户名),noteTitle(笔记标题),noteText(笔记内容);4个字段;
+ (void)addNoteToNoteTable:(NSString*)tableName userId:(NSString*)userId username:(NSString*)username noteTitle:(NSString*)noteTitle noteText:(NSString*)noteText todo:(void(^)(BOOL isSuccessful, NSError *error)) todo{

Expand Down
75 changes: 59 additions & 16 deletions Oncenote/RegisterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <BmobSDK/Bmob.h>
#import "AllUtils.h"
#import "LoginViewController.h"
#import "Constant.h"
//15626266152
//18285115452

Expand All @@ -21,17 +22,20 @@

@interface RegisterViewController ()

//这里的用户名也就是手机号;
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *validateCodeTextField;


@end

@implementation RegisterViewController

- (void)viewDidLoad {
[super viewDidLoad];


}

#pragma mark - 所有按钮的点击操作;
Expand All @@ -57,7 +61,7 @@ - (IBAction)createAccountButtonPressed:(id)sender {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
loginViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self presentViewController:loginViewController animated:true completion:nil];

} cancelButton:@"" cancelButtonAction:nil contextViewController:self];

}else{
Expand All @@ -70,7 +74,7 @@ - (IBAction)createAccountButtonPressed:(id)sender {
}//if();

else{
[AllUtils showPromptDialog:@"提示" andMessage:@"验证失败,请输入正确的验证码" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
[AllUtils showPromptDialog:@"提示" andMessage:@"注册失败,请输入正确的手机号和验证码" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}
}];

Expand All @@ -84,24 +88,51 @@ - (IBAction)getValidateCodeButtonPressed:(id)sender {
//如果该手机号已经存在,不能获取验证码。
//注意:还应该加一个昵称;

[self isRepeatUsername:USER_TABLE username:self.usernameTextField.text limitCount:50];




[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.usernameTextField.text
zone:@"86"
customIdentifier:nil
result:^(NSError *error){
if (!error){
[AllUtils showPromptDialog:@"提示" andMessage:@"验证码发送成功,请稍候!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}
else{
[AllUtils showPromptDialog:@"提示" andMessage:@"验证码发送失败,请填写正确的手机号!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}
}];
}

#pragma mark - 查询该手机号是否已经注册
- (void)isRepeatUsername:(NSString*)tableName username:(NSString*)username limitCount:(int)limitCount{

__block BOOL isRepeatUsername = false;

BmobQuery *queryUser = [BmobQuery queryWithClassName:tableName];
queryUser.limit = limitCount;
[queryUser findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {

if (!error) {
for (BmobObject *obj in array) {

if ([(NSString*)[obj objectForKey:@"username"] isEqualToString:username]) {
//表示已经存在该用户名;
isRepeatUsername = true;
break;
}
}
} else {
[AllUtils showPromptDialog:@"提示" andMessage:@"网络异常,请稍候重试!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}

if (isRepeatUsername) {
[AllUtils showPromptDialog:@"提示" andMessage:@"该账户已经存在,请直接登录!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}else{
//该手机号没有注册,可以获取验证码;
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.usernameTextField.text
zone:@"86"
customIdentifier:nil
result:^(NSError *error){
if (!error){
[AllUtils showPromptDialog:@"提示" andMessage:@"验证码发送成功,请稍候!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}
else{
[AllUtils showPromptDialog:@"提示" andMessage:@"手机号格式错误,请输入正确的手机号!" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];
}
}];
}
}];

}


#pragma mark - 触摸屏幕隐藏键盘
Expand All @@ -114,3 +145,15 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}

@end












0 comments on commit 833f297

Please sign in to comment.