changeuserpassword.component.js
4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
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 user_service_1 = require("./user.service");
//import { ChangeUserPasswordService } from '../ChangePassword/changeuserpassword.service';
var router_1 = require("@angular/router");
var forms_1 = require("@angular/forms");
var datamodel_1 = require("../UserEntity/datamodel");
var confirm_service_1 = require("../../Shared/Confirm/confirm.service");
require("rxjs/Rx");
require("rxjs/add/operator/map");
require("rxjs/add/operator/filter");
var ChangeUserPassword = /** @class */ (function () {
function ChangeUserPassword(changeUserPasswordService, router, fb, _confirmService) {
this.changeUserPasswordService = changeUserPasswordService;
this.router = router;
this.fb = fb;
this._confirmService = _confirmService;
}
ChangeUserPassword.prototype.ngOnInit = function () {
this.user = new datamodel_1.User();
this.alerts = '';
this.changeUserPasswordFrm = this.fb.group({
userId: [''],
loginId: ['', forms_1.Validators.required],
oldPassword: ['', forms_1.Validators.required],
newPassword: ['', [forms_1.Validators.required, forms_1.Validators.minLength(8)]],
confirmPassword: ['', forms_1.Validators.required]
});
this.GetUserById();
};
ChangeUserPassword.prototype.GetUserById = function () {
var _this = this;
this.changeUserPasswordService.GetUserById()
.subscribe(function (x) { _this.BindFormFields(x); }, function (error) { return _this.error = error; });
};
ChangeUserPassword.prototype.onFormSubmit = function () {
var _this = this;
this.alerts = '';
if (this.user.Password != this.changeUserPasswordFrm.value.oldPassword) {
this.alerts = '<span>Old password is invalid</span>';
}
if (this.user.Password == this.changeUserPasswordFrm.value.newPassword) {
this.alerts += '</br><span>New password and old password must be different</span>';
}
if (this.changeUserPasswordFrm.value.newPassword != this.changeUserPasswordFrm.value.confirmPassword) {
this.alerts += '</br><span>New password and confirm password must be same</span>';
}
if (this.alerts == '') {
var obj = this.changeUserPasswordFrm.value;
return this.changeUserPasswordService.ChangeUserPassword(obj)
.subscribe(function (n) { return (_this.AfterInsertData(n)); }, function (error) { return _this.error = error; });
}
};
ChangeUserPassword.prototype.AfterInsertData = function (data) {
if (data.Status == "false") {
this.alerts = "<span>Password change unsuccessfull</span>";
}
else {
this._confirmService.activate("Password changed successfully.", "alertMsg");
//this.alerts = "<span>Password changed successfully</span>";
}
};
ChangeUserPassword.prototype.BindFormFields = function (data) {
this.user = data[0];
this.changeUserPasswordFrm.controls['userId'].setValue(this.user.Id);
this.changeUserPasswordFrm.controls['loginId'].setValue(this.user.LoginId);
};
ChangeUserPassword.prototype.ResetFormFields = function () {
this.changeUserPasswordFrm.reset();
this.changeUserPasswordFrm.controls['loginId'].setValue(this.user.LoginId);
this.changeUserPasswordFrm.controls['oldPassword'].setValue('');
this.changeUserPasswordFrm.controls['newPassword'].setValue('');
this.changeUserPasswordFrm.controls['confirmPassword'].setValue('');
this.alerts = '';
};
ChangeUserPassword = __decorate([
core_1.Component({
templateUrl: './changeuserpassword.component.html'
}),
__metadata("design:paramtypes", [user_service_1.UserService, router_1.Router, forms_1.FormBuilder, confirm_service_1.ConfirmService])
], ChangeUserPassword);
return ChangeUserPassword;
}());
exports.ChangeUserPassword = ChangeUserPassword;
//# sourceMappingURL=changeuserpassword.component.js.map