Commit 8ef38747 by Jan Hrabal

login field

parent bf9b9b45
...@@ -29,10 +29,11 @@ public interface AuthService { ...@@ -29,10 +29,11 @@ public interface AuthService {
/** /**
* Register. * Register.
* @param locale TODO * @param signup the signup
* @param signup the signup * @param email
*/ * @param locale TODO
void register(String login, String password, Locale locale) throws AuthenticationException; */
void register(String login, String email, String password, Locale locale) throws AuthenticationException;
/** /**
......
...@@ -129,7 +129,11 @@ public class AuthApiController { ...@@ -129,7 +129,11 @@ public class AuthApiController {
if (!StringUtils.hasText(signup.getLogin())) { if (!StringUtils.hasText(signup.getLogin())) {
errors.add(ErrorMessage.withFieldCode("login", "AUTH.BAD_USERNAME")); errors.add(ErrorMessage.withFieldCode("login", "AUTH.BAD_USERNAME"));
} }
if (!StringUtils.hasText(signup.getEmail())) {
errors.add(ErrorMessage.withFieldCode("email", "AUTH.BAD_EMAIL"));
}
if (!PasswordUtils.validatePassword(signup.getPassword())) { if (!PasswordUtils.validatePassword(signup.getPassword())) {
errors.add(ErrorMessage.withFieldCode("password", "AUTH.BAD_PASSWORD")); errors.add(ErrorMessage.withFieldCode("password", "AUTH.BAD_PASSWORD"));
} }
...@@ -146,7 +150,7 @@ public class AuthApiController { ...@@ -146,7 +150,7 @@ public class AuthApiController {
} }
try { try {
authService.register(signup.getLogin(), signup.getPassword(), locale); authService.register(signup.getLogin(), signup.getEmail(), signup.getPassword(), locale);
} catch (BadCredentialsException e) { } catch (BadCredentialsException e) {
errors.add(ErrorMessage.withCode(e.getMessage())); errors.add(ErrorMessage.withCode(e.getMessage()));
} catch (Exception e) { } catch (Exception e) {
......
...@@ -4,6 +4,8 @@ public class Signup { ...@@ -4,6 +4,8 @@ public class Signup {
private String login; private String login;
private String email;
private String password; private String password;
private Boolean terms; private Boolean terms;
...@@ -20,6 +22,13 @@ public class Signup { ...@@ -20,6 +22,13 @@ public class Signup {
this.password = password; this.password = password;
} }
public Signup(String login, String email, String password) {
super();
this.login = login;
this.email = email;
this.password = password;
}
public String getLogin() { public String getLogin() {
return login; return login;
} }
...@@ -52,4 +61,11 @@ public class Signup { ...@@ -52,4 +61,11 @@ public class Signup {
this.privacy = privacy; this.privacy = privacy;
} }
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
} }
...@@ -69,7 +69,7 @@ public class AppUserAuthService implements AuthService { ...@@ -69,7 +69,7 @@ public class AppUserAuthService implements AuthService {
@Override @Override
@Transactional @Transactional
public void register(String login, String password, Locale locale) throws AuthenticationException { public void register(String login, String email, String password, Locale locale) throws AuthenticationException {
AppUser user = appUserRepository.findByLogin(login); AppUser user = appUserRepository.findByLogin(login);
if (user != null) { if (user != null) {
throw new BadCredentialsException("AUTH.USER_ALREADY_EXISTS"); throw new BadCredentialsException("AUTH.USER_ALREADY_EXISTS");
......
...@@ -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.getLogin(), RecipientType.TO))); email.setRecipients(Collections.singleton(new EmailRecipient(user.getEmail(), 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