<commit_before>/**
 *
 */
package com.bloatit.web.linkable.login;

import java.util.Locale;

import com.bloatit.framework.mailsender.Mail;
import com.bloatit.framework.mailsender.MailServer;
import com.bloatit.framework.utils.MailUtils;
import com.bloatit.framework.webprocessor.annotations.Optional;
import com.bloatit.framework.webprocessor.annotations.ParamConstraint;
import com.bloatit.framework.webprocessor.annotations.ParamContainer;
import com.bloatit.framework.webprocessor.annotations.RequestParam;
import com.bloatit.framework.webprocessor.annotations.RequestParam.Role;
import com.bloatit.framework.webprocessor.annotations.tr;
import com.bloatit.framework.webprocessor.context.Context;
import com.bloatit.framework.webprocessor.masters.Action;
import com.bloatit.framework.webprocessor.url.Url;
import com.bloatit.model.Member;
import com.bloatit.model.managers.MemberManager;
import com.bloatit.web.url.MemberActivationActionUrl;
import com.bloatit.web.url.SignUpActionUrl;
import com.bloatit.web.url.SignUpPageUrl;

/**
 * A response to a form used sign into the website (creation of a new user)
 */
@ParamContainer("member/dosignup")
public class SignUpAction extends Action {
    @RequestParam(name = "bloatit_login", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for login has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for login has to be inferior to 15"))
    private final String login;

    @RequestParam(name = "bloatit_password", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for password has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    private final String password;

    @RequestParam(name = "bloatit_password_check", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for password has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    private final String passwordCheck;

    @RequestParam(name = "bloatit_fullname", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for fullname has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    @Optional
    private final String fullname;

    @RequestParam(name = "bloatit_email", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for email has to be superior to 5"),//
    max = "30", maxErrorMsg = @tr("Number of characters for email address has to be inferior to 30"))
    private final String email;

    @RequestParam(name = "bloatit_country", role = Role.POST)
    private final String country;

    @RequestParam(name = "bloatit_lang", role = Role.POST)
    private final String lang;

    private final SignUpActionUrl url;

    public SignUpAction(final SignUpActionUrl url) {
        super(url);
        this.url = url;
        this.login = url.getLogin();
        this.password = url.getPassword();
        this.passwordCheck = url.getPasswordCheck();
        this.fullname = url.getFullname();
        this.email = url.getEmail();
        this.lang = url.getLang();
        this.country = url.getCountry();
    }

    @Override
    protected final Url doProcess() {
        if (password != passwordCheck) {
            transmitParameters();
            session.notifyError("Password doesn't match confirmation.");
            return new SignUpPageUrl();
        }

        final Locale locale = new Locale(lang, country);
        final Member m = new Member(login, password, email, fullname, locale);
        final String activationKey = m.getActivationKey();
        final MemberActivationActionUrl url = new MemberActivationActionUrl(login, activationKey);

        final String content = Context.tr("Your Elveos.org account ''{0}'' was created. Please click on the following link to activate your account: \n\n {1}",
                                          login,
                                          url.externalUrlString(Context.getHeader().getHttpHeader()));

        final Mail activationMail = new Mail(email, Context.tr("Elveos.org account activation"), content, "member-docreate");

        MailServer.getInstance().send(activationMail);

        session.notifyGood(Context.tr("Account created, you will receive a mail to activate it."));

        return session.pickPreferredPage();
    }

    @Override
    protected final Url doProcessErrors() {
        return new SignUpPageUrl();
    }

    @Override
    protected Url checkRightsAndEverything() {
        if (MemberManager.loginExists(login)) {
            session.notifyError(Context.tr("Login ''{0}''already used. Find another login", login));
            return doProcessErrors();
        }

        if (MemberManager.emailExists(email)) {
            session.notifyError(Context.tr("Email ''{0}''already used. Find another email or use your old account !", email));
            return doProcessErrors();
        }

        final String userEmail = email.trim();
        if (!MailUtils.isValidEmail(userEmail)) {
            session.notifyError(Context.tr("Invalid email address : " + userEmail));
            return doProcessErrors();
        }
        return NO_ERROR;
    }

    @Override
    protected void transmitParameters() {
        session.addParameter(url.getEmailParameter());
        session.addParameter(url.getLoginParameter());
        session.addParameter(url.getPasswordParameter());
        session.addParameter(url.getCountryParameter());
        session.addParameter(url.getLangParameter());
        session.addParameter(url.getFullnameParameter());
        session.addParameter(url.getPasswordCheckParameter());
    }
}
<commit_msg>Fixing mistake<commit_after>/**
 *
 */
package com.bloatit.web.linkable.login;

import java.util.Locale;

import com.bloatit.framework.mailsender.Mail;
import com.bloatit.framework.mailsender.MailServer;
import com.bloatit.framework.utils.MailUtils;
import com.bloatit.framework.webprocessor.annotations.Optional;
import com.bloatit.framework.webprocessor.annotations.ParamConstraint;
import com.bloatit.framework.webprocessor.annotations.ParamContainer;
import com.bloatit.framework.webprocessor.annotations.RequestParam;
import com.bloatit.framework.webprocessor.annotations.RequestParam.Role;
import com.bloatit.framework.webprocessor.annotations.tr;
import com.bloatit.framework.webprocessor.context.Context;
import com.bloatit.framework.webprocessor.masters.Action;
import com.bloatit.framework.webprocessor.url.Url;
import com.bloatit.model.Member;
import com.bloatit.model.managers.MemberManager;
import com.bloatit.web.url.MemberActivationActionUrl;
import com.bloatit.web.url.SignUpActionUrl;
import com.bloatit.web.url.SignUpPageUrl;

/**
 * A response to a form used sign into the website (creation of a new user)
 */
@ParamContainer("member/dosignup")
public class SignUpAction extends Action {
    @RequestParam(name = "bloatit_login", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for login has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for login has to be inferior to 15"))
    private final String login;

    @RequestParam(name = "<PASSWORD>", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for password has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    private final String password;

    @RequestParam(name = "bloatit_password_check", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for password has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    private final String passwordCheck;

    @RequestParam(name = "bloatit_fullname", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for fullname has to be superior to 4"),//
    max = "15", maxErrorMsg = @tr("Number of characters for password has to be inferior to 15"))
    @Optional
    private final String fullname;

    @RequestParam(name = "bloatit_email", role = Role.POST)
    @ParamConstraint(min = "4", minErrorMsg = @tr("Number of characters for email has to be superior to 5"),//
    max = "30", maxErrorMsg = @tr("Number of characters for email address has to be inferior to 30"))
    private final String email;

    @RequestParam(name = "bloatit_country", role = Role.POST)
    private final String country;

    @RequestParam(name = "bloatit_lang", role = Role.POST)
    private final String lang;

    private final SignUpActionUrl url;

    public SignUpAction(final SignUpActionUrl url) {
        super(url);
        this.url = url;
        this.login = url.getLogin();
        this.password = url.getPassword();
        this.passwordCheck = url.getPasswordCheck();
        this.fullname = url.getFullname();
        this.email = url.getEmail();
        this.lang = url.getLang();
        this.country = url.getCountry();
    }

    @Override
    protected final Url doProcess() {
        if (!password.equals(passwordCheck)) {
            transmitParameters();
            session.notifyError("Password doesn't match confirmation.");
            return new SignUpPageUrl();
        }

        final Locale locale = new Locale(lang, country);
        final Member m = new Member(login, password, email, fullname, locale);
        final String activationKey = m.getActivationKey();
        final MemberActivationActionUrl url = new MemberActivationActionUrl(login, activationKey);

        final String content = Context.tr("Your Elveos.org account ''{0}'' was created. Please click on the following link to activate your account: \n\n {1}",
                                          login,
                                          url.externalUrlString(Context.getHeader().getHttpHeader()));

        final Mail activationMail = new Mail(email, Context.tr("Elveos.org account activation"), content, "member-docreate");

        MailServer.getInstance().send(activationMail);

        session.notifyGood(Context.tr("Account created, you will receive a mail to activate it."));

        return session.pickPreferredPage();
    }

    @Override
    protected final Url doProcessErrors() {
        return new SignUpPageUrl();
    }

    @Override
    protected Url checkRightsAndEverything() {
        if (MemberManager.loginExists(login)) {
            session.notifyError(Context.tr("Login ''{0}''already used. Find another login", login));
            return doProcessErrors();
        }

        if (MemberManager.emailExists(email)) {
            session.notifyError(Context.tr("Email ''{0}''already used. Find another email or use your old account !", email));
            return doProcessErrors();
        }

        final String userEmail = email.trim();
        if (!MailUtils.isValidEmail(userEmail)) {
            session.notifyError(Context.tr("Invalid email address : " + userEmail));
            return doProcessErrors();
        }
        return NO_ERROR;
    }

    @Override
    protected void transmitParameters() {
        session.addParameter(url.getEmailParameter());
        session.addParameter(url.getLoginParameter());
        session.addParameter(url.getPasswordParameter());
        session.addParameter(url.getCountryParameter());
        session.addParameter(url.getLangParameter());
        session.addParameter(url.getFullnameParameter());
        session.addParameter(url.getPasswordCheckParameter());
    }
}

{'fraction_non_alphanumeric': 0.11034716917069859, 'fraction_numerical': 0.005772005772005772, 'mean_word_length': 3.375046416635722, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404811', 'n_tokens_mistral': 3248, 'n_tokens_neox': 3153, 'n_words': 868}