Commit 6379b9bf authored by Oskars's avatar Oskars
Browse files

Add: (to User class) - toString, login, followPage, (to Page class) - addFollower methods.

parent c1e51996
...@@ -5,6 +5,7 @@ import java.security.NoSuchAlgorithmException; ...@@ -5,6 +5,7 @@ import java.security.NoSuchAlgorithmException;
public class Encryption { public class Encryption {
// https://howtodoinjava.com/java/java-security/how-to-generate-secure-password-hash-md5-sha-pbkdf2-bcrypt-examples/
public static String encryptMD5(String inputPassword) { public static String encryptMD5(String inputPassword) {
String generatedPassword = null; String generatedPassword = null;
......
...@@ -53,5 +53,12 @@ public class Page { ...@@ -53,5 +53,12 @@ public class Page {
return "Title: " + title + ", Description: " + description + ", Followers " + followers.size() + ", Posts: " + postsInPage.size(); return "Title: " + title + ", Description: " + description + ", Followers " + followers.size() + ", Posts: " + postsInPage.size();
} }
public boolean addFollower(User user) {
if(user != null){
followers.add(user);
return true;
}else return false;
}
} }
...@@ -13,5 +13,9 @@ public class GuestUser { ...@@ -13,5 +13,9 @@ public class GuestUser {
//SETTERS //SETTERS
//GETTERS //GETTERS
public int getId() {
return generatedId;
}
//OTHER METHODS
} }
package model.users; package model.users;
import model.Encryption; import model.Encryption;
import model.Page;
import model.Verification; import model.Verification;
//import model.users.GuestUser;
public class User { public class User extends GuestUser{
private String nameAndSurname; private String nameAndSurname;
private String username; private String username;
...@@ -13,6 +15,7 @@ public class User { ...@@ -13,6 +15,7 @@ public class User {
//CONSTRUCTORS //CONSTRUCTORS
public User() { public User() {
super();
nameAndSurname = "Empty"; nameAndSurname = "Empty";
username = "Empty"; username = "Empty";
password = "Empty"; password = "Empty";
...@@ -20,6 +23,7 @@ public class User { ...@@ -20,6 +23,7 @@ public class User {
} }
public User(String nameAndSurname, String username, String password) { public User(String nameAndSurname, String username, String password) {
super();
this.nameAndSurname = (Verification.verificateNameAndSurname(nameAndSurname)) this.nameAndSurname = (Verification.verificateNameAndSurname(nameAndSurname))
? nameAndSurname : "Empty"; ? nameAndSurname : "Empty";
this.username = (Verification.verificateUsername(username)) this.username = (Verification.verificateUsername(username))
...@@ -74,4 +78,20 @@ public class User { ...@@ -74,4 +78,20 @@ public class User {
return generatedPassword; return generatedPassword;
} }
//OTHER METHODS
public String toString() {
return "User ID: " + super.getId() + "Full name: " + nameAndSurname + ", Username: " + username;
}
public boolean login(String inputUsername, String inputPassword) {
return (username == inputUsername && generatedPassword == Encryption.encryptMD5(inputPassword))?
true : false;
}
public boolean followPage(Page page) {
if(page != null) {
return page.addFollower(this)? true : false;
}else return false;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment