GSignController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //
  2. // GSignController.m
  3. // aiim
  4. //
  5. // Created by gan on 2025/2/28.
  6. //
  7. #import "GSignController.h"
  8. #import "config.h"
  9. #import "UserNetApi.h"
  10. @interface GSignController ()
  11. @property (weak, nonatomic) IBOutlet UITextField *inputZH;
  12. @property (weak, nonatomic) IBOutlet UITextField *inputMMA;
  13. @property (weak, nonatomic) IBOutlet UITextField *inputMMB;
  14. @property (weak, nonatomic) IBOutlet UITextField *inputYX;
  15. @property (weak, nonatomic) IBOutlet UITextField *inputYZM;
  16. @property (weak, nonatomic) IBOutlet UIButton *getyanzmBt;
  17. @property (weak, nonatomic) IBOutlet UILabel *noteLb;
  18. @property (weak, nonatomic) IBOutlet UIButton *zhuceBt;
  19. @property (nonatomic) NSInteger count;
  20. @property (strong, nonatomic) NSTimer *heatBeat;
  21. @property (strong, nonatomic) NSString *youxiang;
  22. @end
  23. @implementation GSignController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. [self.navigationController setNavigationBarHidden:YES animated:NO];
  28. // 创建一个点击手势
  29. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  30. // 将手势添加到主视图上
  31. [self.view addGestureRecognizer:tap];
  32. // 注册键盘显示通知
  33. [[NSNotificationCenter defaultCenter] addObserver:self
  34. selector:@selector(keyboardWillShow:)
  35. name:UIKeyboardWillShowNotification object:nil];
  36. // 注册键盘隐藏通知
  37. [[NSNotificationCenter defaultCenter] addObserver:self
  38. selector:@selector(keyboardWillHide:)
  39. name:UIKeyboardWillHideNotification object:nil];
  40. [self initSubView];
  41. }
  42. -(void)dismissKeyboard{
  43. NSLog(@"dismissKeyboard");
  44. [self.view endEditing:YES];
  45. }
  46. -(void)initSubView{
  47. _inputZH.borderStyle=UITextBorderStyleNone;
  48. _inputZH.layer.borderWidth = 1.0f;
  49. _inputZH.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  50. _inputZH.layer.cornerRadius = 8.0f; // 可选,设置圆角
  51. _inputZH.backgroundColor = [UIColor clearColor];
  52. _inputZH.textColor=[UIColor whiteColor];
  53. NSString *note = NSLocalizedString(@"Sign-usernme-note", @"");
  54. NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  55. UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  56. _inputZH.leftView = paddingView;
  57. _inputZH.leftViewMode = UITextFieldViewModeAlways;
  58. _inputZH.attributedPlaceholder = placeholder;
  59. _inputMMA.borderStyle=UITextBorderStyleNone;
  60. _inputMMA.layer.borderWidth = 1.0f;
  61. _inputMMA.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  62. _inputMMA.layer.cornerRadius = 8.0f; // 可选,设置圆角
  63. _inputMMA.backgroundColor = [UIColor clearColor];
  64. _inputMMA.textColor=[UIColor whiteColor];
  65. note = NSLocalizedString(@"Sign-passw-note", @"");
  66. NSMutableAttributedString *placeholder2 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  67. UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  68. _inputMMA.leftView = paddingView2;
  69. _inputMMA.leftViewMode = UITextFieldViewModeAlways;
  70. _inputMMA.attributedPlaceholder = placeholder2;
  71. _inputMMB.borderStyle=UITextBorderStyleNone;
  72. _inputMMB.layer.borderWidth = 1.0f;
  73. _inputMMB.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  74. _inputMMB.layer.cornerRadius = 8.0f; // 可选,设置圆角
  75. _inputMMB.backgroundColor = [UIColor clearColor];
  76. _inputMMB.textColor=[UIColor whiteColor];
  77. note = NSLocalizedString(@"Sign-passw-note", @"");
  78. NSMutableAttributedString *placeholder3 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  79. UIView *paddingView3 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  80. _inputMMB.leftView = paddingView3;
  81. _inputMMB.leftViewMode = UITextFieldViewModeAlways;
  82. _inputMMB.attributedPlaceholder = placeholder3;
  83. _inputYX.borderStyle=UITextBorderStyleNone;
  84. _inputYX.layer.borderWidth = 1.0f;
  85. _inputYX.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  86. _inputYX.layer.cornerRadius = 8.0f; // 可选,设置圆角
  87. _inputYX.backgroundColor = [UIColor clearColor];
  88. _inputYX.textColor=[UIColor whiteColor];
  89. note = NSLocalizedString(@"Sign-qingshuryx", @"");
  90. NSMutableAttributedString *placeholder4 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  91. UIView *paddingView4 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  92. _inputYX.leftView = paddingView4;
  93. _inputYX.leftViewMode = UITextFieldViewModeAlways;
  94. _inputYX.attributedPlaceholder = placeholder4;
  95. _inputYZM.borderStyle=UITextBorderStyleNone;
  96. _inputYZM.layer.borderWidth = 1.0f;
  97. _inputYZM.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  98. _inputYZM.layer.cornerRadius = 8.0f; // 可选,设置圆角
  99. _inputYZM.backgroundColor = [UIColor clearColor];
  100. _inputYZM.textColor=[UIColor whiteColor];
  101. note = NSLocalizedString(@"Sign-qingsryzm", @"");
  102. NSMutableAttributedString *placeholder5 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  103. UIView *paddingView5 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  104. _inputYZM.leftView = paddingView5;
  105. _inputYZM.leftViewMode = UITextFieldViewModeAlways;
  106. _inputYZM.attributedPlaceholder = placeholder5;
  107. [_getyanzmBt setTitle:NSLocalizedString(@"Sign-huoquyzm", @"获取验证码") forState:UIControlStateNormal];
  108. _getyanzmBt.titleLabel.font = [UIFont systemFontOfSize: 15.0];
  109. [_getyanzmBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  110. [_getyanzmBt setBackgroundColor:globalColor(GCTypeGreen)];
  111. _getyanzmBt.layer.cornerRadius = 16;
  112. _getyanzmBt.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  113. _noteLb.numberOfLines=3;
  114. _noteLb.font = [UIFont systemFontOfSize:14.0f];
  115. _noteLb.textColor = globalColor(GCTypeDark3);
  116. _noteLb.text =NSLocalizedString(@"Sign-yanzhengmts", @"");
  117. [_zhuceBt setTitle:NSLocalizedString(@"Sign-zhuce", @"注册") forState:UIControlStateNormal];
  118. _zhuceBt.titleLabel.font = [UIFont systemFontOfSize: 19.0];
  119. [_zhuceBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  120. [_zhuceBt setBackgroundColor:globalColor(GCTypeGreen)];
  121. _zhuceBt.layer.cornerRadius = 27;
  122. _zhuceBt.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  123. _count = 0;
  124. [self startHeartbeat];
  125. }
  126. -(void)dealloc{
  127. [self destoryHeartbeat];
  128. }
  129. - (void)keyboardWillShow:(NSNotification *)notification {
  130. CGFloat moveF = 0;
  131. if(_inputMMB.isFirstResponder){
  132. moveF = -100.0f;
  133. }
  134. if(_inputYX.isFirstResponder){
  135. moveF = -150.0f;
  136. }
  137. if(_inputYZM.isFirstResponder){
  138. moveF = -250.0f;
  139. }
  140. CGRect frame = self.view.frame;
  141. NSLog(@"frame.origin.y:%f",frame.origin.y);
  142. frame.origin.y=moveF;
  143. NSDictionary *userInfo = [notification userInfo];
  144. double duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  145. UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
  146. [UIView animateWithDuration:duration
  147. delay:0.0
  148. options:(curve << 16)
  149. animations:^{
  150. self.view.frame = frame;;
  151. } completion:nil];
  152. }
  153. - (void)keyboardWillHide:(NSNotification *)notification{
  154. CGRect frame = self.view.frame;
  155. frame.origin.y=0;
  156. self.view.frame = frame;
  157. }
  158. - (IBAction)gotoBack:(id)sender {
  159. [self dismissViewControllerAnimated:YES completion:nil];
  160. }
  161. - (IBAction)getyanzmAct:(id)sender {
  162. if(_count==0){
  163. _youxiang =_inputYX.text;
  164. NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}|[\\p{L}0-9._%+-]+@[\\p{L}0-9.-]+\\.[\\p{L}]{2,}";
  165. //NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}";
  166. NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
  167. BOOL isValid = [emailTest evaluateWithObject:_youxiang];
  168. if (isValid) {
  169. _count = 60;
  170. [self sendYanzhengma];
  171. } else {
  172. NSLog(@"Email is invalid");
  173. }
  174. }
  175. }
  176. - (IBAction)zbuceAct:(id)sender {
  177. if([_inputYX.text isEqualToString:_youxiang]){
  178. if([_inputMMA.text isEqualToString:_inputMMB.text]){
  179. if(_inputZH.text.length>3&&_inputMMA.text.length>3&&_inputYZM.text.length>3){
  180. NSString *emailRegex = @"^[a-zA-Z0-9]+$";
  181. NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
  182. BOOL isValid = [emailTest evaluateWithObject:_inputZH.text];
  183. if(isValid){
  184. [self updateSign];
  185. }
  186. else{
  187. [MBProgressHUD showWithText:@"帳號只能包含數位字母"];
  188. }
  189. }
  190. else{//所有项目为必填,且不小于4个字符
  191. }
  192. }
  193. else{//密码输入不一致
  194. }
  195. }
  196. else{//邮箱不是获取验证码的邮箱
  197. }
  198. }
  199. //定时服务
  200. - (void)startHeartbeat {
  201. self.heatBeat = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(heartbeatAction) userInfo:nil repeats:YES];
  202. [self.heatBeat setFireDate:[NSDate distantPast]];
  203. [[NSRunLoop currentRunLoop] addTimer:_heatBeat forMode:NSRunLoopCommonModes];
  204. }
  205. //销毁定时
  206. - (void)destoryHeartbeat{
  207. [self.heatBeat invalidate];
  208. self.heatBeat = nil;
  209. }
  210. -(void)heartbeatAction{
  211. if(_count>0){
  212. NSString *note = [NSString stringWithFormat:@"%@(%ld)",NSLocalizedString(@"Sign-wangjimm", @"验证码"),(long)_count];
  213. [_getyanzmBt setTitle:note forState:UIControlStateNormal];
  214. _count=_count-1;
  215. }
  216. else{
  217. [_getyanzmBt setTitle:NSLocalizedString(@"Sign-huoquyzm", @"获取验证码") forState:UIControlStateNormal];
  218. }
  219. }
  220. #pragma mark network
  221. -(void)sendYanzhengma{
  222. NSLog(@"sendYanzhengma");
  223. [UserNetApi getEmailcode:_inputYX.text succ:^(int code, NSDictionary * res) {
  224. NSLog(@"res:%@",res);
  225. } fail:^(NSError * _Nonnull error) {
  226. NSLog(@"errer");
  227. }];
  228. }
  229. -(void)updateSign{
  230. NSDictionary *dic=@{
  231. @"host":@"",
  232. @"username":_inputZH.text,
  233. @"phonenumber":@"",
  234. @"email":_inputYX.text,
  235. @"password":_inputMMA.text,
  236. @"confirmPassword":_inputMMB.text,
  237. @"code":_inputYZM.text,
  238. @"uuid":@""
  239. };
  240. [UserNetApi sign:dic succ:^(int code, NSDictionary * res) {
  241. NSLog(@"res:%@",res);
  242. NSString *cd = res[@"code"];
  243. if(cd.intValue ==200){
  244. [self dismissViewControllerAnimated:YES completion:nil];
  245. }
  246. else{
  247. NSLog(@"注册账号失败!");
  248. }
  249. } fail:^(NSError * _Nonnull error) {
  250. NSLog(@"errer");
  251. }];
  252. }
  253. @end