scheduler-node-models 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/general/emailer.d.ts +1 -0
- package/general/emailer.js +31 -0
- package/general/general.d.ts +12 -0
- package/general/general.js +2 -0
- package/general/index.d.ts +5 -0
- package/general/index.js +21 -0
- package/general/logger.d.ts +10 -0
- package/general/logger.js +90 -0
- package/general/report.d.ts +25 -0
- package/general/report.js +76 -0
- package/general/viewstate.d.ts +5 -0
- package/general/viewstate.js +9 -0
- package/index.d.ts +0 -0
- package/index.js +1 -0
- package/metrics/images.d.ts +22 -0
- package/metrics/images.js +33 -0
- package/metrics/index.d.ts +5 -0
- package/metrics/index.js +21 -0
- package/metrics/mission.d.ts +47 -0
- package/metrics/mission.js +81 -0
- package/metrics/missionSensorOutage.d.ts +11 -0
- package/metrics/missionSensorOutage.js +14 -0
- package/metrics/missionsensor.d.ts +67 -0
- package/metrics/missionsensor.js +128 -0
- package/metrics/outage.d.ts +43 -0
- package/metrics/outage.js +55 -0
- package/metrics/systemdata/classifications.d.ts +18 -0
- package/metrics/systemdata/classifications.js +23 -0
- package/metrics/systemdata/communications.d.ts +21 -0
- package/metrics/systemdata/communications.js +40 -0
- package/metrics/systemdata/dcgs.d.ts +19 -0
- package/metrics/systemdata/dcgs.js +29 -0
- package/metrics/systemdata/exploitations.d.ts +18 -0
- package/metrics/systemdata/exploitations.js +23 -0
- package/metrics/systemdata/groundSystems.d.ts +86 -0
- package/metrics/systemdata/groundSystems.js +143 -0
- package/metrics/systemdata/index.d.ts +7 -0
- package/metrics/systemdata/index.js +23 -0
- package/metrics/systemdata/platform.d.ts +124 -0
- package/metrics/systemdata/platform.js +176 -0
- package/metrics/systemdata/systeminfo.d.ts +28 -0
- package/metrics/systemdata/systeminfo.js +64 -0
- package/package.json +4 -4
- package/scheduler/employees/assignment.d.ts +139 -0
- package/scheduler/employees/assignment.js +304 -0
- package/scheduler/employees/balance.d.ts +35 -0
- package/scheduler/employees/balance.js +39 -0
- package/scheduler/employees/companyinfo.d.ts +16 -0
- package/scheduler/employees/companyinfo.js +6 -0
- package/scheduler/employees/contact.d.ts +36 -0
- package/scheduler/employees/contact.js +40 -0
- package/scheduler/employees/employee.d.ts +427 -0
- package/scheduler/employees/employee.js +1887 -0
- package/scheduler/employees/employeename.d.ts +48 -0
- package/scheduler/employees/employeename.js +97 -0
- package/scheduler/employees/index.d.ts +14 -0
- package/scheduler/employees/index.js +30 -0
- package/scheduler/employees/labor.d.ts +31 -0
- package/scheduler/employees/labor.js +39 -0
- package/scheduler/employees/leave.d.ts +58 -0
- package/scheduler/employees/leave.js +73 -0
- package/scheduler/employees/leaverequest.d.ts +105 -0
- package/scheduler/employees/leaverequest.js +226 -0
- package/scheduler/employees/specialty.d.ts +35 -0
- package/scheduler/employees/specialty.js +40 -0
- package/scheduler/employees/variation.d.ts +80 -0
- package/scheduler/employees/variation.js +132 -0
- package/scheduler/employees/web.d.ts +6 -0
- package/scheduler/employees/web.js +2 -0
- package/scheduler/employees/work.d.ts +96 -0
- package/scheduler/employees/work.js +133 -0
- package/scheduler/employees/workday.d.ts +91 -0
- package/scheduler/employees/workday.js +170 -0
- package/scheduler/labor/index.d.ts +2 -0
- package/scheduler/labor/index.js +18 -0
- package/scheduler/labor/laborcode.d.ts +33 -0
- package/scheduler/labor/laborcode.js +55 -0
- package/scheduler/labor/workcode.d.ts +28 -0
- package/scheduler/labor/workcode.js +35 -0
- package/scheduler/sites/index.d.ts +1 -0
- package/scheduler/sites/index.js +17 -0
- package/scheduler/sites/reports/cofsReport.d.ts +41 -0
- package/scheduler/sites/reports/cofsReport.js +104 -0
- package/scheduler/sites/reports/forecast.d.ts +57 -0
- package/scheduler/sites/reports/forecast.js +205 -0
- package/scheduler/sites/reports/index.d.ts +4 -0
- package/scheduler/sites/reports/index.js +20 -0
- package/scheduler/sites/reports/period.d.ts +11 -0
- package/scheduler/sites/reports/period.js +27 -0
- package/scheduler/sites/reports/section.d.ts +63 -0
- package/scheduler/sites/reports/section.js +186 -0
- package/scheduler/sites/site.d.ts +39 -0
- package/scheduler/sites/site.js +68 -0
- package/scheduler/sites/workcenters/index.d.ts +3 -0
- package/scheduler/sites/workcenters/index.js +19 -0
- package/scheduler/sites/workcenters/position.d.ts +27 -0
- package/scheduler/sites/workcenters/position.js +36 -0
- package/scheduler/sites/workcenters/shift.d.ts +32 -0
- package/scheduler/sites/workcenters/shift.js +47 -0
- package/scheduler/sites/workcenters/workcenter.d.ts +43 -0
- package/scheduler/sites/workcenters/workcenter.js +123 -0
- package/scheduler/teams/company/company.d.ts +99 -0
- package/scheduler/teams/company/company.js +256 -0
- package/scheduler/teams/company/holiday.d.ts +61 -0
- package/scheduler/teams/company/holiday.js +116 -0
- package/scheduler/teams/company/index.d.ts +3 -0
- package/scheduler/teams/company/index.js +19 -0
- package/scheduler/teams/company/modperiod.d.ts +21 -0
- package/scheduler/teams/company/modperiod.js +24 -0
- package/scheduler/teams/contact.d.ts +18 -0
- package/scheduler/teams/contact.js +23 -0
- package/scheduler/teams/index.d.ts +3 -0
- package/scheduler/teams/index.js +19 -0
- package/scheduler/teams/specialty.d.ts +18 -0
- package/scheduler/teams/specialty.js +23 -0
- package/scheduler/teams/team.d.ts +95 -0
- package/scheduler/teams/team.js +351 -0
- package/users/index.d.ts +2 -0
- package/users/index.js +18 -0
- package/users/question.d.ts +47 -0
- package/users/question.js +68 -0
- package/users/user.d.ts +150 -0
- package/users/user.js +304 -0
- package/users/web.d.ts +49 -0
- package/users/web.js +2 -0
package/users/user.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ISecurityQuestion, SecurityQuestion } from './question';
|
|
2
|
+
/**
|
|
3
|
+
* The user class and interface.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* This interface ensures all the required fields are present to represent the user and
|
|
7
|
+
* its class object.
|
|
8
|
+
*/
|
|
9
|
+
export interface IUser {
|
|
10
|
+
_id?: string;
|
|
11
|
+
id: string;
|
|
12
|
+
emailAddress: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
passwordExpires: Date;
|
|
15
|
+
badAttempts: number;
|
|
16
|
+
firstName: string;
|
|
17
|
+
middleName?: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
workgroups: string[];
|
|
20
|
+
resettoken?: string;
|
|
21
|
+
resettokenexp?: Date;
|
|
22
|
+
additionalEmails?: string[];
|
|
23
|
+
questions?: ISecurityQuestion[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This class represents a user and all the actions available to the user object.
|
|
27
|
+
* The main class members are:
|
|
28
|
+
* id (primary key),
|
|
29
|
+
* email address (used in authentication and email messages for reset),
|
|
30
|
+
* password (authentication), password expires (old use -
|
|
31
|
+
* to determine the when the password would expire, but new use is to track when
|
|
32
|
+
* created to allow for the warning to change after 90 days and requiring after 1 year),
|
|
33
|
+
* badAttempts (count of number of mismatch of password since last known good
|
|
34
|
+
* authentication),
|
|
35
|
+
* first, middle and last names (name - middle is optional),
|
|
36
|
+
* workgroups (string array to provide identificationn of permission within an
|
|
37
|
+
* application),
|
|
38
|
+
* resetToken and resettokenexp (a storage location or a reset token used in forgot
|
|
39
|
+
* password change, plus token expiration date/time the reset token expires)
|
|
40
|
+
*/
|
|
41
|
+
export declare class User implements IUser {
|
|
42
|
+
id: string;
|
|
43
|
+
emailAddress: string;
|
|
44
|
+
password?: string;
|
|
45
|
+
passwordExpires: Date;
|
|
46
|
+
badAttempts: number;
|
|
47
|
+
firstName: string;
|
|
48
|
+
middleName?: string;
|
|
49
|
+
lastName: string;
|
|
50
|
+
workgroups: string[];
|
|
51
|
+
resettoken?: string;
|
|
52
|
+
resettokenexp?: Date;
|
|
53
|
+
additionalEmails: string[];
|
|
54
|
+
questions: SecurityQuestion[];
|
|
55
|
+
constructor(user?: IUser);
|
|
56
|
+
/**
|
|
57
|
+
* This function is used to sort this class' objects into an ordered list. The order
|
|
58
|
+
* is determined by last, first and middle names
|
|
59
|
+
* @param other Another user object used during comparison
|
|
60
|
+
* @returns a numeric value to show the object is before or after the other object.
|
|
61
|
+
* -1 is for before and 1 is for after.
|
|
62
|
+
*/
|
|
63
|
+
compareTo(other?: User): number;
|
|
64
|
+
/**
|
|
65
|
+
* This function provides a copy of the user object to the web client. We don't want to
|
|
66
|
+
* pass the password, reset token or expiration date/time.
|
|
67
|
+
* @returns A new User interface for passing
|
|
68
|
+
*/
|
|
69
|
+
cloneForOutput(): IUser;
|
|
70
|
+
/**
|
|
71
|
+
* This function will reset the password, bad attemtps and expiration date. The new
|
|
72
|
+
* password will be excrypted for storage.
|
|
73
|
+
* @param passwd The string value for the new password
|
|
74
|
+
*/
|
|
75
|
+
setPassword(passwd: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* This function will be used in authentication to verify if the password provided is
|
|
78
|
+
* equivelent to the stored one.
|
|
79
|
+
* @param pwd The string value to compare against the encrypted password.
|
|
80
|
+
* @throws An error if the account is locked or there is a mismatch with the password.
|
|
81
|
+
*/
|
|
82
|
+
checkPassword(pwd: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* This function will provide a random 16 character password.
|
|
85
|
+
* @returns A string value representing the new random password.
|
|
86
|
+
*/
|
|
87
|
+
createRandomPassword(): string;
|
|
88
|
+
/**
|
|
89
|
+
* This function will unlock the user account to allow for access.
|
|
90
|
+
*/
|
|
91
|
+
unlock(): void;
|
|
92
|
+
/**
|
|
93
|
+
* This function will provide the user's name in the form first middle and last.
|
|
94
|
+
* @returns A string value for the user's name.
|
|
95
|
+
*/
|
|
96
|
+
getFullName(): string;
|
|
97
|
+
/**
|
|
98
|
+
* This function will provide the user's name in the form first last.
|
|
99
|
+
* @returns A string value for the user's name.
|
|
100
|
+
*/
|
|
101
|
+
getFirstLast(): string;
|
|
102
|
+
/**
|
|
103
|
+
* This function will provide the user's name in the form last, first.
|
|
104
|
+
* @returns A string value for the user's name.
|
|
105
|
+
*/
|
|
106
|
+
getLastFirst(): string;
|
|
107
|
+
/**
|
|
108
|
+
* This function will create a random string used as a token to reset the user's
|
|
109
|
+
* password when the user had forgotten it. It will be emailed to the user's
|
|
110
|
+
* email addresses. The token will be good for 1 hour, so an expiration date/time
|
|
111
|
+
* is also set.
|
|
112
|
+
* @returns A string value for the reset token.
|
|
113
|
+
*/
|
|
114
|
+
createResetToken(): string;
|
|
115
|
+
/**
|
|
116
|
+
* This function will verify the provided string token in comparison to that recorded
|
|
117
|
+
* in the user's record. The process also checks to ensure the token isn't expired.
|
|
118
|
+
* @param token A string value for the comparison token.
|
|
119
|
+
* @returns A boolean value to indicate if the token matches and not expired.
|
|
120
|
+
*/
|
|
121
|
+
checkResetToken(token: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* This function will add a new email address, if it isn't already in the list
|
|
124
|
+
* @param email The string value for the email to add.
|
|
125
|
+
*/
|
|
126
|
+
addAdditionalEmail(email: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* This function will remove an email address from the user's additional email
|
|
129
|
+
* address list.
|
|
130
|
+
* @param email The string value for the email to remove.
|
|
131
|
+
*/
|
|
132
|
+
deleteAdditionalEmail(email: string): void;
|
|
133
|
+
/**
|
|
134
|
+
* This function will update a security question question or answer
|
|
135
|
+
* based on the identifier, field and value provided.
|
|
136
|
+
* @param id A numeric value for the identifier of the question.
|
|
137
|
+
* @param field A string value for the field (question or answer) to be
|
|
138
|
+
* updated.
|
|
139
|
+
* @param value A string value for the updated value for the field.
|
|
140
|
+
*/
|
|
141
|
+
updateSecurityQuestion(id: number, field: string, value: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* This function is used to check the response for a security question
|
|
144
|
+
* answer to the stored value.
|
|
145
|
+
* @param id A numeric value for the question to check against.
|
|
146
|
+
* @param value A string value for the answer to the question.
|
|
147
|
+
* @returns A boolean value for whether the answers match.
|
|
148
|
+
*/
|
|
149
|
+
checkSecurityQuestion(id: number, value: string): boolean;
|
|
150
|
+
}
|
package/users/user.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
const bcrypt_ts_1 = require("bcrypt-ts");
|
|
5
|
+
const question_1 = require("./question");
|
|
6
|
+
/**
|
|
7
|
+
* This class represents a user and all the actions available to the user object.
|
|
8
|
+
* The main class members are:
|
|
9
|
+
* id (primary key),
|
|
10
|
+
* email address (used in authentication and email messages for reset),
|
|
11
|
+
* password (authentication), password expires (old use -
|
|
12
|
+
* to determine the when the password would expire, but new use is to track when
|
|
13
|
+
* created to allow for the warning to change after 90 days and requiring after 1 year),
|
|
14
|
+
* badAttempts (count of number of mismatch of password since last known good
|
|
15
|
+
* authentication),
|
|
16
|
+
* first, middle and last names (name - middle is optional),
|
|
17
|
+
* workgroups (string array to provide identificationn of permission within an
|
|
18
|
+
* application),
|
|
19
|
+
* resetToken and resettokenexp (a storage location or a reset token used in forgot
|
|
20
|
+
* password change, plus token expiration date/time the reset token expires)
|
|
21
|
+
*/
|
|
22
|
+
class User {
|
|
23
|
+
id;
|
|
24
|
+
emailAddress;
|
|
25
|
+
password;
|
|
26
|
+
passwordExpires;
|
|
27
|
+
badAttempts;
|
|
28
|
+
firstName;
|
|
29
|
+
middleName;
|
|
30
|
+
lastName;
|
|
31
|
+
workgroups;
|
|
32
|
+
resettoken;
|
|
33
|
+
resettokenexp;
|
|
34
|
+
additionalEmails;
|
|
35
|
+
questions;
|
|
36
|
+
constructor(user) {
|
|
37
|
+
this.id = (user && user.id) ? user.id : '';
|
|
38
|
+
if (this.id === '') {
|
|
39
|
+
this.id = (user && user._id) ? user._id.toString() : '';
|
|
40
|
+
}
|
|
41
|
+
this.emailAddress = (user) ? user.emailAddress : '';
|
|
42
|
+
this.password = (user) ? user.password : undefined;
|
|
43
|
+
this.passwordExpires = (user) ? new Date(user.passwordExpires) : new Date();
|
|
44
|
+
this.badAttempts = (user) ? user.badAttempts : 0;
|
|
45
|
+
this.firstName = (user) ? user.firstName : '';
|
|
46
|
+
this.middleName = (user) ? user.middleName : undefined;
|
|
47
|
+
this.lastName = (user) ? user.lastName : '';
|
|
48
|
+
this.workgroups = [];
|
|
49
|
+
if (user) {
|
|
50
|
+
user.workgroups.forEach(wg => {
|
|
51
|
+
this.workgroups.push(wg);
|
|
52
|
+
});
|
|
53
|
+
user.workgroups.sort((a, b) => (a < b) ? -1 : 1);
|
|
54
|
+
}
|
|
55
|
+
this.resettoken = (user && user.resettoken) ? user.resettoken : undefined;
|
|
56
|
+
this.resettokenexp = (user && user.resettokenexp)
|
|
57
|
+
? new Date(user.resettokenexp) : undefined;
|
|
58
|
+
this.additionalEmails = [];
|
|
59
|
+
if (user && user.additionalEmails) {
|
|
60
|
+
user.additionalEmails.forEach(em => {
|
|
61
|
+
this.additionalEmails?.push(em);
|
|
62
|
+
});
|
|
63
|
+
this.additionalEmails.sort();
|
|
64
|
+
}
|
|
65
|
+
this.questions = [];
|
|
66
|
+
if (user && user.questions) {
|
|
67
|
+
user.questions.forEach(quest => {
|
|
68
|
+
this.questions.push(new question_1.SecurityQuestion(quest));
|
|
69
|
+
});
|
|
70
|
+
this.questions.sort((a, b) => a.compareTo(b));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
for (let i = 1; i < 4; i++) {
|
|
74
|
+
this.questions.push(new question_1.SecurityQuestion({
|
|
75
|
+
id: i, question: '', answer: ''
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* This function is used to sort this class' objects into an ordered list. The order
|
|
82
|
+
* is determined by last, first and middle names
|
|
83
|
+
* @param other Another user object used during comparison
|
|
84
|
+
* @returns a numeric value to show the object is before or after the other object.
|
|
85
|
+
* -1 is for before and 1 is for after.
|
|
86
|
+
*/
|
|
87
|
+
compareTo(other) {
|
|
88
|
+
if (other) {
|
|
89
|
+
if (other.lastName === this.lastName) {
|
|
90
|
+
if (other.firstName === this.firstName) {
|
|
91
|
+
if (this.middleName && other.middleName) {
|
|
92
|
+
return (this.middleName < other.middleName) ? -1 : 1;
|
|
93
|
+
}
|
|
94
|
+
else if (!this.middleName) {
|
|
95
|
+
return -1;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return (this.firstName < other.firstName) ? -1 : 1;
|
|
102
|
+
}
|
|
103
|
+
return (this.lastName < other.lastName) ? -1 : 1;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This function provides a copy of the user object to the web client. We don't want to
|
|
109
|
+
* pass the password, reset token or expiration date/time.
|
|
110
|
+
* @returns A new User interface for passing
|
|
111
|
+
*/
|
|
112
|
+
cloneForOutput() {
|
|
113
|
+
const output = new User(this);
|
|
114
|
+
output.password = undefined;
|
|
115
|
+
output.resettoken = undefined;
|
|
116
|
+
output.resettokenexp = undefined;
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* This function will reset the password, bad attemtps and expiration date. The new
|
|
121
|
+
* password will be excrypted for storage.
|
|
122
|
+
* @param passwd The string value for the new password
|
|
123
|
+
*/
|
|
124
|
+
setPassword(passwd) {
|
|
125
|
+
const salt = (0, bcrypt_ts_1.genSaltSync)(12);
|
|
126
|
+
const result = (0, bcrypt_ts_1.hashSync)(passwd, salt);
|
|
127
|
+
this.password = result;
|
|
128
|
+
this.passwordExpires = new Date();
|
|
129
|
+
this.badAttempts = 0;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* This function will be used in authentication to verify if the password provided is
|
|
133
|
+
* equivelent to the stored one.
|
|
134
|
+
* @param pwd The string value to compare against the encrypted password.
|
|
135
|
+
* @throws An error if the account is locked or there is a mismatch with the password.
|
|
136
|
+
*/
|
|
137
|
+
checkPassword(pwd) {
|
|
138
|
+
if (this.password && (0, bcrypt_ts_1.compareSync)(pwd, this.password)) {
|
|
139
|
+
if (this.badAttempts > 2) {
|
|
140
|
+
throw new Error("Account Locked");
|
|
141
|
+
}
|
|
142
|
+
this.badAttempts = 0;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.badAttempts++;
|
|
147
|
+
throw new Error("Account Mismatch");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* This function will provide a random 16 character password.
|
|
152
|
+
* @returns A string value representing the new random password.
|
|
153
|
+
*/
|
|
154
|
+
createRandomPassword() {
|
|
155
|
+
let result = '';
|
|
156
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
|
157
|
+
+ '0123456789';
|
|
158
|
+
const charLength = characters.length;
|
|
159
|
+
for (let i = 0; i < 16; i++) {
|
|
160
|
+
result += characters.charAt(Math.floor(Math.random() * charLength));
|
|
161
|
+
}
|
|
162
|
+
this.setPassword(result);
|
|
163
|
+
this.badAttempts = -1;
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* This function will unlock the user account to allow for access.
|
|
168
|
+
*/
|
|
169
|
+
unlock() {
|
|
170
|
+
this.badAttempts = 0;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* This function will provide the user's name in the form first middle and last.
|
|
174
|
+
* @returns A string value for the user's name.
|
|
175
|
+
*/
|
|
176
|
+
getFullName() {
|
|
177
|
+
if (!this.middleName) {
|
|
178
|
+
return this.firstName + ' ' + this.lastName;
|
|
179
|
+
}
|
|
180
|
+
return this.firstName + ' ' + this.middleName.substring(0, 1) + '. '
|
|
181
|
+
+ this.lastName;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* This function will provide the user's name in the form first last.
|
|
185
|
+
* @returns A string value for the user's name.
|
|
186
|
+
*/
|
|
187
|
+
getFirstLast() {
|
|
188
|
+
return this.firstName + ' ' + this.lastName;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* This function will provide the user's name in the form last, first.
|
|
192
|
+
* @returns A string value for the user's name.
|
|
193
|
+
*/
|
|
194
|
+
getLastFirst() {
|
|
195
|
+
return this.lastName + ', ' + this.firstName;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* This function will create a random string used as a token to reset the user's
|
|
199
|
+
* password when the user had forgotten it. It will be emailed to the user's
|
|
200
|
+
* email addresses. The token will be good for 1 hour, so an expiration date/time
|
|
201
|
+
* is also set.
|
|
202
|
+
* @returns A string value for the reset token.
|
|
203
|
+
*/
|
|
204
|
+
createResetToken() {
|
|
205
|
+
let result = '';
|
|
206
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
|
207
|
+
+ '0123456789';
|
|
208
|
+
const charLength = characters.length;
|
|
209
|
+
for (let i = 0; i < 16; i++) {
|
|
210
|
+
result += characters.charAt(Math.floor(Math.random() * charLength));
|
|
211
|
+
}
|
|
212
|
+
let now = new Date();
|
|
213
|
+
this.resettokenexp = new Date(now.getTime() + 3600000);
|
|
214
|
+
this.resettoken = result;
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* This function will verify the provided string token in comparison to that recorded
|
|
219
|
+
* in the user's record. The process also checks to ensure the token isn't expired.
|
|
220
|
+
* @param token A string value for the comparison token.
|
|
221
|
+
* @returns A boolean value to indicate if the token matches and not expired.
|
|
222
|
+
*/
|
|
223
|
+
checkResetToken(token) {
|
|
224
|
+
const now = new Date();
|
|
225
|
+
if (this.resettoken && this.resettokenexp) {
|
|
226
|
+
if (this.resettoken === token
|
|
227
|
+
&& now.getTime() < this.resettokenexp?.getTime()) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
if (this.resettokenexp.getTime() < now.getTime()) {
|
|
232
|
+
throw new Error("Reset Token Expired");
|
|
233
|
+
}
|
|
234
|
+
throw new Error("Reset Token Error");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* This function will add a new email address, if it isn't already in the list
|
|
241
|
+
* @param email The string value for the email to add.
|
|
242
|
+
*/
|
|
243
|
+
addAdditionalEmail(email) {
|
|
244
|
+
let found = false;
|
|
245
|
+
this.additionalEmails.forEach(em => {
|
|
246
|
+
if (em.toLowerCase() === email.toLowerCase()) {
|
|
247
|
+
found = true;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (!found) {
|
|
251
|
+
this.additionalEmails.push(email);
|
|
252
|
+
this.additionalEmails.sort();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* This function will remove an email address from the user's additional email
|
|
257
|
+
* address list.
|
|
258
|
+
* @param email The string value for the email to remove.
|
|
259
|
+
*/
|
|
260
|
+
deleteAdditionalEmail(email) {
|
|
261
|
+
let found = -1;
|
|
262
|
+
this.additionalEmails.forEach((em, e) => {
|
|
263
|
+
if (em.toLowerCase() === email.toLowerCase()) {
|
|
264
|
+
found = e;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
if (found >= 0) {
|
|
268
|
+
this.additionalEmails.splice(found, 1);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* This function will update a security question question or answer
|
|
273
|
+
* based on the identifier, field and value provided.
|
|
274
|
+
* @param id A numeric value for the identifier of the question.
|
|
275
|
+
* @param field A string value for the field (question or answer) to be
|
|
276
|
+
* updated.
|
|
277
|
+
* @param value A string value for the updated value for the field.
|
|
278
|
+
*/
|
|
279
|
+
updateSecurityQuestion(id, field, value) {
|
|
280
|
+
this.questions.forEach((quest, i) => {
|
|
281
|
+
if (quest.id === id) {
|
|
282
|
+
quest.update(field, value);
|
|
283
|
+
this.questions[i] = quest;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* This function is used to check the response for a security question
|
|
289
|
+
* answer to the stored value.
|
|
290
|
+
* @param id A numeric value for the question to check against.
|
|
291
|
+
* @param value A string value for the answer to the question.
|
|
292
|
+
* @returns A boolean value for whether the answers match.
|
|
293
|
+
*/
|
|
294
|
+
checkSecurityQuestion(id, value) {
|
|
295
|
+
let answer = false;
|
|
296
|
+
this.questions.forEach(quest => {
|
|
297
|
+
if (quest.id === id) {
|
|
298
|
+
answer = quest.compare(value);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
return answer;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.User = User;
|
package/users/web.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface will be used to authenticate with the application through the api
|
|
3
|
+
* server.
|
|
4
|
+
*/
|
|
5
|
+
export interface AuthenticationRequest {
|
|
6
|
+
emailAddress: string;
|
|
7
|
+
password: string;
|
|
8
|
+
application?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* This interface will be used between the client and the api server to request a new
|
|
12
|
+
* user. All fields are required.
|
|
13
|
+
*/
|
|
14
|
+
export interface AddUserRequest {
|
|
15
|
+
emailAddress: string;
|
|
16
|
+
firstName: string;
|
|
17
|
+
middleName?: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
password: string;
|
|
20
|
+
application: string;
|
|
21
|
+
permissions?: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This interface will be used to update a user with a call from the client to the
|
|
25
|
+
* api server. All fields would be required.
|
|
26
|
+
*/
|
|
27
|
+
export interface UpdateUserRequest {
|
|
28
|
+
id: string;
|
|
29
|
+
field: string;
|
|
30
|
+
value: string;
|
|
31
|
+
subid: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* This interface is used in the first part of the forgot password process where the
|
|
35
|
+
* requestor passes his/her email address used as the user identifier for the account.
|
|
36
|
+
*/
|
|
37
|
+
export interface ForgotPasswordRequest {
|
|
38
|
+
emailAddress: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This interface is used in the second part of the forgot password process, to provide
|
|
42
|
+
* the user's account email address, password and the passed reset token sent via email
|
|
43
|
+
* to the user's accounts.
|
|
44
|
+
*/
|
|
45
|
+
export interface PasswordResetRequest {
|
|
46
|
+
emailAddress: string;
|
|
47
|
+
password: string;
|
|
48
|
+
resettoken: string;
|
|
49
|
+
}
|
package/users/web.js
ADDED