-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.js
More file actions
81 lines (68 loc) · 2.06 KB
/
User.js
File metadata and controls
81 lines (68 loc) · 2.06 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
class User{
constructor(username, password, name) {
//constructor
this.username = username; //check in database to ensure username & password are unqiue
this.password = stringToHash(password);
this.name = name;
this.userType = "User";
}
getUserType() {
return this.userType;
}
getUsername() {
return this.username;
}
getPassword() {
return hashToString(this.password);
}
getName() {
return this.name;
}
editName(newName) {
this.name = newName;
return true;
}
editUsername(newUsername) {
this.username = newUsername;
return true;
}
editPassword(newPassword) {
this.password = stringToHash(newPassword);
return true;
}
//Login functionality
ViewCars(carsArray, startDate, endDate, startTime, endTime) {
let avail_cars = [];
for(let i = 0; i < carsArray.length; i++){
if(carsArray[i].CheckAvail(startDate, endDate, startTime, endTime)){
avail_cars.push(carsArray[i]);
}
}
return avail_cars;
}
//approving clients request online, client has to have an account
//checking avail should be done before request gets here
addReservation(startDate, endDate, startTime, endTime, clientUsername, carObj) {
carObj.AddReserve(startDate, endDate, startTime, endTime, clientUsername);
}
removeReservation(startDate, endDate, startTime, endTime, carObj) {
carObj.RemoveReserve(startDate, endDate, startTime, endTime);
}
stringToHash(str) {
let hash = '';
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
hash += charCode.toString(16);
}
return hash;
}
hashToString(hash) {
let str = '';
for (let i = 0; i < hash.length; i += 2) {
const hex = hash.substr(i, 2);
str += String.fromCharCode(parseInt(hex, 16));
}
return str;
}
}
module.exports = User;