Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ()
- {
- 'use strict';
- angular.module('app.core')
- .factory('AuthService', AuthService);
- /** @ngInject */
- function AuthService($http, $state, store, token, API, $q) {
- var session;
- return {
- login: login,
- logout: logout,
- isLoggedIn: isLoggedIn,
- getUserData: getUserData,
- loadSessionData: loadSessionData,
- getSessionData: getSessionData,
- setSessionData: setSessionData,
- destroySessionData: destroySessionData
- }
- /** @ngInject */
- function login(form){
- $http({
- url: API.URL+'auth/login',
- skipAuthorization: true,
- method: 'POST',
- data: {
- email: form.email,
- password: form.password
- }
- })
- .success(function(response)
- {
- store.set(token.auth, response.token);
- $state.go('app.dashboard');
- })
- .error(function(err){
- console.log(err);
- });
- }
- /** @ngInject */
- function logout() {
- if (store.get(token.auth)) {
- store.remove(token.auth);
- }
- destroySessionData();
- $state.go('app.pages_auth_login');
- };
- /** @ngInject */
- function isLoggedIn(user){
- return true;
- }
- /** @ngInject */
- function loadSessionData() {
- $http({
- url: API.URL+'auth/session-data',
- method: 'GET'
- })
- .success(function(response)
- {
- setSessionData(response);
- })
- .error(function(err){
- console.log(err);
- });
- };
- /** @ngInject */
- function destroySessionData() {
- setSessionData(null);
- }
- /** @ngInject */
- function isLoggedIn(user){
- return true;
- };
- /** @ngInject */
- function getUserData(){
- if (session) {
- return session.user;
- }
- return null;
- }
- /** @ngInject */
- function getSessionData() {
- return session;
- };
- /** @ngInject */
- function setSessionData(data){
- session = data;
- };
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement