Exemplo n.º 1
0
 def __call__(self, form, field):
     u = User.query.filter(
         func.lower(User.username) == func.lower(field.data)).first()
     if not u:
         raise ValidationError(self.message_username)
     elif not verify_password(u.password, form[self.pw_field].data):
         raise ValidationError(self.message_password)
Exemplo n.º 2
0
 def __call__(self, form, field):
     u = User.query.filter(
         func.lower(User.username) == func.lower(field.data)).first()
     if not u:
         raise ValidationError(self.message_username)
     elif not verify_password(u.password, form[self.pw_field].data):
         raise ValidationError(self.message_password)
Exemplo n.º 3
0
 def __call__(self, form, field):
     u = models.User.query.filter_by(username = field.data).first()
     if not u:
         raise ValidationError(self.message_username)
     elif not utils.verify_password(u.password, form[self.pw_field].data):
         raise ValidationError(self.message_password)
Exemplo n.º 4
0
def settings():
    user = current_user
    form = SettingsForm(obj=user)
    logout = False

    if form.validate_on_submit():
        user.ability_programmer = form.ability_programmer.data
        user.ability_gamedesigner = form.ability_gamedesigner.data
        user.ability_2dartist = form.ability_2dartist.data
        user.ability_3dartist = form.ability_3dartist.data
        user.ability_composer = form.ability_composer.data
        user.ability_sounddesigner = form.ability_sounddesigner.data
        user.abilities_extra = form.abilities_extra.data
        user.real_name = form.real_name.data
        user.about = form.about.data
        user.website = form.website.data
        user.pm_mode = form.pm_mode.data
        user.avatar = form.avatar.data
        user.notify_new_jam = form.notify_new_jam.data
        user.notify_jam_start = form.notify_jam_start.data
        user.notify_jam_finish = form.notify_jam_finish.data
        user.notify_game_comment = form.notify_game_comment.data
        user.notify_team_invitation = form.notify_team_invitation.data
        user.notify_newsletter = form.notify_newsletter.data

        if user.location != form.location.data and form.location.data:
            if user.setLocation(form.location.data):
                flash(f"Location was set to: {user.location_display}",
                      "success")
            else:
                flash("Could not find the location you entered.", "error")
        if not form.location.data:
            user.setLocation("")

        if form.old_password.data and form.new_password.data and form.new_password2.data:
            if not verify_password(user.password, form.old_password.data):
                flash(
                    "Your password is incorrect. The password was not changed.",
                    "error")
            else:
                user.password = hash_password(form.new_password.data)
                flash("Your password was changed", "success")

        if user.email != form.email.data and form.email.data:
            user.new_email = form.email.data
            user.is_verified = False

            same_email = User.query.filter_by(email=user.new_email).all()
            if not (len(same_email) == 0 or
                    (len(same_email) == 1 and same_email[0] == user)):
                flash(
                    "This email address is already in use by another account.",
                    "error")
                return redirect(url_for("settings"))

            body = render_template("emails/account/verification.txt",
                                   recipient=user,
                                   email_changed=True)
            mail.send_message(
                subject=f"{app.config['LONG_NAME']}: email verification",
                recipients=[user.new_email],
                body=body)

            logout = True
            flash(
                "Your email address has changed. Please check your inbox for the verification.",
                "info")

        db.session.commit()
        flash("Your settings were saved.", "success")

        if logout:
            return redirect(url_for("logout"))
        else:
            return redirect(url_for("settings"))

    return render_template('account/settings.html', form=form)
Exemplo n.º 5
0
def settings():
    user = current_user
    form = SettingsForm(obj=user)
    logout = False

    if form.validate_on_submit():
        user.ability_programmer = form.ability_programmer.data
        user.ability_gamedesigner = form.ability_gamedesigner.data
        user.ability_2dartist = form.ability_2dartist.data
        user.ability_3dartist = form.ability_3dartist.data
        user.ability_composer = form.ability_composer.data
        user.ability_sounddesigner = form.ability_sounddesigner.data
        user.abilities_extra = form.abilities_extra.data
        user.real_name = form.real_name.data
        user.about = form.about.data
        user.website = form.website.data
        user.pm_mode = form.pm_mode.data
        user.avatar = form.avatar.data
        user.notify_new_jam = form.notify_new_jam.data
        user.notify_jam_start = form.notify_jam_start.data
        user.notify_jam_finish = form.notify_jam_finish.data
        user.notify_game_comment = form.notify_game_comment.data
        user.notify_team_invitation = form.notify_team_invitation.data
        user.notify_newsletter = form.notify_newsletter.data

        if user.location != form.location.data and form.location.data:
            if user.setLocation(form.location.data):
                flash("Location was set to: " + user.location_display, "success")
            else:
                flash("Could not find the location you entered.", "error")
        if not form.location.data:
            user.setLocation("")

        if form.old_password.data and form.new_password.data and form.new_password2.data:
            if not verify_password(user.password, form.old_password.data):
                flash("Your password is incorrect. The password was not changed.", "error")
            else:
                user.password = hash_password(form.new_password.data)
                flash("Your password was changed", "success")

        if user.email != form.email.data and form.email.data:
            user.new_email = form.email.data
            user.is_verified = False

            same_email = User.query.filter_by(email=user.new_email).all()
            if not (len(same_email) == 0 or (len(same_email) == 1 and same_email[0] == user)):
                flash("This email address is already in use by another account.", "error")
                return redirect(url_for("settings"))

            body = render_template("emails/account/verification.txt", recipient=user, email_changed=True)
            mail.send_message(
                subject=app.config["LONG_NAME"] + ": eMail verification", recipients=[user.new_email], body=body
            )

            logout = True
            flash("Your email address has changed. Please check your inbox for the verification.", "info")

        db.session.commit()
        flash("Your settings were saved.", "success")

        if logout:
            return redirect(url_for("logout"))
        else:
            return redirect(url_for("settings"))

    return render_template("account/settings.html", form=form)