Skip to content
Snippets Groups Projects

Fix/login

Merged Mads Lundegaard requested to merge fix/login into dev
1 unresolved thread
Files
3
package NTNU.IDATT1002.repository;
import NTNU.IDATT1002.ApplicationState;
import NTNU.IDATT1002.models.ImageAlbum;
import NTNU.IDATT1002.models.Login;
import NTNU.IDATT1002.models.User;
import NTNU.IDATT1002.utils.Authentication;
@@ -12,16 +14,38 @@ import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* Login Repository
*
* Implements {@link Repository} whick supports CRUD operations.
*
* @author madslun
* @version 1.0 22.03.20
* @see NTNU.IDATT1002.repository.Repository
*/
public class LoginRepository extends GenericRepository<Login, String>{
private EntityManager entityManager;
/**
* Constructor to inject {@link EntityManager} dependency and sets the class type to {@link Login}
*
* @param entityManager the entity manager to utilize
*/
public LoginRepository(EntityManager entityManager) {
super(entityManager);
setClassType(Login.class);
}
/**
* Logs a user into the sytem
*
* @param username of user that should login
* @param password of the user that should login
* @return boolean of the operation
*/
public boolean logIn(String username, String password) {
try {
Optional<Login> login = findById(username);
@@ -37,6 +61,15 @@ public class LoginRepository extends GenericRepository<Login, String>{
return false;
}
/**
* Checks the old password on the user and changes to the new password if the old is correct
*
* @param username of the user that want to change password
* @param oldPassword that will be checked to the database
* @param newPassword that will be changed to
* @return boolean of the operation
*/
public boolean changePassword(String username, String oldPassword, String newPassword) {
ArrayList<String> info = new ArrayList<>();
try {
Loading