2015-08-31 17:42:21 +02:00
|
|
|
angular.module('ponyfm').factory('auth', [
|
2015-10-25 03:35:37 +01:00
|
|
|
'$rootScope'
|
|
|
|
($rootScope) ->
|
|
|
|
data: {isLogged: window.pfm.auth.isLogged, user: window.pfm.auth.user}
|
|
|
|
login: (email, password, remember) ->
|
|
|
|
def = new $.Deferred()
|
|
|
|
$.post('/api/web/auth/login', {email: email, password: password, remember: remember, _token: pfm.token})
|
|
|
|
.done ->
|
|
|
|
$rootScope.$apply -> def.resolve()
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
.fail (res) ->
|
|
|
|
$rootScope.$apply -> def.reject res.responseJSON.messages
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
def.promise()
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
logout: -> $.post('/api/web/auth/logout', {_token: pfm.token})
|
2015-08-31 17:42:21 +02:00
|
|
|
])
|
|
|
|
|