Skip to content

Instantly share code, notes, and snippets.

@felisio
Created June 20, 2017 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felisio/3457eebee4d5ca51868bec33219b0dce to your computer and use it in GitHub Desktop.
Save felisio/3457eebee4d5ca51868bec33219b0dce to your computer and use it in GitHub Desktop.
esqueleto do service para angular 1
/*
* servicos para o site
*/
var $service = angular.module('app.services', []);
//-----------processo de Autenticação do usuario ----------------------------------//
//Factory para autenticação
$service.factory('AuthService', function ($rootScope, $http, Session) {
return {
login: function (user) {
//atraves do $HTTP - chamar metodo de login para os parametros
// se retornar com sucesso armazenar usuario no serviço Session que esta abaixo
}
};
});
// Service para guardar a sessão do usuario
$service.service('Session', function ($rootScope, $browser) {
this.create = function (sessionId, userId, userRole, user) {
this.id = sessionId;
this.userId = userId;
this.userRole = userRole;
this.user = user;
//TODO: falta implementar o armazenamento em LocalStorage
};
this.destroy = function () {
this.id = null;
this.userId = null;
this.userRole = null;
this.user = null;
};
return this;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment