This repository was archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathLogin.js
52 lines (45 loc) · 1.42 KB
/
Login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Login Module
============
In here we're demonstrating opening a modal upon entering a state (instead of swapping a view).
$modal is part of ui.bootstrap
*/
// Tracks the previous location and allows you to redirect back to that location
var previousLocation;
var module = angular.module('App.Login', ['ui.router', 'ui.bootstrap']);
module.config(function($stateProvider) {
$stateProvider.state('login', {
parent: 'guest',
url: '/login',
resolve: {
user: (User) => new User(),
redirect: ($location) => {
return () => {
// Note we're returning a function to be called later, that has the redirect info pre-filled
// TODO: Change to state code
$location.path( previousLocation );
};
},
modal: ($modal) => $modal.open({
templateUrl: 'modules/Authentication/Login.html',
controller: 'Login',
})
},
onExit(modal) {
modal.close();
}
});
});
module.run(function($rootScope, $location) {
$rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
// TODO: Change to state code
previousLocation = $location.path();
});
});
module.controller('Login', ($scope, UserObject, Authentication, user, redirect) => {
$scope.user = user;
$scope.login = () => {
Authentication.login($scope.user, $scope.rememberMe)
.then( redirect, (response) => $scope.error = response);
};
});