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;
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) {
String generatedPassword = null;
......
......@@ -53,5 +53,12 @@ public class Page {
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 {
//SETTERS
//GETTERS
public int getId() {
return generatedId;
}
//OTHER METHODS
}
package model.users;
import model.Encryption;
import model.Page;
import model.Verification;
//import model.users.GuestUser;
public class User {
public class User extends GuestUser{
private String nameAndSurname;
private String username;
......@@ -13,6 +15,7 @@ public class User {
//CONSTRUCTORS
public User() {
super();
nameAndSurname = "Empty";
username = "Empty";
password = "Empty";
......@@ -20,6 +23,7 @@ public class User {
}
public User(String nameAndSurname, String username, String password) {
super();
this.nameAndSurname = (Verification.verificateNameAndSurname(nameAndSurname))
? nameAndSurname : "Empty";
this.username = (Verification.verificateUsername(username))
......@@ -74,4 +78,20 @@ public class User {
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