|
8 | 8 | * @requires $location |
9 | 9 | * Contrller for Login Page |
10 | 10 | **/ |
11 | | -angular.module ('com.module.users') |
12 | | - .controller ('LoginCtrl', function ($scope, $routeParams, $location, toasty, User, AppAuth, gettextCatalog) { |
13 | | - |
14 | | - var TWO_WEEKS = 1000 * 60 * 60 * 24 * 7 * 2; |
15 | | - |
16 | | - $scope.credentials = { |
17 | | - email: 'admin@admin.com', |
18 | | - password: 'admin', |
19 | | - ttl: TWO_WEEKS, |
20 | | - rememberMe: true |
21 | | - }; |
22 | | - |
23 | | - $scope.schema = [ |
24 | | - { |
25 | | - label: '', |
26 | | - property: 'email', |
27 | | - placeholder: 'email', |
28 | | - type: 'email', |
29 | | - attr: {required: true, ngMinlength: 4}, |
30 | | - msgs: { |
31 | | - required: 'You need an email address', |
32 | | - email: 'Email address needs to be valid', |
33 | | - valid: 'Nice email address!' |
34 | | - } |
35 | | - }, |
36 | | - { |
37 | | - label: '', |
38 | | - property: 'password', |
39 | | - placehodler: gettextCatalog.getString ('Password'), |
40 | | - type: 'password', |
41 | | - attr: {required: true} |
42 | | - }, |
43 | | - { |
44 | | - property: 'rememberMe', |
45 | | - label: gettextCatalog.getString ('Stay signed in'), |
46 | | - type: 'checkbox' |
47 | | - } |
48 | | - ]; |
49 | | - |
50 | | - $scope.options = { |
51 | | - validation: { |
52 | | - enabled: true, |
53 | | - showMessages: false |
54 | | - }, |
55 | | - layout: { |
56 | | - type: 'basic', |
57 | | - labelSize: 3, |
58 | | - inputSize: 9 |
59 | | - } |
60 | | - }; |
61 | | - |
62 | | - $scope.loginGoogle = function () { |
63 | | - window.location = '/auth/google'; |
64 | | - }; |
65 | | - |
66 | | - $scope.loginFacebook = function () { |
67 | | - window.location = '/auth/facebook'; |
68 | | - }; |
69 | | - |
70 | | - $scope.login = function () { |
71 | | - |
72 | | - |
73 | | - $scope.loginResult = User.login ({ |
74 | | - include: 'user', |
75 | | - rememberMe: $scope.credentials.rememberMe |
76 | | - }, $scope.credentials, |
77 | | - function (user) { |
78 | | - |
79 | | - console.log (user.id); // => acess token |
80 | | - console.log (user.ttl); // => 1209600 time to live |
81 | | - console.log (user.created); // => 2013-12-20T21:10:20.377Z |
82 | | - console.log (user.userId); // => 1 |
83 | | - |
84 | | - var next = $location.nextAfterLogin || '/'; |
85 | | - $location.nextAfterLogin = null; |
86 | | - AppAuth.currentUser = $scope.loginResult.user; |
87 | | - toasty.pop.success ({ |
88 | | - title: gettextCatalog.getString ('Logged in'), |
89 | | - msg: gettextCatalog.getString ('You are logged in!'), |
90 | | - sound: false |
91 | | - }); |
92 | | - if (next === '/login') { |
93 | | - next = '/'; |
| 11 | +angular.module('com.module.users') |
| 12 | + .controller('LoginCtrl', function ($scope, $routeParams, $location, toasty, User, AppAuth, AuthProvider, gettextCatalog) { |
| 13 | + |
| 14 | + var TWO_WEEKS = 1000 * 60 * 60 * 24 * 7 * 2; |
| 15 | + |
| 16 | + $scope.credentials = { |
| 17 | + email: 'admin@admin.com', |
| 18 | + password: 'admin', |
| 19 | + ttl: TWO_WEEKS, |
| 20 | + rememberMe: true |
| 21 | + }; |
| 22 | + |
| 23 | + $scope.schema = [ |
| 24 | + { |
| 25 | + label: '', |
| 26 | + property: 'email', |
| 27 | + placeholder: 'email', |
| 28 | + type: 'email', |
| 29 | + attr: {required: true, ngMinlength: 4}, |
| 30 | + msgs: { |
| 31 | + required: 'You need an email address', |
| 32 | + email: 'Email address needs to be valid', |
| 33 | + valid: 'Nice email address!' |
94 | 34 | } |
95 | | - $location.path (next); |
| 35 | + }, |
| 36 | + { |
| 37 | + label: '', |
| 38 | + property: 'password', |
| 39 | + placehodler: gettextCatalog.getString('Password'), |
| 40 | + type: 'password', |
| 41 | + attr: {required: true} |
| 42 | + }, |
| 43 | + { |
| 44 | + property: 'rememberMe', |
| 45 | + label: gettextCatalog.getString('Stay signed in'), |
| 46 | + type: 'checkbox' |
| 47 | + } |
| 48 | + ]; |
96 | 49 |
|
| 50 | + $scope.options = { |
| 51 | + validation: { |
| 52 | + enabled: true, |
| 53 | + showMessages: false |
97 | 54 | }, |
98 | | - function (res) { |
99 | | - $scope.loginError = res.data.error; |
100 | | - }); |
| 55 | + layout: { |
| 56 | + type: 'basic', |
| 57 | + labelSize: 3, |
| 58 | + inputSize: 9 |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + $scope.socialLogin = function (provider) { |
| 63 | + window.location = provider.authPath; |
| 64 | + }; |
| 65 | + |
| 66 | + AuthProvider.count(function (result) { |
| 67 | + if (result.count > 0) { |
| 68 | + AuthProvider.find(function (result) { |
| 69 | + $scope.authProviders = result; |
| 70 | + }); |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | + $scope.login = function () { |
| 75 | + |
| 76 | + |
| 77 | + $scope.loginResult = User.login({ |
| 78 | + include: 'user', |
| 79 | + rememberMe: $scope.credentials.rememberMe |
| 80 | + }, $scope.credentials, |
| 81 | + function (user) { |
| 82 | + |
| 83 | + console.log(user.id); // => acess token |
| 84 | + console.log(user.ttl); // => 1209600 time to live |
| 85 | + console.log(user.created); // => 2013-12-20T21:10:20.377Z |
| 86 | + console.log(user.userId); // => 1 |
| 87 | + |
| 88 | + var next = $location.nextAfterLogin || '/'; |
| 89 | + $location.nextAfterLogin = null; |
| 90 | + AppAuth.currentUser = $scope.loginResult.user; |
| 91 | + toasty.pop.success({ |
| 92 | + title: gettextCatalog.getString('Logged in'), |
| 93 | + msg: gettextCatalog.getString('You are logged in!'), |
| 94 | + sound: false |
| 95 | + }); |
| 96 | + if (next === '/login') { |
| 97 | + next = '/'; |
| 98 | + } |
| 99 | + $location.path(next); |
| 100 | + |
| 101 | + }, |
| 102 | + function (res) { |
| 103 | + $scope.loginError = res.data.error; |
| 104 | + }); |
101 | 105 |
|
102 | 106 |
|
103 | | - }; |
| 107 | + }; |
104 | 108 |
|
105 | 109 |
|
106 | | -}); |
| 110 | + }); |
0 commit comments