-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUser.ts
95 lines (77 loc) · 2.09 KB
/
User.ts
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
import InputValidator from "../common/InputValidator";
import IUnits from "../interfaces/IUnits";
import { Globals } from "../common/Globals";
/**
* Represents a user-row in the database
*/
export default class User implements IUnits {
/**
* The ID of the user
*/
public userID: number;
/**
* The name of the user
*/
public username: string;
/**
* The encrypted password of the user
*/
public password: string;
/**
* The e-mail address of the user
*/
public email: string;
/**
* The unix-timestamp of the last time the user was online
*/
public lastTimeOnline: number;
/**
* The current planet of the user
*/
public currentPlanet: number;
/**
* The ID of the technology which is currently being researched.
* This value is 0 if no technology is currently being researched.
*/
public bTechID: number;
/**
* The time, at which the research will be completed
*/
public bTechEndTime: number;
/**
* Checks, if the planet is currently researching
*/
public isResearching(): boolean {
return this.bTechID > 0 && this.bTechEndTime > 0;
}
/**
* Returns, if the contains valid data or not
*/
public isValid(): boolean {
if (!InputValidator.isSet(this.userID) || this.userID <= 0) {
return false;
}
if (!InputValidator.isSet(this.username) || this.username.length > 20 || this.username.length < 5) {
return false;
}
if (!InputValidator.isSet(this.password) || this.password.length > 60) {
return false;
}
if (!InputValidator.isSet(this.email) || this.email.length > 64) {
return false;
}
if (!InputValidator.isSet(this.lastTimeOnline) || this.lastTimeOnline <= 0) {
return false;
}
if (!InputValidator.isSet(this.currentPlanet) || this.currentPlanet <= 0) {
return false;
}
if (!InputValidator.isSet(this.bTechID) || this.bTechID < 0 || this.bTechID > Globals.MAX_TECHNOLOGY_ID) {
return false;
}
if (!InputValidator.isSet(this.bTechEndTime) || this.bTechEndTime < 0) {
return false;
}
return true;
}
}