'use strict'; /** * @ngdoc function * @name netvueApp.controller:PasswordresetCtrl * @description * # PasswordresetCtrl * Controller of the netvueApp */ angular.module('netvueApp') .controller('PasswordresetCtrl', ['$scope', '$routeParams', '$location', '$cookieStore', 'Validator', function ($scope, $routeParams, $location, $cookieStore, Validator) { $scope.data = {}; $scope.data.code = $location.search().code; $scope.expires = $location.search().expires; $scope.loc = $scope.failback = function () { $location.url('/memberresetpwd'); }; if (!$scope.data.code || !$scope.expires) { $scope.$emit('showInfoModal', { 'langcontent': 'broken_link', 'clickPositive': $scope.failback }); } else { var nowdate = new Date(); if (nowdate.getTime() > $scope.expires) { $scope.$emit('showInfoModal', { 'langcontent': 'expire_link', 'clickPositive': $scope.failback }); } } $scope.sumbitFunc = function() { $scope.errcode = undefined; if ($scope.usererr || $scope.pwderr || $scope.pwderr2) return; $scope.data.newpass = hex_md5($scope.plainPWD); var param = { data: $scope.data, scope:$scope, success: function(data, textStatus, xhr) { if (xhr.status == 204) { $cookieStore.put('passmd5', $scope.data.newpass); $scope.$emit('showInfoModal', { 'langcontent': 'reset_password_success', 'clickPositive':function() { $location.url('/memberlogin'); } }); } }, fail: function(xhr, textStatus, errorThrown) { var responseMsg = JSON.parse(xhr.responseText); console.log(responseMsg.ret); console.log(API.errorCode(responseMsg.ret)); $scope.errcode = responseMsg.ret; } } API['update_user_password_code'](param); }; $scope.$watch('data.user', function(value){ $scope.usererr = Validator.isValidUsername(value); }); $scope.$watch('plainPWD', function(value){ $scope.pwderr = Validator.isValidPassword(value); }); $scope.$watch('plainPWD2', function(value){ $scope.pwderr2 = (value && (value != $scope.plainPWD)) ? 'two_pwd_not_match' : null; }); }]);