Commit bf9b9b45 by Jan Hrabal

login

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