IOS - 注册页面
2015-07-20 19:13
543 查看
注册页面
手机号+密码+服务条款 -> 注册
新用户: 发送验证码+跳转
老用户: 提示\登录
代码
效果
手机号+密码+服务条款 -> 注册
新用户: 发送验证码+跳转
老用户: 提示\登录
代码
// // UserRegisterViewController.h // SymptomChecker // // Created by Wang on 2015-7-20. // #import "UserAccountBaseViewController.h" @interface UserRegisterViewController : UserAccountBaseViewController @end
// // UserRegisterViewController.m // SymptomChecker // // Created by C.L.Wang on 2015-7-20. // #import "UserRegisterViewController.h" // 注册页面 #import "UserLoginViewController.h" // 登录页面 #import "ActivateUserViewController.h" // 短信验证 #import "ForgetPasswordViewController.h" // 忘记密码 #define kViewRadio viewWidth()/320 @interface UserRegisterViewController () <AutoLoginDelegate> @end @implementation UserRegisterViewController { AccountTextInputElement* _phoneNo; // 用户名 AccountTextInputElement* _password; // 密码 AccountRegisterLegalElement* _registerLegal; // 法律条款 NSString* _source; // 源-未使用 } - (id) initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query { self = [super initWithNavigatorURL:URL query:query]; if (self) { self.title = @"注册"; _source = query[@"source"]; } return self; } // 页面初始化 - (void)viewDidLoad { [super viewDidLoad]; self.title = @"注册"; CGRect logoRect = CGRectMake(12*kViewRadio, 20*kViewRadio, viewWidth()-24*kViewRadio, 100*kViewRadio); // Logo UIImageView* logoView = [CYResource loadImageView:@"mat_logo_login.png" andFrame:logoRect]; [logoView setContentMode:UIViewContentModeScaleAspectFit]; [self.CYScrollView addSubview: logoView]; // 组合框 UIView *formView = [self formAreaWithFormElements:[self getFormElements]]; [self.CYScrollView addSubview:formView]; CGRect submitRect = CGRectMake(16*kViewRadio, formView.bottom + 16*kViewRadio, viewWidth() - 32*kViewRadio, 44*kViewRadio); // 注册按钮 UIButton *submitButton = [[FilledColorButton alloc] initWithFrame:submitRect type:kFilledBtnGreen title:@"注册"]; [submitButton addTarget:self action:@selector(onSubmitButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.CYScrollView addSubview:submitButton]; // 法律条款勾选 _registerLegal = [AccountRegisterLegalElement elementWithID:0 andValue:YES]; [_registerLegal setValue:YES]; CGRect legalRect = CGRectMake(8*kViewRadio, submitButton.bottom+4*kViewRadio, viewWidth()-16*kViewRadio, 40*kViewRadio); AccountRegisterLegalView *legalView = [[AccountRegisterLegalView alloc] initWithFrame:legalRect]; [legalView updateWithItem:_registerLegal]; [self.CYScrollView addSubview:legalView]; } // 重载组合框 - (UIView *)formAreaWithFormElements:(NSArray *)formElements { // 设置UITableView self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.tableFooterView = nil; self.tableView.tableHeaderView = nil; self.tableView.backgroundView = nil; self.tableView.rowHeight = 50*kViewRadio; self.tableView.frame = CGRectMake(0,1,viewWidth(),formElements.count*50*kViewRadio); self.tableView.autoresizingMask = UIViewAutoresizingNone; self.tableView.bounces = NO; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; NITableViewModel* model = [[NITableViewModel alloc] initWithSectionedArray:formElements delegate:self.cellFactory]; self.tableViewModel = model; CGFloat inputAreaHeight = formElements.count*50*kViewRadio+ 1; CGRect inputRect = CGRectMake(16*kViewRadio, 140*kViewRadio, viewWidth()-32*kViewRadio, inputAreaHeight); // 输入框border UIView *inputArea = [[UIView alloc] initWithFrame:inputRect]; inputArea.clipsToBounds = YES; inputArea.layer.cornerRadius = 3; inputArea.layer.borderWidth = 0.5; inputArea.layer.borderColor = RGBCOLOR_HEX(0xb6b6b6).CGColor; [inputArea addSubview:self.tableView]; return inputArea; } // // 派生类定义自己的Form Elements // - (NSArray*) getFormElements { _phoneNo = [AccountTextInputElement textInputElementWithID:kFormElementTagIdUserName placeholderText:@"手机号" value:nil]; [_phoneNo setStyle:kUserCenterItemTop]; _password = [AccountTextInputElement passwordInputElementWithID:kFormElementTagIdUserPassword placeholderText:@"密码" value: nil]; [_password setStyle:kUserCenterItemMiddle]; [_password setDelegate:self]; return @[_phoneNo, _password]; } // 重写登录失败事件 - (void)didFailLoginChunyuServerWithError:(NSError *)error info:(NSDictionary *)info { // 防止登录错误, 验证码请求 if (info != nil && [info[@"type"] intValue] == 0) { [self showLoading:NO withText: nil]; return; } [self sendMatVCode]; // Mat发送验证码 [self showLoading:NO withText: nil]; } /** * 发送验证码 * * {"version":16,"token":"","msgType":"MSG_GET_SMS_VCODE_REQ","msgSeq":755, * "appType":4,"IMEI":"356199060018702","phoneNo":"15698755897"} */ - (void) sendMatVCode { User* currentUser = [User currentUser]; // 请求参数 NSMutableDictionary* paras = [[NSMutableDictionary alloc] init]; [paras setValue:currentUser.matVersion forKey:@"version"]; [paras setValue:(currentUser.matToken == nil) ? @"":currentUser.matToken forKey:@"token"]; [paras setValue:@"MSG_GET_SMS_VCODE_REQ" forKey:@"msgType"]; [paras setValue:[NSString stringWithFormat:@"%d",currentUser.matMsgSeq] forKey:@"msgSeq"]; [paras setValue:currentUser.matAppType forKey:@"appType"]; [paras setValue:currentUser.uniqueDeviceToken forKey:@"IMEI"]; [paras setValue:_phoneNo.value forKey:@"phoneNo"]; [paras setValue:@"P" forKey:@"regType"]; // 持久化 [currentUser setMatPhoneNo: _phoneNo.value]; [currentUser setMatPassword: _password.value]; [currentUser synchronize]; NSLog(@"发送验证码参数: %@", paras); [[ChunyuAPIClient sharedClient] postPath:@"http://agent.iotxmm.com/noauth/serviceManager" parameters:paras requestContentType:kCYHttpRequestContentTypeJSON success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"MSG_GET_SMS_VCODE_REQ + %@", responseObject); NSLog(@"description = %@", responseObject[@"description"]); // 注册成功过之后准备激活 [self showLoading: NO withText: nil]; if ([responseObject[@"errorCode"] intValue] == 0) { [self activateUserWithUsername:_phoneNo.value password:_password.value]; } else { [SVProgressHUD showErrorWithStatus:responseObject[@"description"]]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [self showLoading: NO withText: nil]; [Utility toastLoginError:error]; }]; } // 验证手机号 - (void)activateUserWithUsername:(NSString *)username password:(NSString *)password { ActivateUserViewController *controller = [[ActivateUserViewController alloc] initWithNavigatorURL: nil query: @{@"username": _phoneNo.value, @"password": _password.value}]; controller.dismissBlock = self.dismissBlock; [self.navigationController pushViewController:controller animated:YES]; } /** * 注册按钮监听 * * @param button 注册按钮 */ - (void) onSubmitButtonClicked: (UIButton*) button { // 首先判断数据是否有效 if ([self isFormValid]) { [self showLoading:YES withText:@"注册中..."]; [self registerOnMat]; // Mat注册请求 } } /** * Mat注册请求 * {"version":16,"token":"","msgType":"MSG_IS_PHONENO_REGISTERED_REQ", * "msgSeq":433,"appType":4,"IMEI":"356199060018702","phoneNo":"26578966987"} */ - (void) registerOnMat { User* currentUser = [User currentUser]; NSMutableDictionary* paras = [[NSMutableDictionary alloc] init]; [paras setValue:currentUser.matVersion forKey:@"version"]; [paras setValue:(currentUser.matToken == nil) ? @"":currentUser.matToken forKey:@"token"]; [paras setValue:@"MSG_IS_PHONENO_REGISTERED_REQ" forKey:@"msgType"]; [paras setValue:[NSString stringWithFormat:@"%d",currentUser.matMsgSeq] forKey:@"msgSeq"]; [paras setValue:currentUser.matAppType forKey:@"appType"]; [paras setValue:currentUser.uniqueDeviceToken forKey:@"IMEI"]; [paras setValue:_phoneNo.value forKey:@"phoneNo"]; NSLog(@"注册请求参数: %@", paras); [[ChunyuAPIClient sharedClient] postPath:[ChunyuAPIClient MAT_NOAUTH_HTTP_URL] parameters:paras requestContentType:kCYHttpRequestContentTypeJSON success:^(AFHTTPRequestOperation *operation, id responseObject) { [self showLoading:NO withText:nil]; NSLog(@"MSG_USER_LOGON_REQ + %@", responseObject); NSString* loginState = responseObject[@"description"]; NSLog(@"注册状态: %@", loginState); // 未注册, 直接注册 if ([responseObject[@"isRegistered"] intValue] == 0) { [self sendMatVCode]; // Mat发送验证码 return; } else { [SVProgressHUD showErrorWithStatus: @"手机号码已经被注册"]; } [[ThirdpartyLoginManager sharedInstance] loginToServerWithUsername:ENSURE_NOT_NULL(_phoneNo.value) password:ENSURE_NOT_NULL(_password.value) method:kSNSLoginMethodOther delegate:self type:0]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"responseObject + %@", error); }]; } // 注册信息是否符合 - (BOOL) isFormValid { [super viewWillAppear: NO]; // 这样修改是为了让UITextField能够becomeFirstResponder AccountTextInputCell* userNameCell = (AccountTextInputCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; AccountTextInputCell* userPasswordCell = (AccountTextInputCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]; UITextField* userNameTxt = userNameCell.textField; UITextField* userPasswordTxt = userPasswordCell.textField; [userNameTxt resignFirstResponder]; [userPasswordTxt resignFirstResponder]; // 手机号 if (![User isUsernameValid:_phoneNo.value]) { [SVProgressHUD showErrorWithStatus: @"手机号码应该是11位数字"]; [userNameTxt becomeFirstResponder]; return NO; } else { [userNameTxt resignFirstResponder]; } // 密码 if (![User isPasswordValid: _password.value]) { [SVProgressHUD showErrorWithStatus: @"密码应该为6~20位"]; [userPasswordTxt becomeFirstResponder]; return NO; } else { [userPasswordTxt resignFirstResponder]; } // 同意服务 if (!_registerLegal.value) { [SVProgressHUD showErrorWithStatus: @"您必须同意我们的服务条款才能继续注册"]; return NO; } return YES; } @end
效果
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- ios通过按钮点击异步加载图片
- ios中图像进行压缩方法汇总
- IOS检测指定路径的文件是否存在
- iOS、Mac OS X系统中编程实现汉字转拼音的方法(超级简单)