IOS - 注册页面
来源:互联网 发布:改本地host变更域名 编辑:程序博客网 时间:2024/05/22 00:36
注册页面
手机号+密码+服务条款 -> 注册
新用户: 发送验证码+跳转
老用户: 提示\登录
代码
//// 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
效果
1 0
- IOS - 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- 注册页面
- iOS 注册或登录页面(UILable,UITextField,UIButton)
- iOS日常需求:注册页面的倒计时按钮
- iOS中QQ登录界面的制作,登录页面和注册页面的切换
- JS实现HTML地图定位
- 没参加的2015百度之星——数矩形
- hdoj1021Fibonacci Again
- 多渠道批量打包
- 237 Delete Node in a Linked List
- IOS - 注册页面
- 设立尾指针的单循环链表的表示和实现
- C++容器&数据结构
- OC_NSString
- 数据库之 truncate 、delete 、drop之区别
- 数据分析浅谈
- 项目名中&的问题
- iOS OC05_NSString总结
- ViewPager相关笔记