Skip to content

Instantly share code, notes, and snippets.

@CiscoKidxx
Created September 7, 2016 05:42
Show Gist options
  • Save CiscoKidxx/b8123e34843ca141b155b52b879fe2ff to your computer and use it in GitHub Desktop.
Save CiscoKidxx/b8123e34843ca141b155b52b879fe2ff to your computer and use it in GitHub Desktop.
AuthService.js
angular.module('app').factory('AuthService', function ($http, $auth, ResponseService, $localStorage, $q, appAuth, userData) {
var factory = {
admin: function (email, password) {
return $http.put('/api/admin/login', {
email: email,
password: password
})
.then(function onSuccess (res){
$localStorage.adminHash = res.data.admin;
return $auth.setToken(res.data.token);
})
.catch(function onError(res) {
ResponseService.error(res);
return $q.reject();
});
},
user: function (email, password) {
return $http.put('/api/user/login', {
email: email,
password: password
})
.then(function onSuccess (res){
$auth.setToken(res.data.token);
return res.data.user;
})
.catch(function onError(res) {
ResponseService.error(res);
return $q.reject();
});
},
signup: function (email, password, name, company, reCaptcha) {
console.log('Test');
return $http.put('/api/user/signupWithEmail', {
email : email,
password : password,
name : name,
company : company,
reCaptcha : reCaptcha
})
.then(function onSuccess (res){
$localStorage.userHash = res.data.user;
$auth.setToken(res.data.token);
})
.catch(function onError(res) {
ResponseService.error(res);
return $q.reject();
});
},
forgot: function (email, reCaptcha) {
return $http.put('/api/user/forgotPassword', {
email : email,
reCaptcha : reCaptcha
})
.then(function onSuccess (res){
return ResponseService.info(res);
})
.catch(function (res) {
ResponseService.error(res);
return $q.reject();
});
},
validateEmail: function (email) {
return $http.put('/api/user/validateEmail', {
email : email
})
.then(function onSuccess (res) {
return true;
})
.catch(function (res) {
return $q.reject();
});
},
};
return factory;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment