123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict';
- app.controller('ForgotpwdCtrl', ['$scope', '$http', '$state', '$interval', 'toaster', 'md5', function ($scope, $http, $state, $interval, toaster, MD5) {
- $scope.username = "";
- $scope.code = "";
- $scope.authError = null;
- $scope.codeTime = 0;
- $scope.getCheckCode = function () {
- function isPhone(str) {
- var phoneReg = /^[1][3456789]\d{9}$/;
- return phoneReg.test(str);
- }
- if (!isPhone($scope.username)) {
- toaster.pop("warning", "提示", "请输入11位正确手机号码",2000);
- return;
- }
- $scope.authError = null;
- $http.get('/manager/getCheckCode', {params: {username: $scope.username}})
- .then(function (response) {
- if (response.result == 0) {
- $scope.authError = response.description;
- } else {
- $scope.codeTime = 60;
- var timer = $interval(function () {
- $scope.codeTime--;
- if ($scope.codeTime <= 0) {
- $interval.cancel(timer);
- }
- }, 1000);
- }
- }, function (x) {
- $scope.authError = '服务器异常';
- });
- };
- $scope.sendCheck = function () {
- $scope.authError = null;
- $http.post('/manager/verifyForgetCode', {
- username: $scope.username,
- password: MD5.createHash($scope.password + ''),
- code: $scope.code
- })
- .then(function (response) {
- if (response.result === 0) {
- $scope.authError = '验证码不对';
- } else {
- $state.go('app');
- }
- }, function (x) {
- $scope.authError = '服务器异常';
- });
- };
- }]);
|