diff --git a/app/scripts/controllers/register.coffee b/app/scripts/controllers/register.coffee index 327e38b..a243883 100644 --- a/app/scripts/controllers/register.coffee +++ b/app/scripts/controllers/register.coffee @@ -22,30 +22,3 @@ angular.module('angularCmsApp').controller 'RegisterCtrl', ($scope, $location, $ $scope.register = (user)-> $log.info('register', user) - #Register the user - cmsAuthService.register(user).then( - (data)-> - #Login the user - cmsAuthService.authorize(user).then( - - $log.info(data) - - #Welcome the user - cmsNotify( '.message', 'info', 'Registered!', "You have registered as #{data.user.email}") - - #Set user session - session = - user: data.user - authorized: true - - #Set user cookie - cmsSessionService.setSession(session) - - #Change location - $location.path('/dashboard') - ) - , - (err) -> - $log.error(err) - cmsNotify( '.message', 'danger', 'Error!', err.data.message, 4000) - ) diff --git a/app/scripts/services/cmsauthservice.coffee b/app/scripts/services/cmsauthservice.coffee index 4cf8db2..8290b73 100644 --- a/app/scripts/services/cmsauthservice.coffee +++ b/app/scripts/services/cmsauthservice.coffee @@ -31,7 +31,13 @@ angular.module('angularCmsApp').service 'cmsAuthService', ($q, $http, $log, $roo register - I handle register a user. ### register: (user) -> - return $http.post(@endpoint + "/register", user) + $http.post(@endpoint + "/register", user).then( + (res)=> + @authorize(res.data) + , (err) -> + $log.error(err) + cmsNotify( '.message', 'danger', 'Error!', err.data.message, 4000) + ) ###* Logout method to clear the session. @@ -65,6 +71,6 @@ angular.module('angularCmsApp').service 'cmsAuthService', ($q, $http, $log, $roo #Change location $rootScope.App.location.path('/dashboard') , (err)-> - console.error(err) + $log.error(err) cmsNotify('.login-message', 'danger', 'Error!', err.data.message) )