1- angular . module ( 'UserController' , [ ] ) . controller ( 'UserController' , [ '$scope' , '$rootScope' , 'User' , 'Auth' , '$localStorage' ,
2- function ( $scope , $rootScope , User , Auth , $localStorage ) {
31angular . module ( 'UserController' , [ ] ) . controller ( 'UserController' , [ '$scope' , '$rootScope' , 'User' , 'Auth' , '$localStorage' , '$location' ,
42 function ( $scope , $rootScope , User , Auth , $localStorage , $location ) {
53 $scope . login = function ( ) {
@@ -9,6 +7,7 @@ angular.module('UserController', []).controller('UserController', ['$scope', '$r
97 } ) ;
108 user . $login ( function ( user ) {
119 $localStorage . token = user . token ;
10+ $scope . getAuthenticatedUser ( user ) ;
1211 } , function ( err ) {
1312 console . log ( err ) ;
1413 } ) ;
@@ -23,14 +22,24 @@ angular.module('UserController', []).controller('UserController', ['$scope', '$r
2322 password : this . password ,
2423 email : this . email
2524 } ) ;
26- user . $save ( function ( res ) {
27- $location . path ( 'users/view/' + res . id ) ;
25+ user . $save ( function ( user ) {
26+ $localStorage . token = user . token ;
27+ $scope . getAuthenticatedUser ( user ) ;
28+ $location . path ( 'users/view/' + user . id ) ;
29+ } , function ( err ) {
30+ console . log ( err ) ;
31+ } ) ;
32+ } ;
2833
2934 $scope . findOne = function ( ) {
3035 var splitPath = $location . path ( ) . split ( '/' ) ;
3136 var userId = splitPath [ splitPath . length - 1 ] ;
3237 $scope . user = User . get ( { userId : userId } ) ;
3338 } ;
39+
40+ $scope . getByToken = function ( ) {
41+ return new User ( ) . $getByToken ( function ( res ) {
42+ console . log ( res ) ;
3443 } , function ( err ) {
3544 console . log ( err ) ;
3645 } ) ;
0 commit comments