SignupViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. //
  2. // SignupViewController.m
  3. // RA TradeFiling
  4. //
  5. // Created by Rui Zhang on 1/19/21.
  6. //
  7. #import "SignupViewController.h"
  8. #import "const.h"
  9. #import "RAUtils.h"
  10. #import "RADataProvider.h"
  11. @interface SignupViewController ()
  12. @property(nonatomic ,strong) UITextField * firstResponderTextF;//记录将要编辑的输入框
  13. @property (assign) int y;
  14. @property (assign) int offset;
  15. @end
  16. @implementation SignupViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // [self.navigationController.navigationBar setTintColor:UIColor.blueColor]; // BarItem颜色
  20. // [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.lightTextColor}];
  21. [self.btn_agree setImage:[UIImage imageNamed:@"checkbox_unchecked_30.png"] forState:UIControlStateNormal];
  22. [self.btn_agree setImage:[UIImage imageNamed:@"checkbox_30.png"] forState:UIControlStateSelected];
  23. self.btn_signup.enabled=false;
  24. self.tf_email.delegate=self;
  25. self.tf_pass0.delegate=self;
  26. self.tf_pass1.delegate=self;
  27. _offset=0;
  28. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  29. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  30. // Do any additional setup after loading the view.
  31. }
  32. - (void)viewWillAppear:(BOOL)animated
  33. {
  34. [super viewWillAppear:animated];
  35. self.y=self.view.frame.origin.y;
  36. // [IQKeyboardManager sharedManager].enable = NO;
  37. // [self.navigationController.navigationBar setHidden:false];
  38. }
  39. - (void)viewWillDisappear:(BOOL)animated {
  40. [super viewWillDisappear:animated];
  41. // [IQKeyboardManager sharedManager].enable = YES;
  42. }
  43. - (IBAction)onAgreeClick:(id)sender {
  44. self.btn_agree.selected = !self.btn_agree.selected;
  45. if(self.btn_agree.selected)
  46. {
  47. self.btn_signup.enabled=true;
  48. }
  49. else
  50. {
  51. self.btn_signup.enabled=false;
  52. }
  53. }
  54. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  55. if ([self.firstResponderTextF isFirstResponder])
  56. [self.firstResponderTextF resignFirstResponder];
  57. [[self view] endEditing:YES];
  58. }
  59. - (IBAction)onSignUpClick:(id)sender {
  60. // NSError *error = nil;
  61. // NSDataDetector *detector =
  62. // [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
  63. NSString *email = self.tf_email.text.lowercaseString;
  64. NSString * password = self.tf_pass0.text;
  65. NSString * password1 = self.tf_pass1.text;
  66. if(email.length<1||password.length<1)
  67. {
  68. // [RAUtils message_alert:@"EMAIL or PASSWORD can't be empty." title:@"ERROR" controller:self];
  69. [RAUtils message_box:@"ERROR" message:@"EMAIL or PASSWORD can't be empty." completion:nil];
  70. return;
  71. }
  72. bool pass_match = false;
  73. if([password isEqualToString:password1])
  74. {
  75. pass_match=true;
  76. }
  77. if(!pass_match)
  78. {
  79. [RAUtils message_box:@"ERROR" message:@"PASSWORD does not match." completion:nil];
  80. // [RAUtils message_alert:@"PASSWORD does not match." title:@"ERROR" controller:self];
  81. return;
  82. }
  83. bool email_valid=[RAUtils validateEmail:email];
  84. if(!email_valid)
  85. {
  86. // [RAUtils message_alert:@"EMAIL is invalid." title:@"ERROR" controller:self];
  87. [RAUtils message_box:@"ERROR" message:@"EMAIL is invalid." completion:nil];
  88. return;
  89. }
  90. bool pass_valid =[RAUtils checkPassword:password];
  91. if(!pass_valid)
  92. {
  93. [RAUtils message_box:@"ERROR" message:@"PASSWORD is invalid.\r\nPassword must 8-16 characters, letters, numbers and uppercase letters are allowed." completion:nil];
  94. // [RAUtils message_alert:@"PASSWORD is invalid.\r\nPassword must 8-16 characters, letters, numbers and uppercase letters are allowed." title:@"ERROR" controller:self];
  95. return;
  96. }
  97. [RADataProvider Signup:email password:password completionHandler:^(NSMutableDictionary *result) {
  98. int ret=[result[@"result"] intValue];
  99. // self.mum.hidden=true;
  100. // self.loginButton.enabled = true;
  101. if (ret==RESULT_TRUE)
  102. {
  103. [RAUtils message_box:@"Signup" message:@"Successful" completion:^{
  104. [self.navigationController popToRootViewControllerAnimated:YES];
  105. }];
  106. // [RAUtils message_alert:@"Successful" title:@"Signup" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
  107. // [self.navigationController popToRootViewControllerAnimated:YES];;
  108. // } completion:^{
  109. //
  110. //
  111. //
  112. // }];
  113. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  114. // [defaults removeObjectForKey:@"user"];
  115. // [defaults removeObjectForKey:@"password"];
  116. // // if(self.checkSavePassword.selected)
  117. // {
  118. //
  119. //
  120. // [defaults setValue:[AESCrypt encrypt:self.editUser.text.lowercaseString password:@"usai"] forKey:@"user"];
  121. // [defaults setValue:[AESCrypt encrypt:self.editPassword.text password:@"usai"] forKey:@"password"];
  122. // [defaults setBool:TRUE forKey:@"autologin"];
  123. // }
  124. //
  125. //
  126. // [defaults synchronize];
  127. // [RASingleton.sharedInstance login:self.editUser.text.lowercaseString password:self.editPassword.text firstName:result[@"nick_name"] companyList:result[@"company"] functions:result[@"function_panel"]];
  128. // RASingleton.sharedInstance.fields=result[@"fields"];
  129. //
  130. //// RASingleton.sharedInstance.user=self.editUser.text.lowercaseString;
  131. //// RASingleton.sharedInstance.password=self.editPassword.text;
  132. // [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN object:nil];
  133. //
  134. // if(!self.checkSavePassword.selected)
  135. // {
  136. // self.editUser.text=@"";
  137. // self.editPassword.text=@"";
  138. // }
  139. //
  140. // if(self.loginSuccessful)
  141. // self.loginSuccessful();
  142. // [self dismissViewControllerAnimated:true completion:^{
  143. // ;
  144. // }];
  145. // [self performSegueWithIdentifier:@"LOGIN" sender:self];
  146. }
  147. else
  148. {
  149. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
  150. // int a = RESULT_NET_NOTAVAILABLE;
  151. NSString* message = nil;
  152. switch (ret) {
  153. case RESULT_NET_NOTAVAILABLE:
  154. message = NSLocalizedString(@"net_not_available", nil);
  155. break;
  156. case RESULT_NET_ERROR:
  157. message = NSLocalizedString(@"net_error", nil);
  158. break;
  159. case RESULT_FALSE:
  160. message = NSLocalizedString(@"auth_error", nil);
  161. break;
  162. case RESULT_VER_LOW:
  163. message = NSLocalizedString(@"ver_low", nil);
  164. break;
  165. case RESULT_FAILED_WITH_MESSAGE:
  166. message = result[@"err_msg"];
  167. break;
  168. default:
  169. message=[NSString stringWithFormat:@"Failed to login code %d",ret];
  170. break;
  171. }
  172. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  173. UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  174. }];
  175. [alertVC addAction:action];
  176. [self presentViewController:alertVC animated:YES completion:nil];
  177. }
  178. }];
  179. }
  180. - (void)dealloc{
  181. //移除键盘通知监听者
  182. [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  183. [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  184. }
  185. #pragma maek UITextFieldDelegate
  186. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  187. self.firstResponderTextF = textField;//当将要开始编辑的时候,获取当前的textField
  188. return YES;
  189. }
  190. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  191. [textField resignFirstResponder];
  192. return YES;
  193. }
  194. #pragma mark : UIKeyboardWillShowNotification/UIKeyboardWillHideNotification
  195. - (void)keyboardWillShow:(NSNotification *)notification{
  196. self.navigationController.navigationBar.translucent=NO;
  197. CGRect rect = [self.firstResponderTextF.superview convertRect:self.firstResponderTextF.frame toView:self.view];//获取相对于self.view的位置
  198. NSDictionary *userInfo = [notification userInfo];
  199. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];//获取弹出键盘的fame的value值
  200. CGRect keyboardRect = [aValue CGRectValue];
  201. keyboardRect = [self.view convertRect:keyboardRect fromView:self.view.window];//获取键盘相对于self.view的frame ,传window和传nil是一样的
  202. CGFloat keyboardTop = keyboardRect.origin.y;
  203. // NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘弹出动画时间值
  204. // NSTimeInterval animationDuration = [animationDurationValue doubleValue];
  205. if (keyboardTop < CGRectGetMaxY(rect)) {//如果键盘盖住了输入框
  206. CGFloat gap = keyboardTop - CGRectGetMaxY(rect) - 10;//计算需要网上移动的偏移量(输入框底部离键盘顶部为10的间距)
  207. _offset = _offset+gap;
  208. // __weak typeof(self)weakSelf = self;
  209. // [UIView animateWithDuration:animationDuration animations:^{
  210. //
  211. // }];
  212. self.view.frame = CGRectMake(self.view.frame.origin.x, _offset, self.view.frame.size.width, self.view.frame.size.height);
  213. }
  214. }
  215. - (void)keyboardWillHide:(NSNotification *)notification{
  216. // NSDictionary *userInfo = [notification userInfo];
  217. // NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘隐藏动画时间值
  218. // NSTimeInterval animationDuration = [animationDurationValue doubleValue];
  219. if (self.view.frame.origin.y < 0) {//如果有偏移,当影藏键盘的时候就复原
  220. _offset = 0;
  221. self.view.frame = CGRectMake(self.view.frame.origin.x, self.y, self.view.frame.size.width, self.view.frame.size.height);
  222. // __weak typeof(self)weakSelf = self;
  223. // [UIView animateWithDuration:animationDuration animations:^{
  224. // self.navigationController.navigationBar.translucent=NO;
  225. //
  226. //
  227. // }];
  228. }
  229. }
  230. //#pragma mark - UITextViewDelegate
  231. //- (void)textViewDidEndEditing:(UITextView *)textView
  232. //{
  233. // if(textView.text.length < 1){
  234. // textView.text = @"ADDRESS";
  235. // textView.textColor = PlaceHolderColor;
  236. // }
  237. //}
  238. //- (void)textViewDidBeginEditing:(UITextView *)textView
  239. //{
  240. // if([textView.text isEqualToString:@"ADDRESS"]){
  241. // textView.text=@"";
  242. // textView.textColor=[UIColor blackColor];
  243. // }
  244. //}
  245. /*
  246. #pragma mark - Navigation
  247. // In a storyboard-based application, you will often want to do a little preparation before navigation
  248. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  249. // Get the new view controller using [segue destinationViewController].
  250. // Pass the selected object to the new view controller.
  251. }
  252. */
  253. @end