Implement a password reset flow.

This commit is contained in:
Me Car 2016-01-10 20:00:08 +09:00
parent 23d47be04c
commit 746d034461
14 changed files with 900 additions and 37 deletions

View file

@ -58,6 +58,10 @@ public interface MageServer {
// registers a user to the user DB.
boolean registerUser(String sessionId, String userName, String password, String email) throws MageException;
boolean emailAuthToken(String sessionId, String email) throws MageException;
boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException;
// connection methods
// DEPRECATED - Use connectUser instead. This is only kept for older clients.
// This can be deleted once users transitioned to newer clients (1.4.6v1 and later).

View file

@ -46,6 +46,7 @@ public class Connection {
private String username;
private String password;
private String email;
private String authToken;
private String adminPassword;
private ProxyType proxyType;
private String proxyHost;
@ -182,6 +183,14 @@ public class Connection {
this.email = email;
}
public String getAuthToken() {
return authToken;
}
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
public String getAdminPassword() {
return adminPassword;
}

View file

@ -204,6 +204,36 @@ public class SessionImpl implements Session {
});
}
@Override
public synchronized boolean emailAuthToken(final Connection connection) {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying to ask for an auth token to " + getEmail() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
boolean result = server.emailAuthToken(sessionId, connection.getEmail());
if (result) {
logger.info("An auth token is emailed to " + getEmail() + " from MAGE server at " + connection.getHost() + ":" + connection.getPort());
}
return result;
}
});
}
@Override
public synchronized boolean resetPassword(final Connection connection) {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying reset the password in XMAGE server at " + connection.getHost() + ":" + connection.getPort());
boolean result = server.resetPassword(sessionId, connection.getEmail(), connection.getAuthToken(), connection.getPassword());
if (result) {
logger.info("Password is successfully reset in MAGE server at " + connection.getHost() + ":" + connection.getPort());
}
return result;
}
});
}
@Override
public synchronized boolean connect(final Connection connection) {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@ -1445,6 +1475,16 @@ public class SessionImpl implements Session {
return username == null ? "" : username;
}
private String getEmail() {
String email = connection.getEmail();
return email == null ? "" : email;
}
private String getAuthToken() {
String authToken = connection.getAuthToken();
return authToken == null ? "" : authToken;
}
@Override
public boolean updatePreferencesForServer(UserData userData) {
try {

View file

@ -36,6 +36,10 @@ public interface Connect {
boolean register(Connection connection);
boolean emailAuthToken(Connection connection);
boolean resetPassword(Connection connection);
boolean connect(Connection connection);
boolean stopConnecting();