Search in sources :

Example 6 with AdminUser

use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.

the class DatabaseTokens method loadTokenFromResultSet.

private VerificationToken loadTokenFromResultSet(ResultSet rs) throws SQLException {
    if (rs.next()) {
        AdminUser adminUser = databaseAdminUsers.loadAdminUser(rs.getString("AdminEmail"));
        String token = rs.getString("Token");
        return new VerificationToken(token, adminUser);
    }
    return null;
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser)

Example 7 with AdminUser

use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.

the class WebController method dashboard.

/**
 * GET request handler for serving the admin dashboard with the active user's name as a model attribute.
 * @param model
 * @return
 */
@GetMapping("/dashboard")
public String dashboard(Model model) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String email = auth.getName();
    AdminUser user = authenticationBackend.findByEmail(email);
    String name = user.getName();
    model.addAttribute("name", name);
    return "dashboard";
}
Also used : Authentication(org.springframework.security.core.Authentication) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser)

Example 8 with AdminUser

use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.

the class AuthenticationController method registerUserAccount.

@PostMapping("/registration")
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid AdminUserDTO accountDTO, BindingResult result, WebRequest request, Errors errors, Model model) {
    if (result.hasErrors()) {
        return new ModelAndView("registration", "user", accountDTO);
    }
    try {
        AdminUser registered = createUserAccount(accountDTO, result);
        String appUrl = request.getContextPath();
        eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl));
        model.addAttribute("messageType", "Registration");
        model.addAttribute("messageString", "Check your emails for a verification link!");
    } catch (EmailNotPermittedException e) {
        model.addAttribute("messageType", "Failed Registration");
        model.addAttribute("messageString", "You are not permitted to create an account.");
    } catch (EmailExistsException e) {
        model.addAttribute("messageType", "Failed Registration");
        model.addAttribute("messageString", "A user with this email address has already registered.");
    } catch (Exception e) {
        e.printStackTrace();
        model.addAttribute("messageType", "Registration Error");
        model.addAttribute("messageString", "Your registration failed!");
    }
    return new ModelAndView("message", "user", accountDTO);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException) EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) SQLException(java.sql.SQLException) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)

Example 9 with AdminUser

use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.

the class UserService method registerNewUserAccount.

@Transactional
@Override
public AdminUser registerNewUserAccount(AdminUserDTO accountDTO) throws EmailNotPermittedException, EmailExistsException, SQLException {
    if (authenticationBackend.userExists(accountDTO.getEmail())) {
        throw new EmailExistsException("There is already an account with that email address: " + accountDTO.getEmail());
    }
    if (!authenticationBackend.emailPermitted(accountDTO.getEmail())) {
        throw new EmailNotPermittedException("The following email is not on the list of permitted emails: " + accountDTO.getEmail());
    }
    AdminUser user = new AdminUser();
    user.setName(accountDTO.getName());
    user.setPassword(passwordEncoder.encode(accountDTO.getPassword()));
    user.setEmail(accountDTO.getEmail());
    user.setEnabled(false);
    authenticationBackend.addAdminUser(user);
    return user;
}
Also used : EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with AdminUser

use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.

the class RegistrationListener method confirmRegistration.

private void confirmRegistration(OnRegistrationCompleteEvent event) {
    AdminUser adminUser = event.getAdminUser();
    String token = UUID.randomUUID().toString();
    service.createVerificationToken(adminUser, token);
    String recipientAddress = adminUser.getEmail();
    String subject = "Registration Confirmation";
    String confirmationUrl = event.getAppUrl() + "/registrationConfirm?token=" + token;
    String message = "Registration Successful ";
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(recipientAddress);
    email.setSubject(subject);
    email.setText(message + "<a href=\"" + "http://localhost:8080" + confirmationUrl + "\"\\a>");
    email.setFrom(env.getProperty("support.email"));
    final Logger log = LoggerFactory.getLogger(LumberjackApplication.class);
    log.info("About to send email!");
    mailSender.send(email);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) Logger(org.slf4j.Logger)

Aggregations

AdminUser (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser)10 EmailExistsException (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)4 EmailNotPermittedException (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException)4 SQLException (java.sql.SQLException)3 MailAuthenticationException (org.springframework.mail.MailAuthenticationException)3 VerificationToken (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken)3 Logger (org.slf4j.Logger)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Calendar (java.util.Calendar)1 Authentication (org.springframework.security.core.Authentication)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 Transactional (org.springframework.transaction.annotation.Transactional)1