cloud work - user management

This commit is contained in:
Branislav Stojkovic
2016-10-22 15:09:10 +02:00
parent d8b915f8a5
commit 5b5b75142f
18 changed files with 192 additions and 118 deletions
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.model;
package org.diylc.plugins.cloud.model;
import java.io.Serializable;
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.model;
package org.diylc.plugins.cloud.model;
import java.io.File;
import java.util.List;
@@ -12,9 +12,9 @@ import com.diyfever.httpproxy.ParamName;
*
*/
public interface ServiceAPI {
public static final String URL_KEY = "serviceUrl";
/**
* Creates a user with the specified details.
*
@@ -62,6 +62,19 @@ public interface ServiceAPI {
@ParamName("password") String password,
@ParamName("machineId") String machineId);
/***
* Retrieves current user's details.
*
* @param username
* @param password
* @param machineId
* @return string with an error message if it fails, or an instance of
* {@link UserEntity} if it succeeds.
*/
Object getUserDetails(@ParamName("username") String username,
@ParamName("token") String token,
@ParamName("machineId") String machineId);
/***
* Tries to authenticate with the token that was previously created by
* calling login() function.
@@ -127,7 +140,7 @@ public interface ServiceAPI {
* @return a {@link List} of available categories.
*/
List<String> getCategories();
/**
* @return a {@link List} of available sortings.
*/
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.model;
package org.diylc.plugins.cloud.model;
import java.io.Serializable;
@@ -6,48 +6,27 @@ public class UserEntity implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String userName;
private String password;
private String username;
private String email;
private String website;
private String bio;
public UserEntity(int id, String userName, String password, String email,
String website, String bio) {
public UserEntity(String userName, String email, String website, String bio) {
super();
this.id = id;
this.userName = userName;
this.password = password;
this.username = username;
this.email = email;
this.website = website;
this.bio = bio;
}
public int getId() {
return id;
public String getUsername() {
return username;
}
public void setId(int id) {
this.id = id;
public void setUsername(String username) {
this.username = username;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
@@ -78,11 +57,8 @@ public class UserEntity implements Serializable {
int result = 1;
result = prime * result + ((bio == null) ? 0 : bio.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + id;
result = prime * result
+ ((password == null) ? 0 : password.hashCode());
result = prime * result
+ ((userName == null) ? 0 : userName.hashCode());
+ ((username == null) ? 0 : username.hashCode());
result = prime * result + ((website == null) ? 0 : website.hashCode());
return result;
}
@@ -106,17 +82,10 @@ public class UserEntity implements Serializable {
return false;
} else if (!email.equals(other.email))
return false;
if (id != other.id)
return false;
if (password == null) {
if (other.password != null)
if (username == null) {
if (other.username != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
} else if (!username.equals(other.username))
return false;
if (website == null) {
if (other.website != null)
@@ -128,7 +97,7 @@ public class UserEntity implements Serializable {
@Override
public String toString() {
return "UserEntity [userName=" + userName + "]";
return "UserEntity [userName=" + username + "]";
}
}
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
public class CloudException extends Exception {
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
public interface CloudListener {
@@ -1,17 +1,15 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.swing.plugins.cloud.model.ServiceAPI;
import org.diylc.plugins.cloud.model.ServiceAPI;
import org.diylc.plugins.cloud.model.UserEntity;
import com.diyfever.httpproxy.PhpFlatProxy;
import com.diyfever.httpproxy.ProxyFactory;
@@ -160,6 +158,27 @@ public class CloudPresenter {
}
public UserEntity getUserDetails() throws CloudException {
String username = ConfigurationManager.getInstance().readString(
USERNAME_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
Object res;
try {
res = service.getUserDetails(username, token, getMachineId());
} catch (Exception e) {
throw new CloudException(e);
}
if (res instanceof String)
throw new CloudException(res.toString());
if (res instanceof UserEntity)
return (UserEntity) res;
throw new CloudException(
"Unexpected server response received for category list: "
+ res.getClass().getName());
}
private String getMachineId() {
if (machineId == null) {
try {
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
public class NotConnectedException extends Exception {
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
public class NotExistsException extends Exception {
@@ -1,4 +1,4 @@
package org.diylc.swing.plugins.cloud.presenter;
package org.diylc.plugins.cloud.presenter;
public class NotLoggedInException extends Exception {