cloud user management

This commit is contained in:
Branislav Stojkovic
2016-10-22 19:12:34 +02:00
parent a7a99cc4ec
commit ff019542f8
7 changed files with 343 additions and 59 deletions
@@ -43,7 +43,7 @@ public interface ServiceAPI {
* @return "Success" if the operation is successful or error message if it
* failed.
*/
String updateUser(@ParamName("username") String username,
String updateUserDetails(@ParamName("username") String username,
@ParamName("token") String token,
@ParamName("machineId") String machineId,
@ParamName("email") String email,
@@ -89,6 +89,20 @@ public interface ServiceAPI {
@ParamName("token") String token,
@ParamName("machineId") String machineId);
/***
* Updates password of the current user using token to authenticate.
*
* @param username
* @param token
* @param machineId
* @param password
* @return "Success" if the login is successful or error message if it
* failed.
*/
String updatePassword(@ParamName("username") String username,
@ParamName("oldPassword") String oldPassword,
@ParamName("newPassword") String newPassword);
/***
* Searches for projects that meet the specified search criteria. Supports
* pagination.
@@ -179,6 +179,39 @@ public class CloudPresenter {
+ res.getClass().getName());
}
public void updatePassword(String oldPassword, String newPassword)
throws CloudException {
String username = ConfigurationManager.getInstance().readString(
USERNAME_KEY, null);
String res;
try {
res = service.updatePassword(username, oldPassword, newPassword);
} catch (Exception e) {
throw new CloudException(e);
}
if (!res.equals(SUCCESS))
throw new CloudException(res);
}
public void updateUserDetails(String email, String website, String bio)
throws CloudException {
String username = ConfigurationManager.getInstance().readString(
USERNAME_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
String res;
try {
res = service.updateUserDetails(username, token, getMachineId(),
email, website, bio);
} catch (Exception e) {
throw new CloudException(e);
}
if (!res.equals(SUCCESS))
throw new CloudException(res);
}
private String getMachineId() {
if (machineId == null) {
try {