def validate_email(email):
    regex = re.compile("[^@]+@[^@]+\.[^@]+")
    if not regex.fullmatch(email):
        raise GraphQLError(_("The email you entered is invalid."))
    db_user = ModelUserAccount.find_by_email(email)
    if db_user:
        raise GraphQLError(_("There already exists a user with that email."))
Exemplo n.º 2
0
 def mutate(self, info, **kwargs):
     if current_user.is_authenticated:
         raise GraphQLError(_("You are already logged in."))
     email = kwargs.get("email")
     password = kwargs.get("password")
     remember = kwargs.get("remember")
     user = ModelUserAccount.find_by_email(email)
     auth_error = GraphQLError(_("Invalid username or password."))
     if not user:
         raise auth_error
     if not user.check_password(password):
         raise auth_error
     login_user(user, remember=remember)
     refresh()
     with session_scope() as db_session:
         save_custom_sets(db_session)
     return LoginUser(user=user, ok=True)
Exemplo n.º 3
0
 def mutate(self, info, **kwargs):
     if current_user.is_authenticated:
         raise GraphQLError(_("You are already logged in."))
     email = kwargs.get("email")
     user = ModelUserAccount.find_by_email(email)
     auth_error = GraphQLError(
         _("We could not find an account with that email."))
     if not user:
         raise auth_error
     if not user.verified:
         raise GraphQLError(_("Please verify your email first."))
     token = encode_token(user.email, reset_password_salt)
     reset_password_url = "{}reset-password?token={}".format(
         base_url, token)
     template = template_env.get_template("reset_password.html")
     content = template.render(display_name=user.username,
                               reset_password_url=reset_password_url)
     q.enqueue(send_email, user.email, _("Reset your DofusLab password"),
               content)
     return RequestPasswordReset(ok=True)
Exemplo n.º 4
0
    def mutate(self, info, **kwargs):
        if current_user.is_authenticated:
            raise GraphQLError(_("You are already logged in."))
        token = kwargs.get("token")
        password = kwargs.get("password")
        email = decode_token(token, reset_password_salt)
        invalid_token_error = GraphQLError(
            _("The link is invalid or expired. Please request a new one."))
        if not email:
            raise invalid_token_error
        user = ModelUserAccount.find_by_email(email)

        if not user:
            raise GraphQLError(
                _("The link is invalid or expired. Please request a new one."))

        validation.validate_password(password)
        if user.check_password(password):
            raise GraphQLError(
                _("You must enter a password different from your current one.")
            )
        with session_scope() as db_session:
            user.password = ModelUserAccount.generate_hash(password)
            return ResetPassword(ok=True)