Skip to content

Commit f846248

Browse files
committed
Add the token field to the User and cleanup unneeded constructs
1 parent dd69021 commit f846248

2 files changed

Lines changed: 32 additions & 26 deletions

File tree

  • library/src

library/src/androidTest/java/com/proxerme/library/connection/user/request/LoginRequestTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public void testPasswordParameter() throws Exception {
8181
}
8282

8383
private User generateTestUser() {
84-
return new User("121658", "121658_VHuZqz.jpg");
84+
return new User("121658", "121658_VHuZqz.jpg", "OmSjyOzMeyICUnErDD04lsDta7REW2fIn6ZWUxG96" +
85+
"mIXHmplYymjYZK94BNXA1wloFSVcw3fTKdA6CT49ek7b4dfCYcdWQ0Xv2TFvTUoD8XGHOHP11Uc46rF4" +
86+
"BSXrZUU1LxwEqSgxNWdAC3ACWMF2di3N0Xe9S88BEBe3tuAfoNP1NpAIadJlwK9DHlLxqS83rl6VPD9b" +
87+
"qXabkKTsYBOslW61fOwFFDI7WLZLo8UM35XnPRPLsBdLwgJL5dpJQ6");
8588
}
8689
}

library/src/main/java/com/proxerme/library/connection/user/entitiy/User.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
* @author Ruben Gees
1515
*/
1616
public class User implements Parcelable, IdItem, ImageItem {
17+
1718
public static final Creator<User> CREATOR = new Creator<User>() {
19+
@Override
1820
public User createFromParcel(Parcel source) {
1921
return new User(source);
2022
}
2123

24+
@Override
2225
public User[] newArray(int size) {
2326
return new User[size];
2427
}
@@ -28,60 +31,64 @@ public User[] newArray(int size) {
2831
private String id;
2932
@Json(name = "avatar")
3033
private String imageId;
34+
@Json(name = "token")
35+
private String loginToken;
3136

3237
private User() {
3338

3439
}
3540

3641
/**
37-
* Constructor for a user after the login.
42+
* The Constructor.
3843
*
39-
* @param id The id of the user.
40-
* @param image The profile picture of the user.
44+
* @param id The id of the user.
45+
* @param image The profile picture of the user.
46+
* @param loginToken The login token, usable for further authentication.
4147
*/
42-
public User(@NonNull String id,
43-
@NonNull String image) {
48+
public User(@NonNull String id, @NonNull String image, @NonNull String loginToken) {
4449
this.id = id;
4550
this.imageId = image;
51+
this.loginToken = loginToken;
4652
}
4753

4854
protected User(Parcel in) {
4955
this.id = in.readString();
5056
this.imageId = in.readString();
57+
this.loginToken = in.readString();
5158
}
5259

5360
/**
5461
* Returns the id of the user.
5562
*
5663
* @return The id.
57-
* @throws RuntimeException If the user has no id yet, meaning he is not logged in yet.
5864
*/
5965
@NonNull
6066
@Override
61-
public String getId() throws UserInitializationException {
62-
if (id == null) {
63-
throw new UserInitializationException("User has no id yet.");
64-
}
65-
67+
public String getId() {
6668
return id;
6769
}
6870

6971
/**
7072
* Returns the profile picture of the user.
7173
*
7274
* @return The image.
73-
* @throws RuntimeException If the user has not image yet, meaning he is not logged in yet.
7475
*/
7576
@NonNull
7677
@Override
77-
public String getImageId() throws UserInitializationException {
78-
if (imageId == null) {
79-
throw new UserInitializationException("User has no image yet.");
80-
}
81-
78+
public String getImageId() {
8279
return imageId;
8380
}
8481

82+
/**
83+
* Returns the login token of the user for further authentification.
84+
*
85+
* @return The token.
86+
*/
87+
@NonNull
88+
public String getLoginToken() {
89+
return loginToken;
90+
}
91+
8592
@SuppressWarnings("SimplifiableIfStatement")
8693
@Override
8794
public boolean equals(Object o) {
@@ -91,13 +98,15 @@ public boolean equals(Object o) {
9198
User user = (User) o;
9299

93100
if (!id.equals(user.id)) return false;
94-
return imageId.equals(user.imageId);
101+
if (!imageId.equals(user.imageId)) return false;
102+
return loginToken.equals(user.loginToken);
95103
}
96104

97105
@Override
98106
public int hashCode() {
99107
int result = id.hashCode();
100108
result = 31 * result + imageId.hashCode();
109+
result = 31 * result + loginToken.hashCode();
101110
return result;
102111
}
103112

@@ -110,12 +119,6 @@ public int describeContents() {
110119
public void writeToParcel(Parcel dest, int flags) {
111120
dest.writeString(this.id);
112121
dest.writeString(this.imageId);
113-
}
114-
115-
public static class UserInitializationException extends RuntimeException {
116-
117-
public UserInitializationException(String message) {
118-
super(message);
119-
}
122+
dest.writeString(this.loginToken);
120123
}
121124
}

0 commit comments

Comments
 (0)