悟空记账

JZPhoneLoginViewController.m 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //
  2. // JZPhoneLoginViewController.m
  3. // JIZHANG
  4. //
  5. // Created by jikaipeng on 2017/10/26.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "JZPhoneLoginViewController.h"
  9. #import "JZSettingViewController.h"
  10. #import "AppDelegate.h"
  11. #import "JZTabBarViewController.h"
  12. #import "JZForgetPwdViewController.h"
  13. #import "JZRegisterViewController.h"
  14. #import <WXApi.h>
  15. #import <UMSocialCore/UMSocialCore.h>
  16. #import "JZUtil.h"
  17. @interface JZPhoneLoginViewController ()
  18. //手机号
  19. @property (weak, nonatomic) IBOutlet UITextField *phoneField;
  20. //密码
  21. @property (weak, nonatomic) IBOutlet UITextField *pwdField;
  22. //登录按钮
  23. @property (weak, nonatomic) IBOutlet UIButton *loginBtn;
  24. //找回密码
  25. @property (weak, nonatomic) IBOutlet UIButton *forgetBtn;
  26. //微信登录
  27. @property (weak, nonatomic) IBOutlet UIButton *WXLogin;
  28. //注册按钮
  29. @property (weak, nonatomic) IBOutlet UIButton *registerBtn;
  30. //退出登录按钮
  31. @property (weak, nonatomic) IBOutlet UIButton *backBtn;
  32. @end
  33. @implementation JZPhoneLoginViewController
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. // Do any additional setup after loading the view from its nib.
  37. [self setupNavBar];
  38. [self initUI];
  39. }
  40. - (void)viewWillAppear:(BOOL)animated {
  41. [super viewWillAppear:animated];
  42. [MobClick beginLogPageView:@"loginPage"];
  43. }
  44. - (void)viewWillDisappear:(BOOL)animated {
  45. [super viewWillDisappear:animated];
  46. [MobClick endLogPageView:@"loginPage"];
  47. }
  48. #pragma mark - event handle
  49. - (void)setupNavBar {
  50. [self addLeftBarButtonItemWithImageName:@"mine_back" title:@"返回" target:self selector:@selector(disMissAction)];
  51. }
  52. - (void) initUI{
  53. self.phoneField.clearButtonMode = UITextFieldViewModeWhileEditing;
  54. self.pwdField.clearButtonMode = UITextFieldViewModeWhileEditing;
  55. self.phoneField.keyboardType = UIKeyboardTypeNumberPad;
  56. [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
  57. self.loginBtn.layer.cornerRadius = 12;
  58. self.loginBtn.layer.masksToBounds = YES;
  59. self.WXLogin.layer.cornerRadius = 12;
  60. self.WXLogin.layer.masksToBounds = YES;
  61. self.loginBtn.backgroundColor = [UIColor baseColor];
  62. [self.WXLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  63. self.pwdField.secureTextEntry = YES;
  64. [self.loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
  65. self.WXLogin.backgroundColor = [UIColor baseColor];
  66. [self.forgetBtn addTarget:self action:@selector(forgetBtnAction) forControlEvents:UIControlEventTouchUpInside];
  67. [self.registerBtn addTarget:self action:@selector(registerAction) forControlEvents:UIControlEventTouchUpInside];
  68. [self.WXLogin addTarget:self action:@selector(WXLoginAction) forControlEvents:UIControlEventTouchUpInside];
  69. // if ([WXApi isWXAppInstalled]) {
  70. // self.WXLogin.hidden = NO;
  71. // } else{
  72. // self.WXLogin.hidden = YES;
  73. // }
  74. }
  75. - (void)loginAction{
  76. NSString *mobile = self.phoneField.text;
  77. NSString *password = self.pwdField.text;
  78. NSDictionary *params = @{@"mobile":mobile,@"password":password};
  79. NSString *URLString = [NSString stringWithFormat:@"%@/login",URL];
  80. [JZHttp post:URLString params:params success:^(id json) {
  81. NSString *token = json[@"token"];
  82. if (token) {
  83. [MobClick event:@"phoneLogin"];
  84. [[NSUserDefaults standardUserDefaults] setObject:mobile forKey:JZPHONE];
  85. [[NSUserDefaults standardUserDefaults] setObject:token forKey:JZTOKEN];
  86. [JZUtil saveTimeinterval];
  87. [[NSUserDefaults standardUserDefaults] setObject:@"PhoneLogin" forKey:JZLoginMode];
  88. [[NSUserDefaults standardUserDefaults] synchronize];
  89. [MBProgressHUD showSuccess:@"登录成功"];
  90. if (self.vcClassStr.length) {
  91. self.loginCompleteBlock();
  92. [self dismissViewControllerAnimated:YES completion:nil];
  93. } else {
  94. AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  95. appdelegate.window.rootViewController = nil;
  96. JZTabBarViewController *tabVC = [[JZTabBarViewController alloc]init];
  97. tabVC.selectedViewController = [tabVC.viewControllers objectAtIndex:3];
  98. appdelegate.window.rootViewController = tabVC;
  99. }
  100. }
  101. [self.view endEditing:YES];
  102. } failure:^(NSError *error) {
  103. [MBProgressHUD showError:@"登录失败,请重试"];
  104. }];
  105. }
  106. - (void)forgetBtnAction{
  107. CATransition *animation = [CATransition animation];
  108. [animation setDuration:0.3];
  109. [animation setType:kCATransitionMoveIn];
  110. [animation setSubtype:kCATransitionFromRight];
  111. [[[[UIApplication sharedApplication] keyWindow] layer] addAnimation:animation forKey:nil];
  112. JZForgetPwdViewController *forgetPwdVC = [[JZForgetPwdViewController alloc]init];
  113. [self presentViewController:forgetPwdVC animated:NO completion:nil];
  114. }
  115. - (void)registerAction{
  116. CATransition *animation = [CATransition animation];
  117. [animation setDuration:0.3];
  118. [animation setType:kCATransitionMoveIn];
  119. [animation setSubtype:kCATransitionFromRight];
  120. [[[[UIApplication sharedApplication] keyWindow] layer] addAnimation:animation forKey:nil];
  121. JZRegisterViewController *registVC = [[JZRegisterViewController alloc]init];
  122. [self presentViewController:registVC animated:NO completion:nil];
  123. }
  124. - (void)WXLoginAction{
  125. [[JZLoginManager shareInstance] loginWithPlatform:UMSocialPlatformType_WechatSession success:^(UMSocialUserInfoResponse *response) {
  126. if (response) {
  127. NSString *openid = response.openid;
  128. NSString *nickname = response.name;
  129. NSString *sex = response.unionGender;
  130. NSString *headimgurl = response.iconurl;
  131. NSString *unionid = response.unionId;
  132. if ([sex isEqualToString:@"男"]) {
  133. sex = @"1";
  134. } else{
  135. sex = @"2";
  136. }
  137. NSString *urlString = [NSString stringWithFormat:@"%@/weChatLogin",URL];
  138. NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:openid,@"openid",nickname,@"nickname",sex,@"sex",headimgurl,@"headimgurl",unionid,@"unionid",nil];
  139. [JZHttp post:urlString params:params success:^(id json) {
  140. if (json) {
  141. NSString *token = json[@"token"];
  142. if (token.length && nickname && sex && headimgurl) {
  143. [MobClick event:@"wxLogin"];
  144. [[NSUserDefaults standardUserDefaults] setObject:token forKey:JZTOKEN];
  145. [[NSUserDefaults standardUserDefaults] setObject:@"WXLogin" forKey:JZLoginMode];
  146. [[NSUserDefaults standardUserDefaults] setObject:nickname forKey:JZWeixinNickName];
  147. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:JZWeixinSex];
  148. [[NSUserDefaults standardUserDefaults] setObject:headimgurl forKey:JZWeixinImage];
  149. [JZUtil saveTimeinterval];
  150. [[NSUserDefaults standardUserDefaults] synchronize];
  151. if (![[NSUserDefaults standardUserDefaults] valueForKey:JZFirstLogin]) {
  152. [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:JZWxBangPhone];
  153. [[NSUserDefaults standardUserDefaults] synchronize];
  154. }
  155. //保存时间戳
  156. [MBProgressHUD showSuccess:@"登录成功"];
  157. AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  158. JZTabBarViewController *tabVC = [[JZTabBarViewController alloc]init];
  159. tabVC.selectedViewController = [tabVC.viewControllers objectAtIndex:3];
  160. appdelegate.window.rootViewController = tabVC;
  161. }
  162. }
  163. } failure:^(NSError *error) {
  164. }];
  165. }
  166. } fail:^(NSError *error) {
  167. }];
  168. }
  169. #pragma mark - 设置弹出提示语
  170. - (void)setupAlertController {
  171. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请先安装微信客户端" preferredStyle:UIAlertControllerStyleAlert];
  172. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  173. [alert addAction:actionConfirm];
  174. [self presentViewController:alert animated:YES completion:nil];
  175. }
  176. - (void)disMissAction{
  177. if (self.vcClassStr.length) {
  178. self.loginCancelBlock();
  179. if ([self.delegate respondsToSelector:@selector(loginCancelAction)]) {
  180. [self.delegate loginCancelAction];
  181. }
  182. }
  183. [self dismissViewControllerAnimated:YES completion:nil];
  184. }
  185. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  186. [self.view endEditing:YES];
  187. }
  188. - (void)didReceiveMemoryWarning {
  189. [super didReceiveMemoryWarning];
  190. // Dispose of any resources that can be recreated.
  191. }
  192. -(void)aN1T3p2v:(UIImage*) aN1T3p2v a9dV3C:(UIBarButtonItem*) a9dV3C aAtVcde5o:(UISearchBar*) aAtVcde5o akvbhW7tPQ:(UIViewController*) akvbhW7tPQ aNt9QVsD:(UIControlEvents*) aNt9QVsD aqp4L:(UIBarButtonItem*) aqp4L aqXKkDov4RV:(UIControlEvents*) aqXKkDov4RV aSIaZk:(UIControl*) aSIaZk a14Z3rO:(UIKeyCommand*) a14Z3rO aL07xoEu:(UIImageView*) aL07xoEu {
  193. NSLog(@"iXsmNthTyM5WeClV8EqczaQ1AdovYKg6");
  194. NSLog(@"2KSUbAXvIs5H94eqrhzlCRTY7pDkQnuwWjJZVNL");
  195. NSLog(@"Z4sxzC0GqyPwBViUH5celJ21OLSAF3Wbpkonr");
  196. NSLog(@"b57uWo0vPV14ATgFds9Jp2lek");
  197. NSLog(@"zSnpPB7M4lXWqGLi0xZhQ5k3ftd9EJyabUgowvTj");
  198. NSLog(@"6i7T05nWQVJNR3fB4tx8Z");
  199. NSLog(@"rYGFMLEiom6HyQ0jX4s");
  200. NSLog(@"TFiVmpE0ecZSdBRbKXyrLJh8QjM9WOIk4uHtnG");
  201. NSLog(@"YT50uSO4xEadBp62g3");
  202. NSLog(@"N9U0du6yM1qZ3PYSmwIifsztlXjHBrnLxKGFp");
  203. NSLog(@"mQ42oi6qTIdNCM5x1PbfgAD0kZwHl");
  204. NSLog(@"NauW4qFGojlA9ShMfpy5sB");
  205. NSLog(@"2czsNRaEMurPfn");
  206. NSLog(@"5IWGehqx0BkzsuK9cmnJ1QD4Nb");
  207. NSLog(@"3DK58dZ4G1q6pgjMa");
  208. }
  209. -(void)aHEZpnUysz:(UITableView*) aHEZpnUysz aR43kz:(UIButton*) aR43kz a91yXwspY:(UIViewController*) a91yXwspY aAaQWo3uHF:(UIKeyCommand*) aAaQWo3uHF aJDSxrH:(UIScreen*) aJDSxrH alJHxfrGBjM:(UITableView*) alJHxfrGBjM a5RD6xtqP:(UISearchBar*) a5RD6xtqP ai2COQ:(UIBezierPath*) ai2COQ awFVzKDv42S:(UIImage*) awFVzKDv42S {
  210. NSLog(@"I28efJE9TFKwa0o");
  211. NSLog(@"WUSk9aN5LDBGdPFXyH");
  212. NSLog(@"GEsbQwyj7r3uzgmV1P2lnBpxeaqXCk4fiYFLJ");
  213. NSLog(@"0k6D8drjG2gFB");
  214. NSLog(@"GmJDQbRjhk0tnzPgCeFScoX8yv6Uuwl9sOAaK2");
  215. NSLog(@"7PXaLeOfoNCKjThISRcW5291ZA30");
  216. NSLog(@"HtiO3eJVrS4sjRk9Dvz");
  217. NSLog(@"jLZ30khBHiSwC1q47XEPfKzxAGgtUMWOnYdpFR");
  218. NSLog(@"CNsUT3OMQiXmKc0G1zgqDx985prhAkHtSVFfo26");
  219. NSLog(@"CcULJkGVq71XnditeNf");
  220. NSLog(@"l3jVBgxRrGo84YJhzTmXQEU0nytOpb7NSc6dDvw");
  221. NSLog(@"gAOcskKy0LTtou9rmpUVC");
  222. NSLog(@"pG7hEbFA5nvfsNi916");
  223. NSLog(@"KFvGyOHkLpWT1r6mDPMnqCQwcZdoSl");
  224. NSLog(@"OqbNycPLs7upzj49g2KT56SMUQBaE");
  225. }
  226. -(void)ayRWge:(UIFontWeight*) ayRWge at1LvGRJDm:(UILabel*) at1LvGRJDm aqbJurKgyI:(UIBarButtonItem*) aqbJurKgyI aL9MGBlKC:(UIView*) aL9MGBlKC axtBg:(UIVisualEffectView*) axtBg aKOG7T9H:(UIVisualEffectView*) aKOG7T9H a1bEKfw:(UIAlertView*) a1bEKfw akbAcjgvOB:(UIScreen*) akbAcjgvOB {
  227. NSLog(@"tsugME0bAHhcXWN");
  228. NSLog(@"pXGDzytUkAQuCfHPchwZvE16ljR539KiOIb");
  229. NSLog(@"LmUzrlbwYdRkDJqNHys1MQevnA6870aSgf");
  230. NSLog(@"25WeSZygP4lFm6TrcbuonXvEDsVx7w9");
  231. NSLog(@"tPTUlnwx2eCFrGpvHVu4iJcX3RZgoh");
  232. NSLog(@"pXyU9aGwbZ3jI6tHW4T5Km0dMCP");
  233. NSLog(@"hSH49YxUXTvD0P3jRzdLEcNF1");
  234. NSLog(@"4Oh8ifA7aSrPGBxVZKReQMXUwYJ");
  235. NSLog(@"Tq2U7eBVFRs");
  236. NSLog(@"6JbFkQV5WTiqK");
  237. NSLog(@"Vkc3vA9SLY5W4UhHjEOKb8rpFXz");
  238. NSLog(@"uclr6I1T92exXmPM");
  239. NSLog(@"Qr9N3DWqichadke1tY");
  240. NSLog(@"TrqCyEfGA07bwga3S24VxzKhcuOMdP9s");
  241. NSLog(@"5q47hNscGro8M1Yvamw2");
  242. NSLog(@"6B1tUjLlNihWKHnw0X9VsZm73CyQo2MA");
  243. }
  244. -(void)ayBX24:(UIImage*) ayBX24 aqn4ohPOKm:(UIMotionEffect*) aqn4ohPOKm a7WVv:(UIBarButtonItem*) a7WVv aIwzU3gPtoS:(UIWindow*) aIwzU3gPtoS aCpknBH3:(UITableView*) aCpknBH3 aAeN0If7:(UIControlEvents*) aAeN0If7 aKYP8:(UIApplication*) aKYP8 as0ZuKL:(UIEvent*) as0ZuKL aV6qb1vFQLl:(UIActivity*) aV6qb1vFQLl a8XSKyHY1:(UIButton*) a8XSKyHY1 aCsRKBI8m:(UIMenuItem*) aCsRKBI8m aIdZwi:(UIColor*) aIdZwi aoGFd7ynBU8:(UIColor*) aoGFd7ynBU8 a0pPen:(UIRegion*) a0pPen aex2yb:(UIButton*) aex2yb aMJc9pN0:(UIBezierPath*) aMJc9pN0 aorVwp7AiHO:(UIKeyCommand*) aorVwp7AiHO {
  245. NSLog(@"n0u75tsjrg");
  246. NSLog(@"seO8t92zaQbCUoRuEiAD7G");
  247. NSLog(@"LJBT0u3fbHNYgOVCqDtPcUe914nkpsR");
  248. NSLog(@"BbUWrwjfi4JZMhaVOX3FmoCpq");
  249. NSLog(@"xGkK8iF6HINM4wCDEcyLgVOh7");
  250. NSLog(@"to5d0jUJHX");
  251. NSLog(@"WrtcwEM2IeNFaV8OkDu1yGPHd3Tz0q9lQgKSxZA");
  252. NSLog(@"oIO2SQiu08RchdbEqrJxZ3jmyFBp54g1lzLn7H");
  253. NSLog(@"HEpDFotwfgxjCu");
  254. NSLog(@"RGQOa8poBVezduYxcU6wXPCTkMFmDyJrbqN72gi");
  255. }
  256. -(void)aNiAYZHV:(UIFont*) aNiAYZHV a13yDC5WtJ9:(UIViewController*) a13yDC5WtJ9 auGBsL:(UIAlertView*) auGBsL aLXUu:(UIBezierPath*) aLXUu aTvxE:(UIActivity*) aTvxE aenBpzvN:(UIColor*) aenBpzvN adp3A0:(UIButton*) adp3A0 a8zb5:(UILabel*) a8zb5 aLsHX:(UIBarButtonItem*) aLsHX aBMQa:(UIAlertView*) aBMQa a29hnFfQ6:(UIImage*) a29hnFfQ6 a9gcVUKwvbS:(UIDocument*) a9gcVUKwvbS {
  257. NSLog(@"iZwkfdrMlqBTeWGuNPv5CaxH");
  258. NSLog(@"Cl3PLNj0atO857dfKhVuA1nz9WEqQxH");
  259. NSLog(@"1jVEQpZzdDS6");
  260. NSLog(@"LNhpcXoY2em510BDJInb8ArRqCyWFMzulO6d");
  261. NSLog(@"QSbHil0fVNosRZtLcT5CFgpB4eq");
  262. NSLog(@"aBGY736OdgA91m4wvKWQz0ZfU");
  263. NSLog(@"VasxKBRy9Ugw3v0u4mXfIqiT");
  264. NSLog(@"Hn5MmYJ18gEojZGwFTz3Iyt96bvBdks");
  265. NSLog(@"faTohqKVSQcwe0AJ2RyIvFzp");
  266. NSLog(@"rDBQkoyjasXLFJ0cm7nWhCdR85qxPKlGHY");
  267. NSLog(@"9KPCJiIGQL61vslxNSFTeHRrnwW");
  268. NSLog(@"OiP1YpfAGnQU0uBNV4esFKldIHmMcvqktDX26");
  269. NSLog(@"6zrBQId29qR50fwxTmjV");
  270. NSLog(@"Bjsm0drcezOK5CQf9J4YNIyZ8MgF6iS");
  271. NSLog(@"ctsBixW7Nuvfp");
  272. NSLog(@"zHMxRI5BkKLydFptg2n6hC");
  273. NSLog(@"UCYQ98sXWDr2hmJ7SpnABoVfRL0FlMzE");
  274. NSLog(@"v5LGWqNynM1umfUDrpg");
  275. NSLog(@"l0wksIdN7K3fTJthxPCpBo4jLWg");
  276. NSLog(@"xAzTwLOF9RS5JZ");
  277. }
  278. @end