Commit bf9b9b45 by Jan Hrabal

login

parent b2a3d6e0
......@@ -71,6 +71,7 @@ CREATE TABLE APP_USER (
VERSION INT8 NOT NULL DEFAULT 0,
DELETED BOOLEAN DEFAULT FALSE,
LOGIN VARCHAR(250) NOT NULL,
EMAIL VARCHAR(250) NOT NULL,
PASSWORD VARCHAR(500),
PASSWORD_SALT VARCHAR(250),
......
......@@ -251,7 +251,7 @@ public class AuthApiController {
}
if (user != null) {
authService.changePassword(user.getEmail(), chp.getCurrentPassword(), chp.getPassword());
authService.changePassword(user.getLogin(), chp.getCurrentPassword(), chp.getPassword());
return ResponseEntity.accepted().build();
}
......
......@@ -47,7 +47,11 @@ public class AppUser extends AbstractIdEntity {
@Column(name = "DELETED")
private Boolean deleted;
/** The email. */
/** The login. */
@Column(name = "LOGIN")
private String login;
/** The login. */
@Column(name = "EMAIL")
private String email;
......@@ -116,8 +120,8 @@ public class AppUser extends AbstractIdEntity {
*
* @return the email
*/
public String getEmail() {
return email;
public String getLogin() {
return login;
}
/**
......@@ -125,8 +129,8 @@ public class AppUser extends AbstractIdEntity {
*
* @param email the new email
*/
public void setEmail(String email) {
this.email = email;
public void setLogin(String email) {
this.login = email;
}
/**
......@@ -309,4 +313,12 @@ public class AppUser extends AbstractIdEntity {
this.rolesMap = rolesMap;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
......@@ -20,8 +20,8 @@ public class AppUserRepository extends AbstractHibernateRepository {
if (!StringUtils.hasText(username)) {
return null;
}
Query q = entityManager.createQuery("select au from AppUser au where lower(au.email) = :email and (au.deleted is null or au.deleted = false)");
q.setParameter("email", username.trim().toLowerCase());
Query q = entityManager.createQuery("select au from AppUser au where lower(au.login) = :login and (au.deleted is null or au.deleted = false)");
q.setParameter("login", username.trim().toLowerCase());
return singleResult(q);
}
......@@ -30,8 +30,8 @@ public class AppUserRepository extends AbstractHibernateRepository {
if (!StringUtils.hasText(username)) {
return null;
}
Query q = entityManager.createQuery("select au from AppUser au left join fetch au.roles where lower(au.email) = :email and (au.deleted is null or au.deleted = false)");
q.setParameter("email", username.trim().toLowerCase());
Query q = entityManager.createQuery("select au from AppUser au left join fetch au.roles where lower(au.login) = :login and (au.deleted is null or au.deleted = false)");
q.setParameter("login", username.trim().toLowerCase());
AppUser user = singleResult(q);
if (user == null) {
return null;
......@@ -43,7 +43,7 @@ public class AppUserRepository extends AbstractHibernateRepository {
public AppUser registerUser(String username, String password) {
AppUser user = new AppUser();
user.setEmail(username);
user.setLogin(username);
PasswordHash hash = PasswordUtils.hashPassword(password);
user.setPassword(hash.getHash());
......
......@@ -135,7 +135,7 @@ public class AppUserAuthService implements AuthService {
if (user == null) {
throw new BadCredentialsException("AUTH.USER_NOT_FOUND");
}
user = appUserRepository.findByLogin(user.getEmail());
user = appUserRepository.findByLogin(user.getLogin());
if (user == null) {
throw new BadCredentialsException("AUTH.USER_NOT_FOUND");
}
......
......@@ -51,7 +51,7 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Override
public void registerUser(AppUser user, String password) {
Map<String, Object> data = new HashMap<>();
data.put("login", user.getEmail());
data.put("login", user.getLogin());
data.put("password", password);
data.put("loginPath", relativePath("/login"));
......@@ -81,7 +81,7 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
html = templateService.evaluate(html, data, locale);
Email email = new Email();
email.setRecipients(Collections.singleton(new EmailRecipient(user.getEmail(), RecipientType.TO)));
email.setRecipients(Collections.singleton(new EmailRecipient(user.getLogin(), RecipientType.TO)));
email.setSubject(subject);
email.setText(content);
email.setHtml(html);
......
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