feat(users): add feature for verify mail address and active account by mail

This commit is contained in:
OldHawk
2017-11-06 15:01:43 +08:00
parent c34ec9736d
commit 6076ec0a1f
14 changed files with 278 additions and 121 deletions

View File

@@ -5,15 +5,16 @@
.module('users')
.controller('AuthenticationController', AuthenticationController);
AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator', 'Notification',
AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', '$timeout', 'Authentication', 'PasswordValidator', 'Notification',
'MeanTorrentConfig', 'getStorageLangService', '$rootScope', '$stateParams', 'InvitationsService'];
function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator, Notification, MeanTorrentConfig,
function AuthenticationController($scope, $state, UsersService, $location, $window, $timeout, Authentication, PasswordValidator, Notification, MeanTorrentConfig,
getStorageLangService, $rootScope, $stateParams, InvitationsService) {
var vm = this;
vm.lang = getStorageLangService.getLang();
vm.signConfig = MeanTorrentConfig.meanTorrentConfig.sign;
vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app;
vm.authentication = Authentication;
vm.getPopoverMsg = PasswordValidator.getPopoverMsg;
vm.signup = signup;
@@ -22,14 +23,19 @@
vm.usernameRegex = /^(?=[\w.-]+$)(?!.*[._-]{2})(?!\.)(?!.*\.$).{3,34}$/;
vm.credentials = {};
vm.activeMethod = $state.params.method;
// Get an eventual error defined in the URL query string:
if ($location.search().err) {
Notification.error({message: $location.search().err});
}
// If user is signed in then redirect back home
if (vm.authentication.user) {
$location.path('/');
/**
* account active successfully, redirect to home after 2 seconds
*/
if (vm.activeMethod === 'successfully') {
$timeout(function () {
$state.go('home');
}, 3000);
}
/**
@@ -69,6 +75,16 @@
UsersService.userSignup(vm.credentials)
.then(onUserSignupSuccess)
.catch(onUserSignupError);
function onUserSignupSuccess(response) {
vm.waitToActive = true;
vm.waitToActiveTranslate = response.message;
}
function onUserSignupError(response) {
Notification.error({message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signup Error!', delay: 6000});
}
}
/**
@@ -87,6 +103,20 @@
UsersService.userSignin(vm.credentials)
.then(onUserSigninSuccess)
.catch(onUserSigninError);
function onUserSigninSuccess(response) {
// If successful we assign the response to the global user model
vm.authentication.user = response;
$rootScope.$broadcast('auth-user-changed');
$rootScope.$broadcast('user-invitations-changed');
Notification.info({message: 'Welcome ' + response.firstName});
// And redirect to the previous or home page
$state.go($state.previous.state.name || 'home', $state.previous.params);
}
function onUserSigninError(response) {
Notification.error({message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signin Error!', delay: 6000});
}
}
// OAuth provider request
@@ -103,51 +133,6 @@
$window.location.href = url;
}
// Authentication Callbacks
/**
* onUserSignupSuccess
* @param response
*/
function onUserSignupSuccess(response) {
// If successful we assign the response to the global user model
vm.authentication.user = response;
$rootScope.$broadcast('auth-user-changed');
$rootScope.$broadcast('user-invitations-changed');
Notification.success({message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!'});
// And redirect to the previous or home page
$state.go($state.previous.state.name || 'home', $state.previous.params);
}
/**
* onUserSignupError
* @param response
*/
function onUserSignupError(response) {
Notification.error({message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signup Error!', delay: 6000});
}
/**
* onUserSigninSuccess
* @param response
*/
function onUserSigninSuccess(response) {
// If successful we assign the response to the global user model
vm.authentication.user = response;
$rootScope.$broadcast('auth-user-changed');
$rootScope.$broadcast('user-invitations-changed');
Notification.info({message: 'Welcome ' + response.firstName});
// And redirect to the previous or home page
$state.go($state.previous.state.name || 'home', $state.previous.params);
}
/**
* onUserSigninError
* @param response
*/
function onUserSigninError(response) {
Notification.error({message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signin Error!', delay: 6000});
}
/**
* markLinkClick
* @param evt