Revision 49498
Added by Sofia Baltzi over 6 years ago
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/utils/VerificationActions.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import java.sql.SQLException; |
11 | 11 |
import java.sql.Timestamp; |
12 |
import java.time.LocalDateTime; |
|
13 |
import java.time.temporal.ChronoUnit; |
|
12 | 14 |
|
13 | 15 |
/** |
14 | 16 |
* Created by kiatrop on 2/10/2017. |
... | ... | |
96 | 98 |
/** |
97 | 99 |
* Checks if the verification row exists for the given username |
98 | 100 |
*/ |
99 |
public boolean verificationEntryExists(String username, String verificationCode) {
|
|
101 |
public boolean verificationCodeIsCorrect(String username, String verificationCode) {
|
|
100 | 102 |
|
101 | 103 |
try { |
102 | 104 |
UserVerification userVerification = userVerificationDAO.fetchByUsername(username); |
... | ... | |
108 | 110 |
else { |
109 | 111 |
logger.info("User: " + username + " was found!"); |
110 | 112 |
|
111 |
if (userVerification.getVerificationCode() == verificationCode) {
|
|
113 |
if (verificationCode.equals(userVerification.getVerificationCode())) {
|
|
112 | 114 |
logger.info("... and verification code: " + verificationCode + " is correct!"); |
115 |
return true; |
|
113 | 116 |
} |
114 |
return true; |
|
115 | 117 |
} |
116 | 118 |
} catch (SQLException e) { |
117 | 119 |
e.printStackTrace(); |
118 | 120 |
logger.info("Fail to search user.", e); |
119 | 121 |
} |
120 |
return true;
|
|
122 |
return false;
|
|
121 | 123 |
} |
122 | 124 |
|
125 |
public boolean verificationCodeHasExpired(String username){ |
|
126 |
|
|
127 |
try { |
|
128 |
UserVerification userVerification = userVerificationDAO.fetchByUsername(username); |
|
129 |
LocalDateTime date = userVerification.getDate().toLocalDateTime(); |
|
130 |
|
|
131 |
long nHours = ChronoUnit.HOURS.between(date, LocalDateTime.now()); |
|
132 |
|
|
133 |
if (nHours > (long)24) |
|
134 |
return true; |
|
135 |
else |
|
136 |
return false; |
|
137 |
|
|
138 |
} catch (SQLException e) { |
|
139 |
e.printStackTrace(); |
|
140 |
logger.info("Fail to search user.", e); |
|
141 |
} |
|
142 |
return true; |
|
143 |
} |
|
144 |
|
|
123 | 145 |
public DataSourceConnector getDataSourceConnector() { |
124 | 146 |
return dataSourceConnector; |
125 | 147 |
} |
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/dao/UserVerificationDAO.java | ||
---|---|---|
158 | 158 |
UserVerification userVerification = new UserVerification(set.getString("username")); |
159 | 159 |
|
160 | 160 |
userVerification.setId(set.getInt("id")); |
161 |
userVerification.setVerificationCode(set.getString("verification_code")); |
|
162 |
userVerification.setDate(set.getTimestamp("date")); |
|
161 | 163 |
|
162 | 164 |
return userVerification; |
163 | 165 |
} |
Also available in: Unified diff
Work verification code expiration