3
3
4
4
var mainAppControllers = angular . module ( 'mainAppControllers' , [ ] ) ;
5
5
6
- mainAppControllers . controller ( 'NavCtrl' , [ '$scope' , '$http' , '$window' , '$ location', 'localStorageService' , 'AuthenticationService' ,
7
- function ( $scope , $http , $window , $ location, localStorageService , AuthenticationService ) {
6
+ mainAppControllers . controller ( 'NavCtrl' , [ '$scope' , '$http' , '$location' , 'localStorageService' , 'AuthenticationService' ,
7
+ function ( $scope , $http , $location , localStorageService , AuthenticationService ) {
8
8
9
9
10
10
$scope . isAuthenticated = AuthenticationService . isLogged ( )
@@ -17,16 +17,17 @@ mainAppControllers.controller('NavCtrl', ['$scope', '$http','$window','$location
17
17
}
18
18
] ) ;
19
19
20
- mainAppControllers . controller ( 'LoginCtrl' , [ '$scope' , '$http' , '$window' , '$location' , "cryptoJSService" , 'localStorageService' ,
21
- function ( $scope , $http , $window , $location , cryptoJSService , localStorageService ) {
22
-
23
- console . log ( cryptoJSService . cryptoJS ) ;
20
+ mainAppControllers . controller ( 'LoginCtrl' , [ '$scope' , '$http' , '$location' , "cryptoJSService" , 'localStorageService' ,
21
+ function ( $scope , $http , $location , CryptoJS , localStorageService ) {
24
22
25
23
$scope . failed_login = "" ;
26
24
27
25
$scope . submit = function ( )
28
26
{
29
- var user = { "username" : $scope . username , "password" : $scope . password } ;
27
+ var salt = $scope . username ;
28
+ var enc_password = CryptoJS . PBKDF2 ( $scope . password , salt , { keySize : 256 / 32 } ) ;
29
+
30
+ var user = { "username" : $scope . username , "password" : enc_password . toString ( ) } ;
30
31
31
32
if ( $scope . username !== undefined || $scope . password !== undefined ) {
32
33
$http ( { method : 'POST' , url : '/api/login' , data :user } ) .
@@ -37,8 +38,11 @@ mainAppControllers.controller('LoginCtrl', ['$scope', '$http','$window','$locati
37
38
38
39
} ) .
39
40
error ( function ( data , status , headers , config ) {
40
- console . log ( data ) ;
41
- noty ( { text : data , timeout : 2000 , type : 'error' } ) ;
41
+ if ( status === 401 ) {
42
+ noty ( { text : 'Wrong username and/or password!' , timeout : 2000 , type : 'error' } ) ;
43
+ } else {
44
+ noty ( { text : data , timeout : 2000 , type : 'error' } ) ;
45
+ }
42
46
} ) ;
43
47
} else {
44
48
noty ( { text : 'Username and password are mandatory!' , timeout : 2000 , type : 'error' } ) ;
@@ -50,26 +54,32 @@ mainAppControllers.controller('LoginCtrl', ['$scope', '$http','$window','$locati
50
54
] ) ;
51
55
52
56
53
- mainAppControllers . controller ( 'RegistrationCtrl' , [ '$scope' , '$http' , '$window' , '$location ',
54
- function ( $scope , $http ) {
57
+ mainAppControllers . controller ( 'RegistrationCtrl' , [ '$scope' , '$http' , 'cryptoJSService ' ,
58
+ function ( $scope , $http , CryptoJS ) {
55
59
56
60
$scope . signup = function ( )
57
61
{
58
- var user = { "username" : $scope . username , "password" : $scope . password , "check_password" : $scope . check_password } ;
62
+ var salt = $scope . username ;
63
+
64
+ var enc_password = CryptoJS . PBKDF2 ( $scope . password , salt , { keySize : 256 / 32 } ) ;
65
+ var enc_check_password = CryptoJS . PBKDF2 ( $scope . check_password , salt , { keySize : 256 / 32 } ) ;
66
+
67
+ var user = { "username" : $scope . username , "password" : enc_password . toString ( ) , "check_password" : enc_check_password . toString ( ) } ;
59
68
60
69
if ( $scope . username !== undefined || $scope . password !== undefined || $scope . check_password !== undefined ) {
61
70
62
71
if ( $scope . password !== $scope . check_password ) {
63
72
noty ( { text : 'password and check_password must be the same!' , timeout : 2000 , type : 'warning' } ) ;
64
73
} else {
65
- $http ( { method : 'POST' , url : '/signup' , data :user } ) .
74
+ $http ( { method : 'POST' , url : '/api/ signup' , data :user } ) .
66
75
success ( function ( data , status , headers , config ) {
67
- console . log ( data ) ;
68
76
noty ( { text : "Username is registered correctly!" , timeout : 2000 , type : 'success' } ) ;
77
+ $scope . username = null ;
78
+ $scope . password = null ;
79
+ $scope . check_password = null ;
69
80
} ) .
70
81
error ( function ( data , status , headers , config ) {
71
- console . log ( data ) ;
72
- noty ( { text : data , timeout : 2000 , type : 'error' } ) ;
82
+ noty ( { text : data . message , timeout : 2000 , type : 'error' } ) ;
73
83
} ) ;
74
84
}
75
85
@@ -84,8 +94,8 @@ mainAppControllers.controller('RegistrationCtrl', ['$scope', '$http','$window','
84
94
85
95
86
96
87
- mainAppControllers . controller ( 'HomeCtrl' , [ '$scope' , '$http' , '$window' , '$location' , 'localStorageService' , 'AuthenticationService' ,
88
- function ( $scope , $http , $window , $location , localStorageService , AuthenticationService ) {
97
+ mainAppControllers . controller ( 'HomeCtrl' , [ '$scope' , '$http' ,
98
+ function ( $scope , $http ) {
89
99
90
100
$http ( { method : 'GET' , url : '/api/things' } ) .
91
101
success ( function ( data , status , headers , config ) {
@@ -191,9 +201,8 @@ mainAppControllers.controller('HomeCtrl', ['$scope', '$http','$window','$locatio
191
201
] ) ;
192
202
193
203
194
- mainAppControllers . controller ( 'PersonCtrl' , [ '$scope' , '$http' , '$window' , '$location' , 'localStorageService' , 'AuthenticationService' ,
195
- function ( $scope , $http , $window , $location , localStorageService , AuthenticationService ) {
196
-
204
+ mainAppControllers . controller ( 'PersonCtrl' , [ '$scope' , '$http' ,
205
+ function ( $scope , $http ) {
197
206
198
207
$scope . person = null ;
199
208
@@ -218,9 +227,8 @@ mainAppControllers.controller('PersonCtrl', ['$scope', '$http','$window','$locat
218
227
219
228
220
229
221
- mainAppControllers . controller ( 'ThingCtrl' , [ '$scope' , '$http' , '$window' , '$location' , 'localStorageService' , 'AuthenticationService' ,
222
- function ( $scope , $http , $window , $location , localStorageService , AuthenticationService ) {
223
-
230
+ mainAppControllers . controller ( 'ThingCtrl' , [ '$scope' , '$http' ,
231
+ function ( $scope , $http ) {
224
232
225
233
$scope . thing = null ;
226
234
0 commit comments