loginCtrl.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. angular.module('push')
  2. .controller('LoginCtrl', function ($scope, LoginService, UtilService, UserService, homepageOfNodeService, ConfigService, $ionicHistory, $timeout, SqliteStorageService, $ionicPopup, CommonService, $state, ResourceLibraryService, ConstantService) {
  3. if ($scope.app) {
  4. $scope.setStatusBar(0);
  5. }
  6. $scope.defaultLan = UserService.defaultLan;
  7. $scope.loginLogo = 'img/push_login.png';
  8. if ($scope.isLiyangApp) {
  9. $scope.loginLogo = 'img/liyang_login.jpg';
  10. }
  11. $scope.user = {
  12. name: '',
  13. password: ''
  14. };
  15. //登录
  16. $scope.login = function () {
  17. var loginName = $scope.user.name;
  18. var loginPassWord = $scope.user.password;
  19. if (!loginName || !loginPassWord) {
  20. if ($scope.app) {
  21. UtilService.showMess('手机号与密码是必填项!');
  22. } else {
  23. $ionicPopup.alert({
  24. title: '提示',
  25. template: "<p style='text-align: center;'>手机号与密码是必填项!</p>",
  26. buttons: [{ text: "确定" }]
  27. });
  28. //CommonService.showMessage('手机号与密码是必填项!', $scope);
  29. }
  30. return;
  31. }
  32. $scope.showLoadingToast();
  33. LoginService.login(loginName, loginPassWord).then(function (response) {
  34. $scope.hideLoadingToast();
  35. console.log(response);
  36. if (response.code == ConstantService.STATUS_TYPE_21002) {
  37. //未注册
  38. if ($scope.app) {
  39. UtilService.showMess(response.message);
  40. } else {
  41. if ($scope.defaultLan == 'Chinese') {
  42. $ionicPopup.alert({
  43. title: '提示',
  44. template: "<p style='text-align: center;'>" + response.message + "</p>",
  45. buttons: [{ text: "确定" }]
  46. });
  47. } else {
  48. $ionicPopup.alert({
  49. title: 'notice',
  50. template: "<p style='text-align: center;'>User not registered</p>",
  51. buttons: [{ text: "OK" }]
  52. });
  53. }
  54. //CommonService.showMessage(response.message, $scope);
  55. }
  56. } else if (response.code == ConstantService.STATUS_TYPE_21004) {
  57. //用户名或密码错误!
  58. if ($scope.app) {
  59. UtilService.showMess(response.message);
  60. } else {
  61. if ($scope.defaultLan == 'Chinese') {
  62. $ionicPopup.alert({
  63. title: '提示',
  64. template: "<p style='text-align: center;'>" + response.message + "</p>",
  65. buttons: [{ text: "确定" }]
  66. });
  67. } else {
  68. $ionicPopup.alert({
  69. title: 'notice',
  70. template: "<p style='text-align: center;'>Incorrect username or password</p>",
  71. buttons: [{ text: "OK" }]
  72. });
  73. }
  74. // CommonService.showMessage(response.message, $scope);
  75. }
  76. } else if (response.code == 21008) {
  77. //登录超出限制
  78. if ($scope.app) {
  79. UtilService.showMess(response.message);
  80. } else {
  81. if ($scope.defaultLan == 'Chinese') {
  82. $ionicPopup.alert({
  83. title: '提示',
  84. template: "<p style='text-align: center;'>" + response.message + "</p>",
  85. buttons: [{ text: "确定" }]
  86. });
  87. } else {
  88. $ionicPopup.alert({
  89. title: 'notice',
  90. template: "<p style='text-align: center;'>Incorrect username or password</p>",
  91. buttons: [{ text: "OK" }]
  92. });
  93. }
  94. // CommonService.showMessage(response.message, $scope);
  95. }
  96. }
  97. else if (response.code == 3351) {
  98. if ($scope.defaultLan == 'Chinese') {
  99. $ionicPopup.alert({
  100. title: '提示',
  101. template: '用户未注册!'
  102. });
  103. return;
  104. } else {
  105. $ionicPopup.alert({
  106. title: 'notice',
  107. template: 'User not registered!'
  108. });
  109. return;
  110. }
  111. } else if (response.code == ConstantService.STATUS_TYPE_21005) {
  112. //该用户名已被禁用
  113. if ($scope.app) {
  114. UtilService.showMess(response.message);
  115. } else {
  116. $ionicPopup.alert({
  117. title: '提示',
  118. template: "<p style='text-align: center;'>" + response.message + "</p>",
  119. buttons: [{ text: "确定" }]
  120. });
  121. //CommonService.showMessage(response.message, $scope);
  122. }
  123. } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  124. if ($scope.app) {
  125. UtilService.showMess(ConstantService.MESSAGE_TYPE_21000);
  126. }
  127. // } else {
  128. // CommonService.showMessage(ConstantService.MESSAGE_TYPE_21000, $scope);
  129. // }
  130. ConfigService.islogin = true;
  131. //$scope.selCom.hide();
  132. // $timeout(function () {
  133. // $state.reload();
  134. // },30);
  135. //存储用户信息--自动登录
  136. var tempdate = UtilService.formatDate();
  137. sessionStorage.id = response.data.userId;
  138. sessionStorage.mobile = $scope.user.name;
  139. // sessionStorage.password= $scope.user.password;
  140. sessionStorage.updatetime = tempdate.formattime2;
  141. sessionStorage.type = 1;
  142. //保存用户信息
  143. UserService.user = response.data;
  144. UserService.id = response.data.userid;
  145. //UserService.node = response.data.comefrom;
  146. if (UtilService.isDefined(response.data.node.nodename)) {
  147. //UserService.nodename = response.data.node.nodename;
  148. }
  149. UserService.role = response.data.userRoleList;//角色
  150. // if($scope.app){
  151. // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  152. // }
  153. $scope.getUserIMInfo();
  154. // UserService.viplevel = response.member.memberid;
  155. // ConfigService.mychannellist = response.channelList;
  156. //ConfigService.comefrom = response.data.comefrom;
  157. // $ionicHistory.clearCache();
  158. // $scope.go("tab.activityIndex");
  159. // $scope.go("tab.account");
  160. // console.log($location.path().split('/').slice(1).join('.'));
  161. // $scope.go($location.path().split('/').slice(1).join('.'))
  162. /*console.log($scope.user);*/
  163. localStorage.setItem("uid", response.data.userid);
  164. //用户手机号作为用户的唯一的表示,用作全局变量
  165. localStorage.setItem("mobile", $scope.user.name);
  166. //存储密码用作自动登录
  167. localStorage.setItem("password", $scope.user.password);
  168. //保存用户信息
  169. UserService.user = response;
  170. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  171. console.log(response);
  172. })
  173. homepageOfNodeService.getNodeAuth(UserService.node).then(function (res) {
  174. $scope.isUserManager = res.data;
  175. console.log($scope.isUserManager)
  176. })
  177. $timeout(function () {
  178. // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  179. $state.reload();
  180. }, 300);
  181. // $scope.goback();
  182. $state.go('tab.account');
  183. }
  184. }, function () {
  185. $scope.hideLoadingToast();
  186. // if($scope.app){
  187. // UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  188. // }else{
  189. // CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope);
  190. // }
  191. });
  192. };
  193. //微信第三方登录
  194. $scope.wechatLogin = function () {
  195. $scope.showLoadingToast();
  196. //请求用户授权
  197. var scope = "snsapi_userinfo",
  198. state = "_" + (+new Date());
  199. Wechat.auth(scope, state, function (response) {
  200. if ($scope.app) {
  201. UtilService.showMess("授权成功");
  202. } else {
  203. CommonService.showMessage("授权成功", $scope);
  204. }
  205. // console.log(response);
  206. LoginService.getAccessToken(response.code).then(function (res) {
  207. // console.log(res);
  208. // access_token: "16_pKE6r3tWT-Yq9Vjrlop7rXmVjMgXnv87W0UZammN_9yiGaDvMDj4TN5CuDMNYx4UAu7hbfiOLuCTgTFAEsSWV5_BtMJTQjjIdwTTtUk7fvY"
  209. // expires_in: 7200
  210. // openid: "oAmnd54xuec4OsNmIBLkqKHZgQ2M"
  211. // refresh_token: "16_Fc7btUDkiqNK8KGz3FZ9Zd5CkOtaGEiQEBzmFgmrq2ECsd-pRMBIJmpB0IYSTmQ3NBFh6So7vS9wY2dzQ09joaymZ3hHJdM8RxsJRlUiJew"
  212. // scope: "snsapi_userinfo"
  213. // unionid: "olQ930mg5NDUB2ZLN9k7N2DVoZMA"
  214. wechatReqLogin(res);
  215. }, function () {
  216. $scope.hideLoadingToast();
  217. });
  218. }, function (error) {
  219. // console.log(error);
  220. $scope.hideLoadingToast();
  221. });
  222. $timeout(function () {
  223. $scope.hideLoadingToast();
  224. }, 3000);
  225. };
  226. // $scope.login = function () {
  227. // $scope.showLoadingToast();
  228. // // console.log("scope.user.name = " + scope.user.name);
  229. // // console.log("scope.user.password = " + scope.user.password);
  230. // // console.log("user.loginname = " + user.loginname);
  231. // // console.log("user.password = " + user.password);
  232. // /*if($scope.user.name == null && $scope.user.password == null){
  233. // $scope.user.name = user.loginname;
  234. // $scope.user.password = user.password;
  235. // }*/
  236. // LoginService.login($scope.user.loginname, $scope.user.password).then(function (response) {
  237. // $scope.hideLoadingToast();
  238. // if (response.dataType == "-2") {
  239. // //未注册
  240. // if($scope.app){
  241. // UtilService.showMess("未注册");
  242. // }else{
  243. // $ionicPopup.alert({
  244. // title:'提示',
  245. // template:'未注册'
  246. // })
  247. // }
  248. // } else if (response.dataType == "0") {
  249. // //用户名或密码错误!
  250. // if($scope.app){
  251. // UtilService.showMess("手机号或密码错误");
  252. // }else{
  253. // $ionicPopup.alert({
  254. // title:'提示',
  255. // template:'手机号或密码错误'
  256. // })
  257. // }
  258. //
  259. // } else if (response.dataType == "2") {
  260. // //该用户名已被禁用
  261. // if($scope.app){
  262. // UtilService.showMess("用户名已被禁用");
  263. // }else{
  264. // $ionicPopup.alert({
  265. // title:'提示',
  266. // template:'用户名已被禁用'
  267. // })
  268. // }
  269. //
  270. // } else {
  271. // if($scope.app){
  272. // //UtilService.showMess("登录成功");
  273. // }else{
  274. // $ionicPopup.alert({
  275. // title:'提示',
  276. // //template:'登录成功'
  277. // })
  278. // }
  279. // if($scope.app){
  280. // //UtilService.showMess("登录成功");
  281. // }else{
  282. // //CommonService.showMessage("登录成功",$scope);
  283. // }
  284. // ConfigService.islogin = true;
  285. // //存储用户信息--自动登录
  286. // var tempdate = UtilService.formatDate();
  287. // var del_sql = "delete from userinfo";
  288. // if($scope.app){
  289. // SqliteStorageService.deleteData(del_sql);
  290. // SqliteStorageService.insertSingleData("userinfo", {
  291. // id: response.user.userId,
  292. // mobile: $scope.user.name,
  293. // password: $scope.user.password,
  294. // updatetime: tempdate.formattime2,
  295. // type: 1
  296. // });
  297. // }else{
  298. // sessionStorage.id=response.user.userId;
  299. // sessionStorage.mobile=response.user.name;
  300. // sessionStorage.password=response.user.password;
  301. // sessionStorage.updatetime=response.user.formattime2;
  302. // sessionStorage.type=1;
  303. // }
  304. //
  305. // //保存用户信息
  306. // UserService.user = response;
  307. // UserService.id = response.user.userId;
  308. // UserService.role = response.rolelist;
  309. // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  310. // UserService.viplevel = response.member.memberid;
  311. // ConfigService.mychannellist = response.channelList;
  312. // ConfigService.comefrom = response.user.comefrom;
  313. // $ionicHistory.clearCache();
  314. // // $scope.go("tab.activityIndex");
  315. // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  316. // $state.reload();
  317. // }
  318. // }, function () {
  319. // $scope.hideLoadingToast();
  320. // UtilService.showMess("网络不给力,请重试");
  321. // });
  322. // };
  323. $scope.showPrivacyPolicy = function () {
  324. $scope.go('privacyPolicy');
  325. }
  326. // //微信第三方登录
  327. // $scope.wechatLogin = function () {
  328. // $scope.showLoadingToast();
  329. // //请求用户授权
  330. // var scope = "snsapi_userinfo",
  331. // state = "_" + (+new Date());
  332. // Wechat.auth(scope, state, function (response) {
  333. // if($scope.app){
  334. // UtilService.showMess("授权成功");
  335. // }else{
  336. // $ionicPopup.alert({
  337. // title:'提示',
  338. // template:'授权成功'
  339. // })
  340. // }
  341. //
  342. // // console.log(response);
  343. // LoginService.getAccessToken(response.code).then(function (res) {
  344. // // console.log(res);
  345. // wechatReqLogin(res);
  346. // }, function () {
  347. // $scope.hideLoadingToast();
  348. // });
  349. // }, function (error) {
  350. // // console.log(error);
  351. // $scope.hideLoadingToast();
  352. // });
  353. // $timeout(function () {
  354. // $scope.hideLoadingToast();
  355. // }, 5000);
  356. // };
  357. //公用第三方登录返回处理
  358. var thirdCommonLogin = function (response, type, temptoken) {
  359. var tempwechat = {};
  360. if (type == 2) {
  361. tempwechat = angular.fromJson(response.weChat);
  362. } else {
  363. tempwechat = response.qq;
  364. }
  365. if (angular.isDefined(response.gsonInfo)) {
  366. var tempuser = angular.fromJson(response.gsonInfo);
  367. if (tempuser.dataType == "21005") {
  368. //该用户名已被禁用
  369. if ($scope.app) {
  370. UtilService.showMess("用户名已被禁用");
  371. } else {
  372. CommonService.showMessage("用户名已被禁用", $scope);
  373. }
  374. } else if (tempuser.dataType == "21006") {
  375. $scope.go('bindPhone', { tokeninfo: angular.toJson(temptoken), type: type });
  376. } else {
  377. if ($scope.app) {
  378. UtilService.showMess("登录成功");
  379. } else {
  380. CommonService.showMessage("登录成功", $scope);
  381. }
  382. //用户手机号作为用户的唯一的表示,用作全局变量
  383. localStorage.setItem("mobile", tempuser.user.mobile);
  384. //存储密码用作自动登录
  385. localStorage.setItem("password", tempuser.user.password);
  386. //保存用户的userid
  387. localStorage.setItem("userId", tempuser.user.userid);
  388. //保存用户信息
  389. UserService.user = tempuser.user;
  390. UserService.id = localStorage.getItem("userId");
  391. ConfigService.islogin = true;
  392. // 关闭登录框
  393. //$scope.selCom.hide();
  394. $scope.getUserInfo();//获取用户信息
  395. $state.reload();
  396. //存储用户信息--自动登录
  397. /*var tempdate = UtilService.formatDate();
  398. SqliteStorageService.deleteData("delete from userinfo");
  399. var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : "";
  400. var tempobj = {
  401. id: tempuser.user.userid,
  402. mobile: "",
  403. password: "",
  404. updatetime: tempdate.formattime2,
  405. access_token: tempwechat.access_token,
  406. refresh_token: refresh,
  407. openid: tempwechat.openid,
  408. type: type
  409. };
  410. SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) {
  411. }, function (err) {
  412. });*/
  413. ConfigService.isedit = 1;
  414. //保存用户信息
  415. UserService.user = tempuser.user;
  416. UserService.id = tempuser.user.userid;
  417. //UserService.node = tempuser.user.comefrom;
  418. if (UtilService.isDefined(tempuser.user.node.nodename)) {
  419. //UserService.nodename = tempuser.user.node.nodename;
  420. }
  421. UserService.role = tempuser.user.userRoleList;
  422. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  423. // UserService.viplevel = tempuser.member.memberid;
  424. // ConfigService.mychannellist = tempuser.channelList;
  425. ConfigService.comefrom = tempuser.user.comefrom;
  426. // $scope.go("tab.activityIndex");
  427. $timeout(function () {
  428. $state.reload();
  429. }, 300);
  430. $scope.goback();
  431. }
  432. } else {
  433. if (type == 2) {
  434. $scope.wechatLogin();
  435. } else {
  436. // if($scope.app){
  437. // UtilService.showMess("网络不给力,请重试");
  438. // }else{
  439. // CommonService.showMessage("网络不给力,请重试",$scope);
  440. // }
  441. }
  442. }
  443. $scope.hideLoadingToast();
  444. };
  445. //微信请求后台登录
  446. var wechatReqLogin = function (res) {
  447. LoginService.wxLogin(res, "", "").then(function (response) {
  448. thirdCommonLogin(response.data, 2, res);
  449. }, function () {
  450. $scope.hideLoadingToast();
  451. });
  452. };
  453. // var thirdCommonLogin = function (response, type, temptoken) {
  454. // var tempwechat = {};
  455. // if (type == 2) {
  456. // tempwechat = angular.fromJson(response.weChat);
  457. // } else {
  458. // tempwechat = response.qq;
  459. // }
  460. // if (angular.isDefined(response.gsonInfo)) {
  461. // var tempuser = angular.fromJson(response.gsonInfo);
  462. // if (tempuser.dataType == "2") {
  463. // //该用户名已被禁用
  464. // if($scope.app){
  465. // UtilService.showMess("用户名已被禁用");
  466. // }else{
  467. // $ionicPopup.alert({
  468. // title:'提示',
  469. // template:'用户名已被禁用'
  470. // })
  471. // }
  472. //
  473. // } else if (tempuser.dataType == "-2") {
  474. // $scope.go('bindPhone', {tokeninfo: angular.toJson(temptoken), type: type});
  475. // } else {
  476. // if($scope.app){
  477. // UtilService.showMess("登录成功");
  478. // }else{
  479. // $ionicPopup.alert({
  480. // title:'提示',
  481. // template:'登录成功'
  482. // })
  483. // }
  484. //
  485. // ConfigService.islogin = true;
  486. // //存储用户信息--自动登录
  487. // var tempdate = UtilService.formatDate();
  488. // SqliteStorageService.deleteData("delete from userinfo");
  489. // var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : "";
  490. // var tempobj = {
  491. // id: tempuser.user.userId,
  492. // mobile: "",
  493. // password: "",
  494. // updatetime: tempdate.formattime2,
  495. // access_token: tempwechat.access_token,
  496. // refresh_token: refresh,
  497. // openid: tempwechat.openid,
  498. // type: type
  499. // };
  500. // SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) {
  501. // }, function (err) {
  502. // });
  503. // ConfigService.isedit = 1;
  504. // //保存用户信息
  505. // UserService.user = tempuser;
  506. // UserService.id = tempuser.user.userId;
  507. // UserService.role = tempuser.rolelist;
  508. // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  509. // UserService.viplevel = tempuser.member.memberid;
  510. // ConfigService.mychannellist = tempuser.channelList;
  511. // ConfigService.comefrom = tempuser.user.comefrom;
  512. // $ionicHistory.clearCache();
  513. // // $scope.go("tab.activityIndex");
  514. // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  515. // $state.reload();
  516. // }
  517. // } else {
  518. // if (type == 2) {
  519. // $scope.wechatLogin();
  520. // } else {
  521. // UtilService.showMess("网络不给力,请重试");
  522. // }
  523. // }
  524. // $scope.hideLoadingToast();
  525. // };
  526. //
  527. // //微信请求后台登录
  528. // var wechatReqLogin = function (res) {
  529. // LoginService.wxLogin(res, "", "").then(function (response) {
  530. // thirdCommonLogin(response, 2, res);
  531. // }, function () {
  532. // $scope.hideLoadingToast();
  533. // });
  534. // };
  535. $scope.qqLogin = function () {
  536. $scope.showLoadingToast();
  537. var args = {};
  538. args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
  539. QQSDK.ssoLogin(function (result) {
  540. // console.log(result);
  541. LoginService.QQLogin(result, "", "").then(function (response) {
  542. thirdCommonLogin(response, 3, result);
  543. }, function () {
  544. $scope.hideLoadingToast();
  545. })
  546. }, function (failReason) {
  547. UtilService.showMess("授权失败");
  548. $scope.hideLoadingToast();
  549. }, args);
  550. };
  551. $scope.showPassword = function () {
  552. /*$scope.show_psd = !$scope.show_psd*/
  553. $scope.show_psd = false;
  554. };
  555. //关闭启动动画
  556. $timeout(function () {
  557. if (navigator.splashscreen) {
  558. navigator.splashscreen.hide();
  559. }
  560. }, 1000);
  561. //$scope.loginModelPublic();
  562. // $scope.hideModel=function () {
  563. // $scope.selCom.hide();
  564. // }
  565. });