consumerportal
Version:
mydna Custimised for you
70 lines (57 loc) • 1.83 kB
text/typescript
/// <reference path="../../includes.ts" />
module authenSrvc {
export interface IAuthenService {
setAuthentication(data: any): any;
getAuthentication(): any;
setOauth(data: any): any;
getOauth(): any;
setAuthenToLocalStorage(data: any): any;
getAuthenToLocalStorage(): any;
logOut(): any;
}
export class AuthenService implements IAuthenService {
AuthenticationObject: any;
OauthObject: any;
static $inject = [
'$location',
'$rootScope',
'appLocalStorage'
];
constructor(
private $location: angular.ILocationService,
private $rootScope: angular.IRootScopeService,
private storage: app.IAppStorage
){
let vm = this;
vm.AuthenticationObject = {};
}
setAuthentication(data) {
console.log('setAuthentication', data);
this.AuthenticationObject = data;
}
getAuthentication() {
return this.AuthenticationObject;
}
setOauth(data) {
this.OauthObject = data;
}
getOauth() {
return this.OauthObject;
}
setAuthenToLocalStorage(data) {
this.storage.setItem("Token", data);
}
getAuthenToLocalStorage() {
return this.storage.getItem("Token");
}
logOut(){
this.AuthenticationObject = null;
this.$rootScope.$broadcast('changeUser', null);
this.storage.removeItem('Token');
this.$location.path('/login');
}
}
angular
.module('authenSrvc', [])
.service('authenSrvc', AuthenService);
}