Search in sources :

Example 1 with ActivationKeySpammer

use of net.jforum.util.mail.ActivationKeySpammer in project jforum2 by rafaelsteil.

the class UserAction method insertSave.

public void insertSave() {
    UserSession userSession = SessionFacade.getUserSession();
    int userId = userSession.getUserId();
    if ((!SystemGlobals.getBoolValue(ConfigKeys.REGISTRATION_ENABLED) && !SecurityRepository.get(userId).canAccess(SecurityConstants.PERM_ADMINISTRATION)) || ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
        this.registrationDisabled();
        return;
    }
    User u = new User();
    UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
    String username = this.request.getParameter("username");
    String password = this.request.getParameter("password");
    String email = this.request.getParameter("email");
    String captchaResponse = this.request.getParameter("captchaResponse");
    boolean error = false;
    if (username == null || username.trim().equals("") || password == null || password.trim().equals("")) {
        this.context.put("error", I18n.getMessage("UsernamePasswordCannotBeNull"));
        error = true;
    }
    if (username != null) {
        username = username.trim();
    }
    if (!error && username.length() > SystemGlobals.getIntValue(ConfigKeys.USERNAME_MAX_LENGTH)) {
        this.context.put("error", I18n.getMessage("User.usernameTooBig"));
        error = true;
    }
    if (!error && username.indexOf('<') > -1 || username.indexOf('>') > -1) {
        this.context.put("error", I18n.getMessage("User.usernameInvalidChars"));
        error = true;
    }
    if (!error && dao.isUsernameRegistered(username)) {
        this.context.put("error", I18n.getMessage("UsernameExists"));
        error = true;
    }
    if (!error && dao.findByEmail(email) != null) {
        this.context.put("error", I18n.getMessage("User.emailExists", new String[] { email }));
        error = true;
    }
    if (!error && !userSession.validateCaptchaResponse(captchaResponse)) {
        this.context.put("error", I18n.getMessage("CaptchaResponseFails"));
        error = true;
    }
    if (error) {
        this.insert(true);
        return;
    }
    u.setUsername(username);
    u.setPassword(MD5.crypt(password));
    u.setEmail(email);
    boolean requiresMailActivation = SystemGlobals.getBoolValue(ConfigKeys.MAIL_USER_EMAIL_AUTH);
    if (requiresMailActivation) {
        u.setActivationKey(MD5.crypt(username + System.currentTimeMillis()));
    }
    int newUserId = dao.addNew(u);
    if (requiresMailActivation) {
        Executor.execute(new EmailSenderTask(new ActivationKeySpammer(u)));
        this.setTemplateName(TemplateKeys.USER_INSERT_ACTIVATE_MAIL);
        this.context.put("message", I18n.getMessage("User.GoActivateAccountMessage"));
    } else if (SecurityRepository.get(userId).canAccess(SecurityConstants.PERM_ADMINISTRATION)) {
        JForumExecutionContext.setRedirect(this.request.getContextPath() + "/adminUsers/list" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    } else {
        this.logNewRegisteredUserIn(newUserId, u);
    }
    if (!requiresMailActivation) {
        dao.writeUserActive(newUserId);
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) ActivationKeySpammer(net.jforum.util.mail.ActivationKeySpammer) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) UserSession(net.jforum.entities.UserSession)

Aggregations

UserDAO (net.jforum.dao.UserDAO)1 User (net.jforum.entities.User)1 UserSession (net.jforum.entities.UserSession)1 ActivationKeySpammer (net.jforum.util.mail.ActivationKeySpammer)1 EmailSenderTask (net.jforum.util.mail.EmailSenderTask)1