Upgrade Login service.
This commit is contained in:
parent
57256e9ba7
commit
e2a4b0b7ec
@ -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
|
||||
@Injectable()
|
||||
export class LoginService {
|
||||
accessToken() {
|
||||
return sessionStorage.getItem('access_token');
|
||||
}
|
||||
}).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,
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user