LoginViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. //
  2. // LoginViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/7/5.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. #import "LoginViewController.h"
  8. //#import "LPhoneLoginVC.h"
  9. #import "JSONKit.h"
  10. //#import "WeiboSDK.h"
  11. //#import <TencentOpenAPI/TencentOAuth.h>
  12. #import "PhoneLoginViewController.h"
  13. #import "MGRegisterViewController.h"//注册界面
  14. #import "MGLoginView.h"
  15. #import "LPhoneRegistVC.h"
  16. #import "BGLoginView.h"
  17. #import "LoginRecommendVC.h"
  18. //#import "OpenInstallSDK.h"
  19. //#import <FBSDKLoginKit/FBSDKLoginKit.h>
  20. #import <UMLink/UMLink.h>
  21. //#import <FBSDKCoreKit/FBSDKCoreKit.h>
  22. #import "AppleIDManager.h"
  23. @interface LoginViewController ()<NLgDelegate,MobClickLinkDelegate>
  24. //@property (strong, nonatomic) UIButton *visitorsLoginBtn; //游客登入的btn
  25. @property (strong, nonatomic) NSMutableArray *Marray; //登入方式的数组
  26. //@property (strong, nonatomic) UIImageView *selectedImageView; //协议是否选择的图标
  27. //@property (assign, nonatomic) BOOL isSelectProtocol; //是否选择了协议
  28. @property (weak, nonatomic) IBOutlet UIButton *vistorLoginBtn;
  29. @property (weak, nonatomic) IBOutlet UIButton *wechatBtn;
  30. @property (weak, nonatomic) IBOutlet UIButton *qqBtn;
  31. @property (weak, nonatomic) IBOutlet UIButton *weiboBtn;
  32. @property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
  33. //@property(nonatomic, strong) MGLoginView *loginView;
  34. @property(nonatomic, strong) BGLoginView *loginView;
  35. @end
  36. @implementation LoginViewController{
  37. NSTimer *_timer; //定时器
  38. int _timeCount; //定时器时间
  39. }
  40. -(BGLoginView *)loginView{
  41. if (!_loginView) {
  42. _loginView = [BGLoginView new];
  43. _loginView.frame = CGRectMake(0, 0, kScreenW , kScreenH);
  44. FWWeakify(self)
  45. _loginView.clickVistorBlock = ^(BOOL isClickVistoers) {
  46. FWStrongify(self)
  47. [self visitorLoginBtnAction:nil];
  48. };
  49. _loginView.clickForgetPWBlock = ^(BOOL clickForget) {
  50. MGRegisterViewController *vc = [[MGRegisterViewController alloc]initWithLoginType:MGLOGIN_TYPE_FINDPASSWORD];
  51. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  52. };
  53. _loginView.clickReigsterBlock = ^(BOOL clickRegister) {
  54. MGRegisterViewController *vc = [[MGRegisterViewController alloc]initWithLoginType:MGLOGIN_TYPE_REGISTER];
  55. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  56. };
  57. _loginView.clickLoginBlock = ^(NSInteger i) {
  58. FWStrongify(self)
  59. if (i == 0) {
  60. [self loginCodeBtn];
  61. }else if (i == 1){
  62. [self loginByPhone];
  63. }else if (i == 2){
  64. [self wechatLoginBtnAction:nil];
  65. }else if (i == 3){
  66. [self agreementBtnAction:nil];
  67. }
  68. if (i == 1000 + 1) {
  69. [self loginByQQ];
  70. }else if (i == 1000 + 2){
  71. [self loginByWechat];
  72. }else if (i == 1000 + 4){
  73. MGRegisterViewController *vc = [[MGRegisterViewController alloc]initWithLoginType:MGLOGIN_TYPE_CODELOGIN];
  74. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  75. }else if (i == 1000 + 5){//facebook
  76. // [self getUserInfoForPlatform:UMSocialPlatformType_Facebook];
  77. [self loginByFacebook];
  78. }else if (i == 1000 + 6){//google
  79. [self getUserInfoForPlatform:UMSocialPlatformType_GooglePlus];
  80. }
  81. };
  82. }
  83. return _loginView;
  84. }
  85. /*
  86. -(MGLoginView *)loginView{
  87. if (!_loginView) {
  88. _loginView = [MGLoginView new];
  89. _loginView.frame = CGRectMake(kRealValue(21), 0, kScreenW - kRealValue(21 * 2), kRealValue(405));
  90. _loginView.centerY = kScreenH / 2 + kRealValue(15);
  91. _loginView.layer.masksToBounds = YES;
  92. _loginView.layer.cornerRadius = 5;
  93. _loginView.backgroundColor = kWhiteColor;
  94. FWWeakify(self)
  95. _loginView.clickLoginBlock = ^(NSInteger i) {
  96. FWStrongify(self)
  97. if (i == 0) {
  98. [self loginCodeBtn];
  99. }else if (i == 1){
  100. [self loginByPhone];
  101. }else if (i == 2){
  102. [self wechatLoginBtnAction:nil];
  103. }else if (i == 3){
  104. [self agreementBtnAction:nil];
  105. }
  106. };
  107. }
  108. return _loginView;
  109. }
  110. */
  111. - (void)viewDidLoad
  112. {
  113. [super viewDidLoad];
  114. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showVisitorsBtn) name:@"getDeviceTokenComplete" object:nil];
  115. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  116. [imgView setImage:[UIImage imageNamed:@"mg_ig_bgView"]];
  117. [self.view addSubview:imgView];
  118. [self.view addSubview:self.loginView];
  119. _timeCount = 60;
  120. self.LView.LDelegate = self;
  121. [MobClickLink getInstallParams:^(NSDictionary *params, NSURL *URL, NSError *error) {
  122. if(params != nil)
  123. {
  124. NSDictionary *openinstalDic =
  125. @{
  126. @"invite_code":[NSString stringWithFormat:@"%@",params[@"invite_code"]],
  127. @"channel":[NSString stringWithFormat:@"%@",params[@"channel"]],
  128. };
  129. [GlobalVariables sharedInstance].openinstallDic = openinstalDic;
  130. if (!error) {
  131. [MobClickLink handleLinkURL:URL delegate:self];
  132. }
  133. }
  134. } enablePasteboard:YES];
  135. // [[OpenInstallSDK defaultManager] getInstallParmsWithTimeoutInterval:300 completed:^(OpeninstallData * _Nullable appData) {
  136. // if(appData.data != nil)
  137. // {
  138. // NSDictionary *openinstalDic =
  139. // @{
  140. // @"invite_code":[NSString stringWithFormat:@"%@",appData.data[@"invite_code"]],
  141. // @"channel":[NSString stringWithFormat:@"%@",appData.data[@"channel"]],
  142. // };
  143. // [GlobalVariables sharedInstance].openinstallDic = openinstalDic;
  144. // }
  145. // }];
  146. // [self loginWay];
  147. }
  148. #pragma mark - MobClickLinkDelegate
  149. - (void)getLinkPath:(NSString *)path params:(NSDictionary *)params{
  150. [GlobalVariables sharedInstance].openinstallDic = params;
  151. }
  152. - (void)viewWillDisappear:(BOOL)animated
  153. {
  154. [super viewWillDisappear:animated];
  155. [self.navigationController setNavigationBarHidden:NO];
  156. [IQKeyboardManager sharedManager].enable = NO;
  157. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  158. }
  159. - (void)viewWillAppear:(BOOL)animated
  160. {
  161. [super viewWillAppear:animated];
  162. [self setUpLocalizationString];
  163. [self.navigationController setNavigationBarHidden:YES animated:YES];
  164. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:animated];
  165. [IQKeyboardManager sharedManager].enable = YES;
  166. [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  167. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  168. [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 5.0f;
  169. }
  170. - (void)initFWVariables
  171. {
  172. [super initFWVariables];
  173. self.view.backgroundColor = kAppMainColor;
  174. // _isSelectProtocol = YES;
  175. _Marray = [[NSMutableArray alloc]init];
  176. _has_qq_login = (int)self.BuguLive.appModel.has_qq_login;
  177. _has_wx_login = (int)self.BuguLive.appModel.has_wx_login;
  178. _has_mobile_login = (int)self.BuguLive.appModel.has_mobile_login;
  179. _has_sina_login = (int)self.BuguLive.appModel.has_sina_login;
  180. _qqBtn.hidden = (int)self.BuguLive.appModel.has_qq_login == 0;
  181. _wechatBtn.hidden = (int)self.BuguLive.appModel.has_wx_login == 0;
  182. _phoneBtn.hidden = (int)self.BuguLive.appModel.has_mobile_login == 0;
  183. _weiboBtn.hidden = (int)self.BuguLive.appModel.has_sina_login == 0;
  184. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(wxloginback:) name:kWXLoginBack object:nil];
  185. }
  186. - (void)initFWUI
  187. {
  188. [super initFWUI];
  189. // [self creatView];
  190. }
  191. #pragma mark 主UI
  192. - (void)showVisitorsBtn
  193. {
  194. self.vistorLoginBtn.hidden = YES;
  195. }
  196. #pragma mark 登入方式 0qq 1微信 2微博 3手机
  197. - (void)loginWay
  198. {
  199. if (self.has_qq_login == 1)//QQ
  200. {
  201. [_Marray addObject:@"1"];
  202. }
  203. if (self.has_wx_login == 1)//微信
  204. {
  205. [_Marray addObject:@"2"];
  206. }
  207. if (self.has_sina_login == 1)//微博
  208. {
  209. [_Marray addObject:@"3"];
  210. }
  211. // if (self.has_mobile_login == 1)//手机
  212. // {
  213. [_Marray addObject:@"4"];
  214. // }
  215. //如果各种登入方式都没有就将手机的登入方式都显示出来
  216. if (_Marray.count < 1)
  217. {
  218. _Marray = [[NSMutableArray alloc]initWithObjects:@"4", nil];
  219. }
  220. self.LView = [[ULGView alloc]initWithFrame:CGRectMake(0, kScreenH*0.7, kScreenW, 47) Array:_Marray];
  221. self.LView.LDelegate = self;
  222. [self.view addSubview:self.LView];
  223. }
  224. - (IBAction)phoneLoginBtnAction:(id)sender {
  225. [self loginByPhone];
  226. }
  227. //点击获取h验证码
  228. -(void)loginCodeBtn{
  229. if (self.loginView.phoneText.text.length < 1)
  230. {
  231. [FanweMessage alert:ASLocalizedString(@"手机号限制11位数!")];
  232. return;
  233. }
  234. self.loginView.codeBtn.enabled = NO;
  235. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timego) userInfo:nil repeats:YES];
  236. [self timego];
  237. FWWeakify(self)
  238. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  239. [parmDict setObject:@"login" forKey:@"ctl"];
  240. [parmDict setObject:@"send_mobile_verify_international" forKey:@"act"];
  241. // [parmDict setObject:@"1" forKey:@"wx_binding"];
  242. [parmDict setObject:self.loginView.phoneText.text forKey:@"mobile"];
  243. [self showMyHud];
  244. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  245. {
  246. FWStrongify(self)
  247. [self hideMyHud];
  248. [GlobalVariables sharedInstance].otp_message_id = [NSString stringWithFormat:@"%@",[responseJson toString:@"otp_message_id"]];
  249. if ([responseJson toInt:@"status"] != 1)
  250. {
  251. self.loginView.codeBtn.enabled = YES;
  252. [self.loginView.codeBtn setTitle:ASLocalizedString(@"发送验证码") forState:UIControlStateNormal];
  253. [_timer invalidate];
  254. _timer = nil;
  255. }
  256. } FailureBlock:^(NSError *error) {
  257. FWStrongify(self)
  258. [self hideMyHud];
  259. [self.loginView.codeBtn setTitle:ASLocalizedString(@"发送验证码") forState:UIControlStateNormal];
  260. [FanweMessage alert:ASLocalizedString(@"发送失败")];
  261. self.loginView.codeBtn.enabled = YES;
  262. }];
  263. }
  264. #pragma mark 获取验证码的倒计时
  265. - (void)timego
  266. {
  267. [self timerDec:_timeCount];
  268. }
  269. - (void)timerDec:(NSInteger)time
  270. {
  271. if(time > 0)
  272. {
  273. [self.loginView.codeBtn setTitle:[NSString stringWithFormat:ASLocalizedString(@"重新获取(%lds)"),(long)time] forState:UIControlStateDisabled];
  274. // [self.loginView.codeBtn setTitleColor:kAppGrayColor1 forState:UIControlStateDisabled];
  275. _timeCount --;
  276. }else if(time == 0)
  277. {
  278. self.loginView.codeBtn.enabled = YES;
  279. [self.loginView.codeBtn setTitle:[NSString stringWithFormat:ASLocalizedString(@"获取验证码")] forState:UIControlStateNormal];
  280. [_timer invalidate];
  281. _timeCount = 60;
  282. }
  283. }
  284. - (IBAction)wechatLoginBtnAction:(id)sender {
  285. // if (![WXApi isWXAppInstalled])
  286. // {
  287. // [FanweMessage alert:ASLocalizedString(@"微信未安装")];
  288. // }
  289. // else
  290. // {
  291. // [self loginByWechat];
  292. // }
  293. }
  294. - (IBAction)qqLoginBtnAction:(id)sender {
  295. // if (![TencentOAuth iphoneQQInstalled])
  296. // {
  297. // [FanweMessage alert:ASLocalizedString(@"QQ未安装")];
  298. // }
  299. // else
  300. // {
  301. [self loginByQQ];
  302. // }
  303. }
  304. - (IBAction)weiboLoginBtnAction:(id)sender {
  305. // if (![WeiboSDK isWeiboAppInstalled])
  306. // {
  307. // [FanweMessage alert:ASLocalizedString(@"新浪微博未安装")];
  308. // }
  309. // else
  310. // {
  311. [self loginByXinlang];
  312. // }
  313. }
  314. - (IBAction)agreementBtnAction:(id)sender {
  315. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.privacy_link isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  316. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  317. }
  318. #pragma mark 获取UserSig等参数
  319. - (void)getLoginParam:(NSMutableDictionary *)param
  320. {
  321. [self showMyHud];
  322. FWWeakify(self)
  323. [self.httpsManager POSTWithParameters:param SuccessBlock:^(NSDictionary *responseJson)
  324. {
  325. FWStrongify(self)
  326. if ([responseJson toInt:@"status"] == 1)
  327. {
  328. if ([responseJson toInt:@"need_bind_mobile"] == 1)//是否需要绑定手机1需要 0为不需要
  329. {
  330. [self hideMyHud];
  331. PhoneLoginViewController *loginVC = [[PhoneLoginViewController alloc]initWithNibName:NSStringFromClass([PhoneLoginViewController class]) bundle:[NSBundle mainBundle]];
  332. loginVC.loginId = self.loginId;
  333. loginVC.loginType = self.loginType;
  334. loginVC.accessToken = self.accessToken;
  335. loginVC.LNSecBPhone = YES;
  336. [[AppDelegate sharedAppDelegate] pushViewController:loginVC animated:YES];
  337. }else
  338. {
  339. [BGIMLoginManager sharedInstance].loginParam.identifier = [responseJson toString:@"data"];
  340. [BGIMLoginManager sharedInstance].loginParam.isAgree = [responseJson toInt:@"is_agree"];
  341. self.BuguLive.appModel.first_login = [responseJson toString:@"first_login"];
  342. self.BuguLive.appModel.new_level = [responseJson toInt:@"new_level"];
  343. self.BuguLive.appModel.login_send_score = [responseJson toString:@"login_send_score"];
  344. [GlobalVariables sharedInstance].token = [responseJson toString:@"token"];
  345. [[BGIMLoginManager sharedInstance] getUserSig:^{
  346. [[AppDelegate sharedAppDelegate] enterMainUI];
  347. [self hideMyHud];
  348. } failed:^(int errId, NSString *errMsg) {
  349. [self hideMyHud];
  350. }];
  351. }
  352. }
  353. else
  354. {
  355. [self hideMyHud];
  356. }
  357. } FailureBlock:^(NSError *error)
  358. {
  359. [self hideMyHud];
  360. [FanweMessage alertHUD:ASLocalizedString(@"获取登录参数失败,请稍后尝试")];
  361. }];
  362. }
  363. #pragma mark 微信登录
  364. - (void)loginByWechat
  365. {
  366. [self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
  367. /*
  368. // 构造SendAuthReq结构体
  369. SendAuthReq* req =[[SendAuthReq alloc ] init ];
  370. req.scope = @"snsapi_userinfo" ;
  371. req.state = @"123" ;
  372. // 第三方向微信终端发送一个SendAuthReq消息结构
  373. [WXApi sendReq:req];
  374. */
  375. }
  376. #pragma mark 微信登录获取code后oc调用js把code等传上去
  377. - (void)wxloginback:(NSNotification *)text
  378. {
  379. /*
  380. NSString *string = text.object;
  381. NSDictionary *dict = [string objectFromJSONString];
  382. NSString *code = [dict toString:@"code"];
  383. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  384. [parmDict setObject:@"login" forKey:@"ctl"];
  385. [parmDict setObject:@"wx_login" forKey:@"act"];
  386. [parmDict setObject:code forKey:@"code"];
  387. [self getLoginParam:parmDict];
  388. */
  389. }
  390. #pragma mark qq登录
  391. - (void)loginByQQ
  392. {
  393. [self getUserInfoForPlatform:UMSocialPlatformType_QQ];
  394. }
  395. #pragma mark 新浪登录
  396. - (void)loginByXinlang
  397. {
  398. [self getUserInfoForPlatform:UMSocialPlatformType_Sina];
  399. }
  400. #pragma mark 根据对应类型进行登录操作
  401. - (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
  402. {
  403. __weak typeof(self) ws = self;
  404. [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {
  405. UMSocialUserInfoResponse *resp = result;
  406. if (resp)
  407. {
  408. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  409. [parmDict setObject:@"login" forKey:@"ctl"];
  410. if (platformType == UMSocialPlatformType_QQ)
  411. {
  412. [parmDict setObject:@"qq_login" forKey:@"act"];
  413. [parmDict setObject:resp.openid forKey:@"openid"];
  414. [parmDict setObject:resp.accessToken forKey:@"access_token"];
  415. self.loginType = @"qq_login";
  416. self.loginId = resp.openid;
  417. }
  418. else if (platformType == UMSocialPlatformType_WechatSession)
  419. {
  420. [parmDict setObject:@"wx_login" forKey:@"act"];
  421. [parmDict setObject:resp.openid forKey:@"openid"];
  422. [parmDict setObject:resp.accessToken forKey:@"access_token"];
  423. self.loginType = @"wx_login";
  424. self.loginId = resp.openid;
  425. }
  426. else if (platformType == UMSocialPlatformType_Sina)
  427. {
  428. [parmDict setObject:@"sina_login" forKey:@"act"];
  429. [parmDict setObject:resp.uid forKey:@"sina_id"];
  430. [parmDict setObject:resp.accessToken forKey:@"access_token"];
  431. self.loginType = @"sina_login";
  432. self.loginId = resp.uid;
  433. }else if (platformType == UMSocialPlatformType_Facebook){
  434. [parmDict setObject:@"sina_login" forKey:@"act"];
  435. [parmDict setObject:resp.uid forKey:@"sina_id"];
  436. [parmDict setObject:resp.accessToken forKey:@"access_token"];
  437. self.loginType = @"sina_login";
  438. self.loginId = resp.uid;
  439. }else if (platformType == UMSocialPlatformType_GooglePlus){
  440. }
  441. self.accessToken = resp.accessToken;
  442. [ws getLoginParam:parmDict];
  443. }
  444. }];
  445. }
  446. #pragma mark 手机登录
  447. - (void)loginByPhone
  448. {
  449. if (self.loginView.phoneText.text.length < 1) {
  450. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"手机号限制11位数!")];
  451. return;
  452. }
  453. //6.28号修改为密码登录
  454. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  455. [parmDict setObject:@"login" forKey:@"ctl"];
  456. [parmDict setObject:@"password_login" forKey:@"act"];
  457. [parmDict setObject:self.loginView.phoneText.text forKey:@"mobile"];
  458. [parmDict setObject:self.loginView.codeText.text forKey:@"password"];
  459. FWWeakify(self)
  460. [self showMyHud];
  461. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  462. {
  463. FWStrongify(self)
  464. [self hideMyHud];
  465. if ([responseJson toInt:@"status"] == 1)
  466. {
  467. self.BuguLive.appModel.new_level = [responseJson toInt:@"new_level"];
  468. self.BuguLive.appModel.first_login = [responseJson toString:@"first_login"];
  469. self.BuguLive.appModel.login_send_score = [responseJson toString:@"login_send_score"];
  470. if ([responseJson toInt:@"is_lack"] == 1)
  471. {
  472. LPhoneRegistVC *phoneRegist = [[LPhoneRegistVC alloc]init];
  473. phoneRegist.used_id = [responseJson toString:@"user_id"];
  474. phoneRegist.userInfoDic = responseJson[@"user_info"];
  475. phoneRegist.userName = [responseJson[@"user_info"] toString:@"nick_name"];
  476. // [[AppDelegate sharedAppDelegate]pushViewController:phoneRegist];
  477. [self.navigationController presentViewController:phoneRegist animated:YES completion:nil];
  478. }
  479. else
  480. {
  481. [self showMyHud];
  482. NSDictionary *userDic = [responseJson valueForKey:@"user_info"];
  483. self.BuguLive.appModel.is_open_young = [userDic objectForKey:@"is_open_young"];
  484. [BGIMLoginManager sharedInstance].loginParam.identifier = [responseJson toString:@"user_id"];
  485. [BGIMLoginManager sharedInstance].loginParam.isAgree = [responseJson toInt:@"is_agree"];
  486. [GlobalVariables sharedInstance].token = [userDic toString:@"token"];
  487. [[BGIMLoginManager sharedInstance] getUserSig:^{
  488. [[AppDelegate sharedAppDelegate] enterMainUI];
  489. [self hideMyHud];
  490. } failed:^(int errId, NSString *errMsg) {
  491. [self hideMyHud];
  492. }];
  493. }
  494. }
  495. } FailureBlock:^(NSError *error)
  496. {
  497. FWStrongify(self)
  498. [self hideMyHud];
  499. }];
  500. // PhoneLoginViewController *phoneVC = [[PhoneLoginViewController alloc]initWithNibName:NSStringFromClass([PhoneLoginViewController class]) bundle:[NSBundle mainBundle]];
  501. // [[AppDelegate sharedAppDelegate]pushViewController:phoneVC];
  502. }
  503. //游客登录
  504. - (IBAction)visitorLoginBtnAction:(id)sender {
  505. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  506. [parmDict setObject:@"login" forKey:@"ctl"];
  507. [parmDict setObject:@"visitors_login" forKey:@"act"];
  508. [parmDict setObject:[GlobalVariables sharedInstance].deviceToken forKey:@"um_reg_id"];
  509. [self showMyHud];
  510. FWWeakify(self)
  511. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  512. FWStrongify(self)
  513. if ([responseJson toInt:@"status"] == 1)
  514. {
  515. [BGIMLoginManager sharedInstance].loginParam.identifier = [[responseJson objectForKey:@"user_info"] toString:@"user_id"];
  516. [BGIMLoginManager sharedInstance].loginParam.isAgree = [[responseJson objectForKey:@"user"] toInt:@"is_agree"];
  517. self.BuguLive.appModel.first_login = [responseJson toString:@"first_login"];
  518. self.BuguLive.appModel.new_level = [responseJson toInt:@"new_level"];
  519. self.BuguLive.appModel.login_send_score = [responseJson toString:@"login_send_score"];
  520. [[BGIMLoginManager sharedInstance] getUserSig:^{
  521. [[AppDelegate sharedAppDelegate] enterMainUI];
  522. [self hideMyHud];
  523. } failed:^(int errId, NSString *errMsg) {
  524. [self hideMyHud];
  525. }];
  526. }
  527. else
  528. {
  529. [self hideMyHud];
  530. }
  531. } FailureBlock:^(NSError *error) {
  532. FWStrongify(self)
  533. [self hideMyHud];
  534. }];
  535. }
  536. - (void)dealloc
  537. {
  538. [[NSNotificationCenter defaultCenter]removeObserver:self];
  539. }
  540. //- (UIStatusBarStyle)preferredStatusBarStyle{
  541. //
  542. // if (@available(iOS 13, *)) {
  543. // return UIStatusBarStyleLightContent;
  544. // }
  545. // return UIStatusBarStyleLightContent;
  546. //}
  547. - (void)loginByFacebook {
  548. #warning Facebook登录,暂时注释
  549. // FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
  550. //// [loginManager logOut];
  551. // __weak __typeof(self)weakSelf = self;
  552. // [loginManager logInWithPermissions:@[@"public_profile"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
  553. // if(result.isCancelled)
  554. // {
  555. //
  556. // }
  557. // else
  558. // {
  559. //
  560. //// [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result2, NSError *error) {
  561. //// NSDictionary *resultDict = (NSDictionary *)result2;
  562. //// NSString *userName = resultDict[@"name"];
  563. ////
  564. //// NSString *headerImage = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture",resultDict[@"id"]];
  565. ////
  566. //// NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  567. //// [parmDict setObject:@"login" forKey:@"ctl"];
  568. ////
  569. //// [parmDict setObject:@"fb_login" forKey:@"act"];
  570. //// [parmDict setObject:result.token.userID forKey:@"openid"];
  571. //// [parmDict setObject:result.token.tokenString forKey:@"access_token"];
  572. ////
  573. //// [parmDict setObject:userName forKey:@"user_name"];
  574. //// [parmDict setObject:headerImage forKey:@"user_icon"];
  575. //// self.loginType = @"fb_login";
  576. //// self.loginId = result.token.userID;
  577. ////
  578. //// [weakSelf getLoginParam:parmDict];
  579. ////
  580. ////
  581. //// }];
  582. //
  583. //
  584. //
  585. // }
  586. // }];
  587. // [loginManager logInWithPermissions:@[] fromViewController:self handler:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
  588. // }];
  589. // [loginManager logInWithReadPermissions:@[@"email"]
  590. // fromViewController:self
  591. // handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
  592. // //TODO: process error or result
  593. // }];
  594. }
  595. @end