Commit cf2b3498372e8b4b739d8723aa084b756fea661b
1 parent
9835dbe3ed
Exists in
master
login authenticate flow
Showing
3 changed files
with
33 additions
and
26 deletions
Show diff stats
app/views/login/login.controller.js
... | ... | @@ -10,23 +10,9 @@ |
10 | 10 | |
11 | 11 | var loginData = "username=" + $scope.user.username + "&password=" + $scope.user.password; |
12 | 12 | LoginService.loginUser(loginData).then(function(result) { |
13 | - console.log(result) | |
14 | - $state.go('index.dashboard'); | |
15 | - //$state.go('index.dashboard'); | |
16 | - // if(typeof result == 'object') { | |
17 | - // // LoginService.authenticate(); | |
18 | - // // LoginService.setAuth(true); | |
19 | - // // $rootScope.path = true; | |
20 | - // $state.go('index.dashboard'); | |
21 | - // // var reqPwdChng = localStorage.getItem("requiredChangePwd"); | |
22 | - // // if (reqPwdChng && reqPwdChng == "Y") { | |
23 | - // // $state.go('resetPassword'); | |
24 | - // // } else { | |
25 | - // // $state.go('app.upload'); | |
26 | - // // } | |
27 | - // } else { | |
28 | - // //toastr.info("Error in login. Please check login name and password"); | |
29 | - // } | |
13 | + LoginService.authenticate(); | |
14 | + LoginService.setAuth(true); | |
15 | + | |
30 | 16 | }) |
31 | 17 | |
32 | 18 | } | ... | ... |
app/views/login/login.html
... | ... | @@ -7,14 +7,14 @@ |
7 | 7 | <!-- <p>Perfectly designed and precisely prepared admin theme with over 50 pages with extra new web app views. |
8 | 8 | </p> --> |
9 | 9 | <p>Login in. To see it in action.</p> |
10 | - <form class="m-t" role="form" action="#"> | |
10 | + <form class="m-t" role="form"> | |
11 | 11 | <div class="form-group"> |
12 | - <input type="text" class="form-control" placeholder="Username" required="" ng-model="user.username"> | |
12 | + <input type="text" class="form-control" placeholder="Username" required="" ng-model="user.username" required> | |
13 | 13 | </div> |
14 | 14 | <div class="form-group"> |
15 | - <input type="password" class="form-control" placeholder="Password" required="" ng-model="user.password"> | |
15 | + <input type="password" class="form-control" placeholder="Password" required="" ng-model="user.password" required> | |
16 | 16 | </div> |
17 | - <button type="submit" class="btn btn-primary block full-width m-b" ng-click="userData()">Login</button> | |
17 | + <button class="btn btn-primary block full-width m-b" ng-click="userData()">Login</button> | |
18 | 18 | |
19 | 19 | <!-- <a ui-sref="forgot_password"><small>Forgot password?</small></a> |
20 | 20 | <p class="text-muted text-center"><small>Do not have an account?</small></p> | ... | ... |
app/views/login/login.service.js
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | 'use strict'; |
3 | 3 | |
4 | 4 | angular.module('acuefuel') |
5 | - .service('LoginService', ['$rootScope', '$q', '$http', 'BE', LoginService]) | |
5 | + .service('LoginService', ['$rootScope', '$q', '$http', 'BE', '$state', LoginService]) | |
6 | 6 | |
7 | - function LoginService($rootScope, $q, $http, BE) { | |
7 | + function LoginService($rootScope, $q, $http, BE, $state) { | |
8 | 8 | |
9 | 9 | this.loginUser = function(data) { |
10 | 10 | |
... | ... | @@ -25,12 +25,18 @@ |
25 | 25 | var deferred = $q.defer(); |
26 | 26 | $http({ |
27 | 27 | method : 'GET', |
28 | - url : BE.url+'user/authenticate', | |
28 | + url : BE.url+'/user/authenticate', | |
29 | 29 | headers : {'Content-Type': 'application/x-www-form-urlencoded'} |
30 | 30 | }).then(function (result){ |
31 | 31 | console.log(result) |
32 | - localStorage.setItem('userProfileId', result.data.userProfile.id); | |
33 | - localStorage.setItem('email', result.data.userProfile.email); | |
32 | + if(result.data.user.admin == true){ | |
33 | + window.localStorage.setItem('loginId', result.data.id); | |
34 | + window.localStorage.setItem('loginData', JSON.stringify(result.data.userProfile)); | |
35 | + $state.go('index.dashboard'); | |
36 | + }else{ | |
37 | + localStorage.clear(); | |
38 | + toastr.info("Unauthorized"); | |
39 | + } | |
34 | 40 | deferred.resolve(result.data); |
35 | 41 | },function (result){ |
36 | 42 | deferred.resolve(result.data); |
... | ... | @@ -41,6 +47,21 @@ |
41 | 47 | this.setAuth = function(data) { |
42 | 48 | localStorage.setItem('loginStatus', data); |
43 | 49 | } |
50 | + | |
51 | + this.logout = function(data) { | |
52 | + | |
53 | + var deferred = $q.defer(); | |
54 | + $http({ | |
55 | + method : 'POST', | |
56 | + url : BE.url +'/user/logout', | |
57 | + headers : {'Content-Type': 'application/x-www-form-urlencoded'}, | |
58 | + data : data | |
59 | + }) | |
60 | + .success(function(result) { | |
61 | + deferred.resolve(result.data); | |
62 | + }) | |
63 | + return deferred.promise; | |
64 | + } | |
44 | 65 | } |
45 | 66 | |
46 | 67 | })(); |
47 | 68 | \ No newline at end of file | ... | ... |