Commit 634cefca authored by Oskars's avatar Oskars
Browse files

Add: class privateUser

parent 6379b9bf
......@@ -53,12 +53,7 @@ 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;
}
}
......@@ -2,7 +2,7 @@ package model.users;
public class GuestUser {
private int generatedId = 0;
private int generatedId;
private static int IdCounter = 0;
//CONSTRUCTOR
......
package model.users;
public class PostType {
enum Access{
PRIVATE,
PUBLIC
}
}
package model.users;
import java.util.ArrayList;
import model.Post;
public class PrivateUser extends User {
//private ArrayList<Post> privatePosts;
//private ArrayList<Post> publicPosts;
private ArrayList<Post> posts;
private ArrayList<User> followers;
//CONSTRUCTORS
public PrivateUser() {
super();
posts = new ArrayList<Post>();
followers = new ArrayList<User>();
}
public PrivateUser(String nameAndSurname, String username, String password, ArrayList<Post> posts, ArrayList<User> followers) {
super(nameAndSurname, username, password);
this.posts = (posts != null)? posts : new ArrayList<Post>();
this.followers = (followers != null)? followers : new ArrayList<User>();
}
//SETTERS
public void setUser(User user) {
if(user != null) {
this.setNameAndSurname(user.getNameAndSurname());
this.setUsername(user.getUsername());
this.setPassword(user.getPassword());
}
}
public void setPosts(ArrayList<Post> posts) {
if(posts != null) this.posts = posts;
}
public void setFollowers(ArrayList<User> followers) {
if(followers != null) this.followers = followers;
}
//GETTERS
public ArrayList<Post> getPosts() {
return posts;
}
public ArrayList<User> getFollowers(){
return followers;
}
//OTHER METHODS
public String toString() {
return super.toString() + ", Posts: " + posts.size() + ", Followers: " + followers.size();
}
public void followPrivateUser(PrivateUser privateUser) {
if(privateUser != null) {
ArrayList<User> uf = privateUser.getFollowers();
uf.add(this);
privateUser.setFollowers(uf);
}
}
}
package model.users;
import java.util.ArrayList;
import model.Encryption;
import model.Page;
import model.Verification;
......@@ -83,15 +85,21 @@ public class User extends GuestUser{
return "User ID: " + super.getId() + "Full name: " + nameAndSurname + ", Username: " + username;
}
public boolean login(String inputUsername, String inputPassword) {
return (username == inputUsername && generatedPassword == Encryption.encryptMD5(inputPassword))?
public boolean login(String inputPassword) {
return (generatedPassword == Encryption.encryptMD5(inputPassword))?
true : false;
}
public boolean followPage(Page page) {
if(page != null) {
return page.addFollower(this)? true : false;
}else return false;
if(page!= null) {
ArrayList<User> pageFollowers = page.getFollowers();
pageFollowers.add(this);
page.setFollowers(pageFollowers);
return true;
}
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