Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
09843e49ad
@ -1,19 +0,0 @@
|
|||||||
package org.baeldung.event;
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class OnRegistrationComplete extends ApplicationEvent {
|
|
||||||
|
|
||||||
public final Registration registration;
|
|
||||||
|
|
||||||
public OnRegistrationComplete(Registration source) {
|
|
||||||
super(source);
|
|
||||||
this.registration=source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Registration getRegistration() {
|
|
||||||
return registration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package org.baeldung.event;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.baeldung.persistence.model.User;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class OnRegistrationCompleteEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private final String appUrl;
|
||||||
|
private final Locale locale;
|
||||||
|
private final User user;
|
||||||
|
|
||||||
|
public OnRegistrationCompleteEvent(User user, Locale locale, String appUrl) {
|
||||||
|
super(user);
|
||||||
|
this.user = user;
|
||||||
|
this.locale = locale;
|
||||||
|
this.appUrl = appUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppUrl() {
|
||||||
|
return appUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locale getLocale() {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
package org.baeldung.event;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.context.ApplicationEventPublisherAware;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Registration implements ApplicationEventPublisherAware {
|
|
||||||
|
|
||||||
private ApplicationEventPublisher eventPublisher;
|
|
||||||
|
|
||||||
public String getAppUrl() {
|
|
||||||
return appUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Locale getLocale() {
|
|
||||||
return locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppUrl(String appUrl) {
|
|
||||||
this.appUrl = appUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocale(Locale locale) {
|
|
||||||
this.locale = locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String appUrl;
|
|
||||||
private Locale locale;
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
public Registration() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deliver() {
|
|
||||||
this.eventPublisher.publishEvent(new OnRegistrationComplete(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationEventPublisher(
|
|
||||||
ApplicationEventPublisher applicationEventPublisher) {
|
|
||||||
this.eventPublisher = applicationEventPublisher;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,44 @@
|
|||||||
|
package org.baeldung.event.listener;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.baeldung.event.OnRegistrationCompleteEvent;
|
||||||
|
import org.baeldung.persistence.model.User;
|
||||||
|
import org.baeldung.persistence.service.IUserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RegistrationListener implements ApplicationListener<OnRegistrationCompleteEvent> {
|
||||||
|
@Autowired
|
||||||
|
private IUserService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageSource messages;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JavaMailSender mailSender;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(OnRegistrationCompleteEvent event) {
|
||||||
|
this.confirmRegistration(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirmRegistration(OnRegistrationCompleteEvent event) {
|
||||||
|
User user = event.getUser();
|
||||||
|
String token = UUID.randomUUID().toString();
|
||||||
|
service.addVerificationToken(user, token);
|
||||||
|
String recipientAddress = user.getEmail();
|
||||||
|
String subject = "Registration Confirmation";
|
||||||
|
String confirmationUrl = event.getAppUrl() + "/regitrationConfirm.html?token=" + token;
|
||||||
|
String message = messages.getMessage("message.regSucc", null, event.getLocale());
|
||||||
|
SimpleMailMessage email = new SimpleMailMessage();
|
||||||
|
email.setTo(recipientAddress);
|
||||||
|
email.setSubject(subject);
|
||||||
|
email.setText(message + " \r\n" + "http://localhost:8080" + confirmationUrl);
|
||||||
|
mailSender.send(email);
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +0,0 @@
|
|||||||
package org.baeldung.event.service;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.baeldung.event.OnRegistrationComplete;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.persistence.service.IUserService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
import org.springframework.context.MessageSource;
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class RegistrationService implements
|
|
||||||
ApplicationListener<OnRegistrationComplete> {
|
|
||||||
@Autowired
|
|
||||||
private IUserService service;
|
|
||||||
@Autowired
|
|
||||||
private MessageSource messages;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JavaMailSender mailSender;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(OnRegistrationComplete event) {
|
|
||||||
this.confirmRegistration(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void confirmRegistration(OnRegistrationComplete event) {
|
|
||||||
User user = event.getRegistration().getUser();
|
|
||||||
String token = UUID.randomUUID().toString();
|
|
||||||
service.addVerificationToken(user, token);
|
|
||||||
String recipientAddress = user.getEmail();
|
|
||||||
String subject = "Registration Confirmation";
|
|
||||||
String confirmationUrl = event.getRegistration().getAppUrl()
|
|
||||||
+ "/regitrationConfirm.html?token=" + token;
|
|
||||||
String message = messages.getMessage("message.regSucc", null, event
|
|
||||||
.getRegistration().getLocale());
|
|
||||||
SimpleMailMessage email = new SimpleMailMessage();
|
|
||||||
email.setTo(recipientAddress);
|
|
||||||
email.setSubject(subject);
|
|
||||||
email.setText(message + " \r\n" + "http://localhost:8080"
|
|
||||||
+ confirmationUrl);
|
|
||||||
mailSender.send(email);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,7 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import org.baeldung.persistence.model.User;
|
import org.baeldung.persistence.model.User;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
public User findByEmail(String email);
|
public User findByEmail(String email);
|
||||||
|
|
||||||
|
public void delete(User user);
|
||||||
|
|
||||||
public void delete(User user);
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package org.baeldung.persistence.dao;
|
package org.baeldung.persistence.dao;
|
||||||
|
|
||||||
|
import org.baeldung.persistence.model.User;
|
||||||
import org.baeldung.persistence.model.VerificationToken;
|
import org.baeldung.persistence.model.VerificationToken;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface VerificationTokenRepository extends JpaRepository<VerificationToken, Long> {
|
public interface VerificationTokenRepository extends JpaRepository<VerificationToken, Long> {
|
||||||
|
|
||||||
public VerificationToken findByToken(String token);
|
public VerificationToken findByToken(String token);
|
||||||
|
|
||||||
|
public VerificationToken findByUser(User user);
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ import javax.persistence.JoinColumn;
|
|||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity(name = "role")
|
@Entity
|
||||||
@Table(name = "role")
|
@Table
|
||||||
public class Role {
|
public class Role {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@ -28,7 +28,6 @@ public class Role {
|
|||||||
|
|
||||||
public Role() {
|
public Role() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Role(Integer role) {
|
public Role(Integer role) {
|
||||||
|
@ -14,34 +14,28 @@ import javax.persistence.Table;
|
|||||||
@Table
|
@Table
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
@Column(name = "firstName")
|
|
||||||
private String firstName;
|
@Column(name = "firstName")
|
||||||
@Column(name="lastName")
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "lastName")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
@Column(name="email")
|
|
||||||
|
@Column(name = "email")
|
||||||
private String email;
|
private String email;
|
||||||
@Column(name="password")
|
|
||||||
|
@Column(name = "password")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@OneToOne(mappedBy="user",
|
@Column(name = "enabled")
|
||||||
fetch = FetchType.EAGER,
|
private boolean enabled;
|
||||||
cascade= CascadeType.ALL)
|
|
||||||
private VerificationToken verificationToken;
|
@OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||||
|
|
||||||
@OneToOne(mappedBy = "user",fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
|
||||||
private Role role;
|
private Role role;
|
||||||
|
|
||||||
public VerificationToken getVerificationToken() {
|
|
||||||
return verificationToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerificationToken(VerificationToken verificationToken) {
|
|
||||||
this.verificationToken = verificationToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -90,6 +84,14 @@ public class User {
|
|||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
@ -111,11 +113,11 @@ public class User {
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append("User [firstName=").append(firstName).append("]").
|
builder.append("User [firstName=").append(firstName).append("]").append("[lastName=").append(lastName).append("]").append("[username").append(email).append("]");
|
||||||
append("[lastName=").append(lastName).append("]").append("[username").append(email).append("]");
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,109 +13,94 @@ import javax.persistence.JoinColumn;
|
|||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity()
|
@Entity
|
||||||
@Table()
|
@Table
|
||||||
public class VerificationToken {
|
public class VerificationToken {
|
||||||
|
|
||||||
private static final int EXPIRATION = 60 * 24;
|
private static final int EXPIRATION = 60 * 24;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "token")
|
@Column(name = "token")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
@Column(name = "verified")
|
@OneToOne(targetEntity = User.class, fetch = FetchType.EAGER)
|
||||||
private boolean verified;
|
@JoinColumn(name = "user_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
@OneToOne(targetEntity = User.class, fetch = FetchType.EAGER)
|
@Column(name = "expiry_date")
|
||||||
@JoinColumn(name = "user_id")
|
private Date expiryDate;
|
||||||
private User user;
|
|
||||||
|
|
||||||
@Column(name = "expiry_date")
|
public VerificationToken() {
|
||||||
private Date expiryDate;
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public VerificationToken() {
|
public VerificationToken(String token) {
|
||||||
super();
|
super();
|
||||||
|
this.token = token;
|
||||||
|
this.expiryDate = calculateExpiryDate(EXPIRATION);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public VerificationToken(String token, User user) {
|
||||||
|
super();
|
||||||
|
this.token = token;
|
||||||
|
this.user = user;
|
||||||
|
this.expiryDate = calculateExpiryDate(EXPIRATION);
|
||||||
|
}
|
||||||
|
|
||||||
public VerificationToken(String token) {
|
public String getToken() {
|
||||||
super();
|
return token;
|
||||||
this.token = token;
|
}
|
||||||
this.expiryDate = calculateExpiryDate(EXPIRATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VerificationToken(String token, User user) {
|
public void setToken(String token) {
|
||||||
super();
|
this.token = token;
|
||||||
this.token = token;
|
}
|
||||||
this.user = user;
|
|
||||||
this.expiryDate = calculateExpiryDate(EXPIRATION);
|
|
||||||
this.verified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
public User getUser() {
|
||||||
return token;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setToken(String token) {
|
public void setUser(User user) {
|
||||||
this.token = token;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVerified() {
|
public Date getExpiryDate() {
|
||||||
return verified;
|
return expiryDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVerified(boolean verified) {
|
public void setExpiryDate(Date expiryDate) {
|
||||||
this.verified = verified;
|
this.expiryDate = expiryDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
private Date calculateExpiryDate(int expiryTimeInMinutes) {
|
||||||
return user;
|
Calendar cal = Calendar.getInstance();
|
||||||
}
|
cal.setTime(new Timestamp(cal.getTime().getTime()));
|
||||||
|
cal.add(Calendar.MINUTE, expiryTimeInMinutes);
|
||||||
|
return new Date(cal.getTime().getTime());
|
||||||
|
|
||||||
public void setUser(User user) {
|
}
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getExpiryDate() {
|
@Override
|
||||||
return expiryDate;
|
public boolean equals(final Object obj) {
|
||||||
}
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
final VerificationToken verificationToken = (VerificationToken) obj;
|
||||||
|
if (!token.equals(verificationToken.getToken()))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void setExpiryDate(Date expiryDate) {
|
@Override
|
||||||
this.expiryDate = expiryDate;
|
public String toString() {
|
||||||
}
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("Token [String=").append(token).append("]").append("[Expires").append(expiryDate).append("]");
|
||||||
private Date calculateExpiryDate(int expiryTimeInMinutes) {
|
return builder.toString();
|
||||||
Calendar cal = Calendar.getInstance();
|
}
|
||||||
cal.setTime(new Timestamp(cal.getTime().getTime()));
|
|
||||||
cal.add(Calendar.MINUTE, expiryTimeInMinutes);
|
|
||||||
return new Date(cal.getTime().getTime());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
final VerificationToken verificationToken = (VerificationToken) obj;
|
|
||||||
if (!token.equals(verificationToken.getToken()))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("Token [String=").append(token).append("]")
|
|
||||||
.append("[verified=").append(verified).append("]")
|
|
||||||
.append("[Expires").append(expiryDate).append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
package org.baeldung.persistence.service;
|
package org.baeldung.persistence.service;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
import org.baeldung.persistence.model.User;
|
||||||
|
import org.baeldung.persistence.model.VerificationToken;
|
||||||
import org.baeldung.validation.service.EmailExistsException;
|
import org.baeldung.validation.service.EmailExistsException;
|
||||||
|
|
||||||
public interface IUserService {
|
public interface IUserService {
|
||||||
|
|
||||||
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException;
|
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException;
|
||||||
|
|
||||||
public User getRegisteredUser(String email);
|
/* public User getRegisteredUser(String email);*/
|
||||||
|
|
||||||
public User getUser(String verificationToken);
|
public User getUser(String verificationToken);
|
||||||
|
|
||||||
public void verifyRegisteredUser(User user);
|
public void saveRegisteredUser(User user);
|
||||||
|
|
||||||
public void addVerificationToken(User user, String token);
|
public void addVerificationToken(User user, String token);
|
||||||
|
|
||||||
|
public VerificationToken getVerificationToken(String VerificationToken);
|
||||||
|
|
||||||
|
public void verifyUser(VerificationToken token);
|
||||||
|
|
||||||
|
public void deleteUser(User user);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ public class UserDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,63 +13,78 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService implements IUserService {
|
public class UserService implements IUserService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository repository;
|
private UserRepository repository;
|
||||||
// NOV 6
|
|
||||||
@Autowired
|
|
||||||
private VerificationTokenRepository tokenRepository;
|
|
||||||
|
|
||||||
@Transactional
|
@Autowired
|
||||||
@Override
|
private VerificationTokenRepository tokenRepository;
|
||||||
public User registerNewUserAccount(UserDto accountDto)
|
|
||||||
throws EmailExistsException {
|
|
||||||
if (emailExist(accountDto.getEmail())) {
|
|
||||||
throw new EmailExistsException(
|
|
||||||
"There is an account with that email adress: "
|
|
||||||
+ accountDto.getEmail());
|
|
||||||
}
|
|
||||||
User user = new User();
|
|
||||||
user.setFirstName(accountDto.getFirstName());
|
|
||||||
user.setLastName(accountDto.getLastName());
|
|
||||||
user.setPassword(accountDto.getPassword());
|
|
||||||
user.setEmail(accountDto.getEmail());
|
|
||||||
user.setRole(new Role(Integer.valueOf(1), user));
|
|
||||||
return repository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean emailExist(String email) {
|
@Transactional
|
||||||
User user = repository.findByEmail(email);
|
@Override
|
||||||
if (user != null) {
|
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException {
|
||||||
return true;
|
if (emailExist(accountDto.getEmail())) {
|
||||||
}
|
throw new EmailExistsException("There is an account with that email adress: " + accountDto.getEmail());
|
||||||
return false;
|
}
|
||||||
}
|
User user = new User();
|
||||||
|
user.setFirstName(accountDto.getFirstName());
|
||||||
|
user.setLastName(accountDto.getLastName());
|
||||||
|
user.setPassword(accountDto.getPassword());
|
||||||
|
user.setEmail(accountDto.getEmail());
|
||||||
|
user.setRole(new Role(Integer.valueOf(1), user));
|
||||||
|
return repository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private boolean emailExist(String email) {
|
||||||
public User getRegisteredUser(String email) {
|
User user = repository.findByEmail(email);
|
||||||
|
if (user != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
User user = repository.findByEmail(email);
|
/* @Override
|
||||||
return user;
|
public User getRegisteredUser(String email) {
|
||||||
|
|
||||||
}
|
User user = repository.findByEmail(email);
|
||||||
|
return user;
|
||||||
|
|
||||||
@Override
|
}*/
|
||||||
public User getUser(String verificationToken) {
|
|
||||||
User user = tokenRepository.findByToken(verificationToken).getUser();
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
@Override
|
public User getUser(String verificationToken) {
|
||||||
public void verifyRegisteredUser(User user) {
|
User user = tokenRepository.findByToken(verificationToken).getUser();
|
||||||
repository.save(user);
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
@Override
|
public VerificationToken getVerificationToken(String VerificationToken) {
|
||||||
public void addVerificationToken(User user, String token) {
|
return tokenRepository.findByToken(VerificationToken);
|
||||||
VerificationToken myToken = new VerificationToken(token, user);
|
}
|
||||||
user.setVerificationToken(myToken);
|
|
||||||
repository.save(user);
|
@Transactional
|
||||||
}
|
@Override
|
||||||
|
public void saveRegisteredUser(User user) {
|
||||||
|
repository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void verifyUser(VerificationToken token) {
|
||||||
|
tokenRepository.save(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void deleteUser(User user) {
|
||||||
|
repository.delete(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void addVerificationToken(User user, String token) {
|
||||||
|
VerificationToken myToken = new VerificationToken(token, user);
|
||||||
|
// user.setVerificationToken(myToken);
|
||||||
|
tokenRepository.save(myToken);
|
||||||
|
// repository.save(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
return "/homepage.html";
|
return "/homepage.html?user="+authentication.getName();
|
||||||
} else if (isAdmin) {
|
} else if (isAdmin) {
|
||||||
return "/console.html";
|
return "/console.html";
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package org.baeldung.security;
|
package org.baeldung.security;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
@ -12,6 +10,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.baeldung.persistence.dao.UserRepository;
|
import org.baeldung.persistence.dao.UserRepository;
|
||||||
import org.baeldung.persistence.model.User;
|
import org.baeldung.persistence.model.User;
|
||||||
|
import org.baeldung.persistence.service.IUserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
@ -23,83 +22,63 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Transactional
|
@Transactional
|
||||||
public class MyUserDetailsService implements UserDetailsService {
|
public class MyUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
// OCT 21
|
private UserRepository userRepository;
|
||||||
// @Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private IUserService service;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageSource messages;
|
private MessageSource messages;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public MyUserDetailsService(UserRepository repository) {
|
||||||
|
this.userRepository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
||||||
public MyUserDetailsService(UserRepository repository) {
|
boolean enabled = true;
|
||||||
this.userRepository = repository;
|
boolean accountNonExpired = true;
|
||||||
}
|
boolean credentialsNonExpired = true;
|
||||||
|
boolean accountNonLocked = true;
|
||||||
|
try {
|
||||||
|
LOGGER.debug("Loading user by username: {}", email);
|
||||||
|
User user = userRepository.findByEmail(email);
|
||||||
|
LOGGER.debug("Found user: {}", user);
|
||||||
|
if (user == null) {
|
||||||
|
return new org.springframework.security.core.userdetails.User(" ", " ", enabled, true, true, true, getAuthorities(new Integer(1)));
|
||||||
|
}
|
||||||
|
if (!user.isEnabled()) {
|
||||||
|
accountNonExpired = false;
|
||||||
|
service.deleteUser(user);
|
||||||
|
return new org.springframework.security.core.userdetails.User(" ", " ", enabled, accountNonExpired, true, true, getAuthorities(new Integer(1)));
|
||||||
|
}
|
||||||
|
return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword().toLowerCase(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(user.getRole().getRole()));
|
||||||
|
|
||||||
public UserDetails loadUserByUsername(String email)
|
} catch (Exception e) {
|
||||||
throws UsernameNotFoundException {
|
throw new RuntimeException(e);
|
||||||
boolean enabled = true;
|
}
|
||||||
boolean accountNonExpired = true;
|
}
|
||||||
boolean credentialsNonExpired = true;
|
|
||||||
boolean accountNonLocked = true;
|
|
||||||
try {
|
|
||||||
LOGGER.debug("Loading user by username: {}", email);
|
|
||||||
User user = userRepository.findByEmail(email);
|
|
||||||
// OCT 21
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
LOGGER.debug("Found user: {}", user);
|
|
||||||
if (user == null) {
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
|
||||||
" ", " ", enabled, true, true, true,
|
|
||||||
getAuthorities(new Integer(1)));
|
|
||||||
}
|
|
||||||
// OCT 21
|
|
||||||
if (!(user.getVerificationToken().isVerified())) {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
// OCT 21
|
|
||||||
if ((user.getVerificationToken().isVerified())
|
|
||||||
&& (user.getVerificationToken().getExpiryDate().getTime() - cal
|
|
||||||
.getTime().getTime()) <= 0) {
|
|
||||||
userRepository.delete(user);
|
|
||||||
// DEBUGGING
|
|
||||||
System.out.println("Deleted");
|
|
||||||
|
|
||||||
accountNonExpired = false;
|
private Collection<? extends GrantedAuthority> getAuthorities(Integer role) {
|
||||||
}
|
List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(role));
|
||||||
return new org.springframework.security.core.userdetails.User(
|
return authList;
|
||||||
user.getEmail(), user.getPassword().toLowerCase(), enabled,
|
}
|
||||||
accountNonExpired, credentialsNonExpired, accountNonLocked,
|
|
||||||
getAuthorities(user.getRole().getRole()));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
public List<String> getRoles(Integer role) {
|
||||||
throw new RuntimeException(e);
|
List<String> roles = new ArrayList<String>();
|
||||||
}
|
if (role.intValue() == 2) {
|
||||||
}
|
roles.add("ROLE_ADMIN");
|
||||||
|
} else if (role.intValue() == 1) {
|
||||||
|
roles.add("ROLE_USER");
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
private Collection<? extends GrantedAuthority> getAuthorities(Integer role) {
|
private static List<GrantedAuthority> getGrantedAuthorities(List<String> roles) {
|
||||||
List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(role));
|
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||||
return authList;
|
for (String role : roles) {
|
||||||
}
|
authorities.add(new SimpleGrantedAuthority(role));
|
||||||
|
}
|
||||||
public List<String> getRoles(Integer role) {
|
return authorities;
|
||||||
List<String> roles = new ArrayList<String>();
|
}
|
||||||
|
|
||||||
if (role.intValue() == 2) {
|
|
||||||
roles.add("ROLE_ADMIN");
|
|
||||||
|
|
||||||
} else if (role.intValue() == 1) {
|
|
||||||
roles.add("ROLE_USER");
|
|
||||||
}
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<GrantedAuthority> getGrantedAuthorities(
|
|
||||||
List<String> roles) {
|
|
||||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
|
||||||
for (String role : roles) {
|
|
||||||
authorities.add(new SimpleGrantedAuthority(role));
|
|
||||||
}
|
|
||||||
return authorities;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,33 +13,31 @@ import org.springframework.core.env.Environment;
|
|||||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages = { "org.baeldung.event.service",
|
@ComponentScan(basePackages = { "org.baeldung.event.service", "org.baeldung.event", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" })
|
||||||
"org.baeldung.event", "org.baeldung.persistence.service",
|
|
||||||
"org.baeldung.persistence.dao" })
|
|
||||||
@Import({ MvcConfig.class, PersistenceJPAConfig.class, SecSecurityConfig.class })
|
@Import({ MvcConfig.class, PersistenceJPAConfig.class, SecSecurityConfig.class })
|
||||||
@PropertySource("classpath:application.properties")
|
@PropertySource("classpath:application.properties")
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment env;
|
private Environment env;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
|
public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
|
||||||
return new PropertySourcesPlaceholderConfigurer();
|
return new PropertySourcesPlaceholderConfigurer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JavaMailSenderImpl javaMailSenderImpl() {
|
public JavaMailSenderImpl javaMailSenderImpl() {
|
||||||
JavaMailSenderImpl mailSenderImpl = new JavaMailSenderImpl();
|
JavaMailSenderImpl mailSenderImpl = new JavaMailSenderImpl();
|
||||||
mailSenderImpl.setHost(env.getProperty("smtp.host"));
|
mailSenderImpl.setHost(env.getProperty("smtp.host"));
|
||||||
mailSenderImpl.setPort(env.getProperty("smtp.port", Integer.class));
|
mailSenderImpl.setPort(env.getProperty("smtp.port", Integer.class));
|
||||||
mailSenderImpl.setProtocol(env.getProperty("smtp.protocol"));
|
mailSenderImpl.setProtocol(env.getProperty("smtp.protocol"));
|
||||||
mailSenderImpl.setUsername(env.getProperty("smtp.username"));
|
mailSenderImpl.setUsername(env.getProperty("smtp.username"));
|
||||||
mailSenderImpl.setPassword(env.getProperty("smtp.password"));
|
mailSenderImpl.setPassword(env.getProperty("smtp.password"));
|
||||||
Properties javaMailProps = new Properties();
|
Properties javaMailProps = new Properties();
|
||||||
javaMailProps.put("mail.smtp.auth", true);
|
javaMailProps.put("mail.smtp.auth", true);
|
||||||
javaMailProps.put("mail.smtp.starttls.enable", true);
|
javaMailProps.put("mail.smtp.starttls.enable", true);
|
||||||
mailSenderImpl.setJavaMailProperties(javaMailProps);
|
mailSenderImpl.setJavaMailProperties(javaMailProps);
|
||||||
return mailSenderImpl;
|
return mailSenderImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,8 +22,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|||||||
import org.springframework.web.servlet.view.JstlView;
|
import org.springframework.web.servlet.view.JstlView;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages = { "org.baeldung.web.controller", "org.baeldung.persistence.service",
|
@ComponentScan(basePackages = { "org.baeldung.web.controller", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" })
|
||||||
"org.baeldung.persistence.dao" })
|
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package org.baeldung.web.controller;
|
package org.baeldung.web.controller;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import org.baeldung.event.Registration;
|
|
||||||
import org.baeldung.persistence.model.User;
|
import org.baeldung.persistence.model.User;
|
||||||
import org.baeldung.persistence.model.VerificationToken;
|
import org.baeldung.persistence.model.VerificationToken;
|
||||||
import org.baeldung.persistence.service.UserDto;
|
import org.baeldung.persistence.service.UserDto;
|
||||||
import org.baeldung.persistence.service.IUserService;
|
import org.baeldung.persistence.service.IUserService;
|
||||||
|
import org.baeldung.event.OnRegistrationCompleteEvent;
|
||||||
import org.baeldung.validation.service.EmailExistsException;
|
import org.baeldung.validation.service.EmailExistsException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -26,84 +28,77 @@ import org.springframework.web.servlet.ModelAndView;
|
|||||||
@Controller
|
@Controller
|
||||||
public class RegistrationController {
|
public class RegistrationController {
|
||||||
|
|
||||||
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||||
private IUserService service;
|
private IUserService service;
|
||||||
@Autowired
|
|
||||||
private MessageSource messages;
|
@Autowired
|
||||||
@Autowired
|
private MessageSource messages;
|
||||||
private JavaMailSender mailSender;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Registration registration;
|
private JavaMailSender mailSender;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RegistrationController(IUserService service) {
|
public RegistrationController(IUserService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/user/registration", method = RequestMethod.GET)
|
@RequestMapping(value = "/user/registration", method = RequestMethod.GET)
|
||||||
public String showRegistrationForm(WebRequest request, Model model) {
|
public String showRegistrationForm(WebRequest request, Model model) {
|
||||||
LOGGER.debug("Rendering registration page.");
|
LOGGER.debug("Rendering registration page.");
|
||||||
UserDto accountDto = new UserDto();
|
UserDto accountDto = new UserDto();
|
||||||
model.addAttribute("user", accountDto);
|
model.addAttribute("user", accountDto);
|
||||||
return "registration";
|
return "registration";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/regitrationConfirm", method = RequestMethod.GET)
|
@RequestMapping(value = "/regitrationConfirm", method = RequestMethod.GET)
|
||||||
public String confirmRegistration(WebRequest request, Model model,
|
public String confirmRegistration(WebRequest request, Model model, @RequestParam("token") String token) {
|
||||||
@RequestParam("token") String token) {
|
VerificationToken verificationToken = service.getVerificationToken(token);
|
||||||
User user = service.getUser(token);
|
if (verificationToken == null) {
|
||||||
if (user == null) {
|
model.addAttribute("message", messages.getMessage("auth.message.invalidToken", null, request.getLocale()));
|
||||||
model.addAttribute("message", messages.getMessage(
|
return "redirect:/badUser.html?lang=" + request.getLocale().getLanguage();
|
||||||
"auth.message.invalidUser", null, request.getLocale()));
|
|
||||||
return "redirect:/badUser.html?lang="
|
|
||||||
+ request.getLocale().getLanguage();
|
|
||||||
}
|
|
||||||
|
|
||||||
VerificationToken verificationToken = user.getVerificationToken();
|
}
|
||||||
if (!verificationToken.getToken().equals(token)) {
|
User user = verificationToken.getUser();
|
||||||
model.addAttribute("message", messages.getMessage(
|
Calendar cal = Calendar.getInstance();
|
||||||
"auth.message.invalidToken", null, request.getLocale()));
|
if (user == null) {
|
||||||
return "redirect:/badUser.html?lang="
|
model.addAttribute("message", messages.getMessage("auth.message.invalidUser", null, request.getLocale()));
|
||||||
+ request.getLocale().getLanguage();
|
return "redirect:/badUser.html?lang=" + request.getLocale().getLanguage();
|
||||||
}
|
}
|
||||||
user.getVerificationToken().setVerified(true);
|
if ((verificationToken.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
|
||||||
service.verifyRegisteredUser(user);
|
user.setEnabled(false);
|
||||||
return "redirect:/login.html?lang=" + request.getLocale().getLanguage();
|
} else {
|
||||||
}
|
user.setEnabled(true);
|
||||||
|
}
|
||||||
|
service.saveRegisteredUser(user);
|
||||||
|
return "redirect:/login.html?lang=" + request.getLocale().getLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
|
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
|
||||||
public ModelAndView registerUserAccount(
|
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto accountDto, BindingResult result, WebRequest request, Errors errors) {
|
||||||
@ModelAttribute("user") @Valid UserDto accountDto,
|
LOGGER.debug("Registering user account with information: {}", accountDto);
|
||||||
BindingResult result, WebRequest request, Errors errors) {
|
User registered = new User();
|
||||||
|
String appUrl = request.getContextPath();
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
return new ModelAndView("registration", "user", accountDto);
|
||||||
|
}
|
||||||
|
registered = createUserAccount(accountDto);
|
||||||
|
if (registered == null) {
|
||||||
|
result.rejectValue("email", "message.regError");
|
||||||
|
}
|
||||||
|
eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl));
|
||||||
|
return new ModelAndView("successRegister", "user", accountDto);
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER.debug("Registering user account with information: {}",
|
private User createUserAccount(UserDto accountDto) {
|
||||||
accountDto);
|
User registered = null;
|
||||||
User registered = new User();
|
try {
|
||||||
String appUrl = request.getContextPath();
|
registered = service.registerNewUserAccount(accountDto);
|
||||||
if (!result.hasErrors())
|
} catch (EmailExistsException e) {
|
||||||
registered = createUserAccount(accountDto, result);
|
return null;
|
||||||
if (registered == null) {
|
}
|
||||||
result.rejectValue("email", "message.regError");
|
return registered;
|
||||||
}
|
}
|
||||||
if (result.hasErrors()) {
|
|
||||||
return new ModelAndView("registration", "user", accountDto);
|
|
||||||
} else {
|
|
||||||
registration.setAppUrl(appUrl);
|
|
||||||
registration.setLocale(request.getLocale());
|
|
||||||
registration.setUser(registered);
|
|
||||||
registration.deliver();
|
|
||||||
return new ModelAndView("successRegister", "user", accountDto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private User createUserAccount(UserDto accountDto, BindingResult result) {
|
|
||||||
User registered = null;
|
|
||||||
try {
|
|
||||||
registered = service.registerNewUserAccount(accountDto);
|
|
||||||
|
|
||||||
} catch (EmailExistsException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return registered;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,6 @@ hibernate.hbm2ddl.auto=create-drop
|
|||||||
smtp.host=smtp.gmail.com
|
smtp.host=smtp.gmail.com
|
||||||
smtp.port=465
|
smtp.port=465
|
||||||
smtp.protocol=smtps
|
smtp.protocol=smtps
|
||||||
smtp.username=
|
smtp.username=xxx@gmail.com
|
||||||
smtp.password=
|
smtp.password=
|
||||||
support.email=
|
support.email=xxx@gmail.com
|
||||||
|
@ -34,8 +34,8 @@ label.pages.logout=Salir
|
|||||||
label.pages.admin=Administrador
|
label.pages.admin=Administrador
|
||||||
label.pages.home.title=Inicio
|
label.pages.home.title=Inicio
|
||||||
label.pages.home.message=Bienveni@ a Casa
|
label.pages.home.message=Bienveni@ a Casa
|
||||||
label.pages.admin.message=Bienvenido Admin
|
label.pages.admin.message=Bienvenid@ Admin
|
||||||
label.pages.user.message=Bienvenido Usuario
|
label.pages.user.message=Bienvenid@ Usuari@
|
||||||
label.successRegister.title=Registro Exitoso
|
label.successRegister.title=Registro Exitoso
|
||||||
label.badUser.title=Enlace Invalido
|
label.badUser.title=Enlace Invalido
|
||||||
ValidEmail.user.email=Cuenta correo invlida!
|
ValidEmail.user.email=Cuenta correo invlida!
|
||||||
|
@ -13,7 +13,8 @@ code="label.badUser.title"></spring:message></title>
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>
|
<h1>
|
||||||
${message}
|
<div class="alert alert-error">
|
||||||
|
${param.message}
|
||||||
</h1>
|
</h1>
|
||||||
<br>
|
<br>
|
||||||
<a href="<c:url value="/user/registration" />"><spring:message
|
<a href="<c:url value="/user/registration" />"><spring:message
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
|
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<sec:authorize access="hasRole('ROLE_USER')">
|
<sec:authorize access="hasRole('ROLE_USER')">
|
||||||
<spring:message code="label.pages.user.message"></spring:message>
|
<spring:message code="label.pages.user.message"></spring:message>
|
||||||
@ -19,6 +21,7 @@
|
|||||||
<spring:message code="label.pages.admin.message"></spring:message>
|
<spring:message code="label.pages.admin.message"></spring:message>
|
||||||
<br />
|
<br />
|
||||||
</sec:authorize>
|
</sec:authorize>
|
||||||
|
${param.user}
|
||||||
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
|
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
|
||||||
code="label.pages.logout"></spring:message></a> <a
|
code="label.pages.logout"></spring:message></a> <a
|
||||||
href="<c:url value="/home.html" />"><spring:message
|
href="<c:url value="/home.html" />"><spring:message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user