account.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. (function (app) {
  2. app.controller('wechatLoginCtrl', ["$scope", "userService","$ionicNavBarDelegate", "storage", "$state", "msg", "$http", "util","$timeout",
  3. function ($scope, userService,$ionicNavBarDelegate, storage, $state, msg, $http, util, $timeout) {
  4. $ionicNavBarDelegate.showBackButton(false);
  5. $scope.loginbywx = function(){
  6. var scope = "snsapi_userinfo", state = "_" + (+new Date());
  7. Wechat.auth(scope, state, function (response) {
  8. alert(JSON.stringify(response));
  9. $scope.wecaht = response;
  10. }, function (reason) {
  11. alert("Failed: " + reason);
  12. });
  13. msg.loading('登录中...');
  14. userService.loginbywx($scope.wechat).then(function(result){
  15. msg.hide();
  16. storage.setObject('user', result.data.data.user);
  17. storage.set('token', result.data.data.token);
  18. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
  19. $scope.user=storage.getObject('user');
  20. $state.go('app.home');
  21. },function(error){
  22. $state.go("loginAccount",{wechat:$scope.wecaht})
  23. });
  24. };
  25. }]);
  26. app.controller('loginCtrl', ["$scope", "userService","$ionicNavBarDelegate", "storage", "$state", "msg", "$http", "util","$timeout",
  27. function ($scope, userService,$ionicNavBarDelegate, storage, $state, msg, $http, util, $timeout) {
  28. $ionicNavBarDelegate.showBackButton(false);
  29. $scope.wecaht = $stateParams.wechat;
  30. $scope.vm = {
  31. mobile: '',
  32. verify_code: '',
  33. waitSeconds: "获取验证码"
  34. };
  35. $scope.login = function () {
  36. msg.loading('登录中...');
  37. userService.login($scope.vm.mobile, $scope.vm.verify_code,$scope.wechat).then(function (result) {
  38. msg.hide();
  39. storage.setObject('user', result.data.data.user);
  40. storage.set('token', result.data.data.token);
  41. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
  42. $scope.user=storage.getObject('user');
  43. $state.go('app.home');
  44. }, function (error) {
  45. // msg.hide();
  46. // msg.error(error.data.message);
  47. });
  48. };
  49. /* $scope.loginbywx = function () {
  50. var scope = "snsapi_userinfo", state = "_" + (+new Date());
  51. Wechat.auth(scope, state, function (response) {
  52. alert(JSON.stringify(response));
  53. }, function (reason) {
  54. alert("Failed: " + reason);
  55. });
  56. };*/
  57. //获取验证码
  58. $scope.getVerifyCode = function () {
  59. // if (!util.isMobile($scope.vm.mobile)) {
  60. // msg.text('请输入正确的手机号');
  61. // return;
  62. // }
  63. if ($scope.vm.waitSeconds!="获取验证码") {
  64. msg.text('请稍后再试', true);
  65. return;
  66. }
  67. $scope.vm.waitSeconds = "正在发送";
  68. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  69. wait(50);
  70. // $scope.returncode = result.data;
  71. if(result.data.data.verify_code)msg.success(result.data.data.verify_code);
  72. }, function (error) {
  73. $scope.vm.waitSeconds = "获取验证码";
  74. wait(0);
  75. // msg.error(error.data.message);
  76. });
  77. };
  78. var wait = function (seconds) {
  79. if (seconds > 0) {
  80. $scope.vm.waitSeconds = "" + seconds + "秒";
  81. } else {
  82. $scope.vm.waitSeconds = "获取验证码";
  83. }
  84. $timeout(function () {
  85. if (seconds >= 1)
  86. wait(seconds - 1);
  87. }, 1000);
  88. };
  89. $scope.clear = function(){
  90. document.getElementById("tel").value = "";
  91. }
  92. }]);
  93. })(angular.module('app.controllers'));