Skip to content

Commit

Permalink
updated regsiter service
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Dec 9, 2014
1 parent 44ad469 commit 42082a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
27 changes: 0 additions & 27 deletions app/scripts/controllers/register.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
10 changes: 8 additions & 2 deletions app/scripts/services/cmsauthservice.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
)

0 comments on commit 42082a5

Please sign in to comment.