1
|
|
|
/* |
2
|
|
|
* This file is part of Araknemu. |
3
|
|
|
* |
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.data.living.entity.account; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.common.account.Permission; |
23
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
24
|
|
|
|
25
|
|
|
import java.util.EnumSet; |
26
|
|
|
import java.util.Objects; |
27
|
|
|
import java.util.Set; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* AuthenticationAccount data |
31
|
|
|
*/ |
32
|
|
|
@SuppressWarnings("argument") // @todo remove when PK system is changed |
|
|
|
|
33
|
|
|
public final class Account { |
34
|
|
|
private final int id; |
35
|
|
|
|
36
|
|
|
private String name; |
37
|
|
|
private String password; |
38
|
|
|
private String pseudo; |
39
|
|
|
private Set<Permission> permissions; |
40
|
|
|
private String question; |
41
|
|
|
private String answer; |
42
|
|
|
|
43
|
1 |
|
public Account(int id, String name, String password, String pseudo, Set<Permission> permissions, String question, String answer) { |
44
|
1 |
|
this.id = id; |
45
|
1 |
|
this.name = name; |
46
|
1 |
|
this.password = password; |
47
|
1 |
|
this.pseudo = pseudo; |
48
|
1 |
|
this.permissions = permissions; |
49
|
1 |
|
this.question = question; |
50
|
1 |
|
this.answer = answer; |
51
|
1 |
|
} |
52
|
|
|
|
53
|
|
|
public Account(int id, String name, String password, String pseudo) { |
54
|
1 |
|
this(id, name, password, pseudo, EnumSet.noneOf(Permission.class), "", ""); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
public Account(int id) { |
58
|
1 |
|
this(id, null, null, null, null, null, null); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
public int id() { |
62
|
1 |
|
return id; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public String name() { |
66
|
1 |
|
return name; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public String password() { |
70
|
1 |
|
return password; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public String pseudo() { |
74
|
1 |
|
return pseudo; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public Set<Permission> permissions() { |
78
|
1 |
|
return permissions; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public String question() { |
82
|
1 |
|
return question; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public String answer() { |
86
|
1 |
|
return answer; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Change the password |
91
|
|
|
*/ |
92
|
|
|
public void setPassword(String password) { |
93
|
1 |
|
this.password = password; |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Define the entity id |
98
|
|
|
* This method will create a new instance of the account entity |
99
|
|
|
* |
100
|
|
|
* @param id The id to set |
101
|
|
|
* |
102
|
|
|
* @return The new entity instance |
103
|
|
|
*/ |
104
|
|
|
public Account withId(int id) { |
105
|
1 |
|
return new Account( |
106
|
|
|
id, |
107
|
|
|
this.name, |
108
|
|
|
this.password, |
109
|
|
|
this.pseudo, |
110
|
|
|
this.permissions, |
111
|
|
|
this.question, |
112
|
|
|
this.answer |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
@Override |
117
|
|
|
public boolean equals(@Nullable Object o) { |
118
|
1 |
|
if (this == o) { |
119
|
1 |
|
return true; |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
|
if (o == null || getClass() != o.getClass()) { |
123
|
1 |
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
final Account account = (Account) o; |
127
|
|
|
|
128
|
1 |
|
return |
129
|
|
|
id == account.id |
130
|
1 |
|
&& Objects.equals(name, account.name) |
131
|
1 |
|
&& Objects.equals(pseudo, account.pseudo) |
132
|
1 |
|
&& Objects.equals(password, account.password) |
133
|
|
|
; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
@Override |
137
|
|
|
public int hashCode() { |
138
|
1 |
|
int result = id; |
139
|
1 |
|
result = 31 * result + (name != null ? name.hashCode() : 0); |
140
|
1 |
|
result = 31 * result + (password != null ? password.hashCode() : 0); |
141
|
1 |
|
result = 31 * result + (pseudo != null ? pseudo.hashCode() : 0); |
142
|
1 |
|
return result; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|