pulseauthenticate
Version:
Common Authentication library for pulse angular apps
81 lines (79 loc) • 3.76 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
require("rxjs/add/operator/map");
var AuthenticationService = AuthenticationService_1 = (function () {
function AuthenticationService(http) {
this.http = http;
this.userObj = {};
}
AuthenticationService.prototype.login = function (username, password) {
var _this = this;
var authUrl = AuthenticationService_1.hostname + '/PulseServices/Authenticate.svc/Login';
if (AuthenticationService_1.istools == true) {
authUrl = AuthenticationService_1.hostname + '/PulseServices/Authenticate.@@@/Login';
}
return this.http.post(authUrl, { username: username, password: password })
.map(function (response) {
var result = response.json();
if (result.LoginResult && result.LoginResult.success) {
_this.userObj = JSON.stringify(result.LoginResult);
localStorage.setItem('currentUser', _this.userObj);
}
return result.LoginResult;
});
};
AuthenticationService.prototype.getAuthenticationObject = function () {
return JSON.parse(localStorage.getItem('currentUser'));
};
AuthenticationService.prototype.isAuthenticated = function () {
if (localStorage.getItem('currentUser')) {
return true;
}
else {
return false;
}
};
AuthenticationService.prototype.forgotPassword = function (email) {
var authUrl = AuthenticationService_1.hostname + '/PulseServices/Authenticate.svc/ForgotPassword';
if (AuthenticationService_1.istools == true) {
authUrl = AuthenticationService_1.hostname + '/PulseServices/Authenticate.@@@/ForgotPassword';
}
return this.http.post(authUrl, { email: email })
.map(function (response) {
var result = response.json();
if (result.ForgotPasswordResult && result.ForgotPasswordResult.success) {
}
return result.ForgotPasswordResult;
});
};
AuthenticationService.prototype.logout = function () {
localStorage.removeItem('currentUser');
};
return AuthenticationService;
}());
AuthenticationService.hostname = "http://localhost";
AuthenticationService.istools = false;
AuthenticationService = AuthenticationService_1 = __decorate([
core_1.Injectable(),
__metadata("design:paramtypes", [http_1.Http])
], AuthenticationService);
exports.AuthenticationService = AuthenticationService;
function ConfigureAuthenticationService(configuration) {
AuthenticationService.hostname = configuration.hostname;
if (configuration.istools)
AuthenticationService.istools = configuration.istools;
}
exports.ConfigureAuthenticationService = ConfigureAuthenticationService;
var AuthenticationService_1;
//# sourceMappingURL=authentication.service.js.map