diff --git a/src/login/login.service.ts b/src/login/login.service.ts index 8140b79..14e6994 100644 --- a/src/login/login.service.ts +++ b/src/login/login.service.ts @@ -1,45 +1,10 @@ -var base64 = require('base64util'); +import { Injectable } from '@angular/core'; -var loginTmpl = require('./login.tmpl.html'); +import * as base64 from 'base64util'; -module.exports = function($storage, $http, authService, $modal) { - var login = function(email, password) { - // Encode authentication data. - var authdata = base64.encode(email + ':' + password); - - return $http.post('/api/user/login', {}, { - ignoreAuthModule: true, - headers: { - 'authorization': 'Basic ' + authdata - } - }).then(function (result) { - $storage.session.set('refresh_token', result.data.refresh_token); - $storage.session.set('access_token', result.data.access_token); - - authService.loginConfirmed(); - }, function(result) { - loginModal(); - }); - }; - - var loginModal = function () { - $storage.session.clear(); - - $modal({ - templateUrl: loginTmpl, - controller: function($scope, $login) { - $scope.$login = function() { - $scope.$hide(); - $login($scope.email, $scope.password); - }; - }, - locals: { - $login: login, - } - }); - }; - - return { - 'loginModal': loginModal, - }; +@Injectable() +export class LoginService { + accessToken() { + return sessionStorage.getItem('access_token'); + } };