Пример #1
0
def reset_verify(username, token):
    user = User.query.filter_by(username=username).first_or_404()
    if user.token is None:
        flash(f"{user.username}'s account has not requested a password reset.",
              "error")
        return redirect(url_for('index'))
    if user.getResetToken() != token:
        flash(
            "This does not seem to be a valid reset link, if you reset your account multiple "
            "times make sure you are using the link in the last email you received!",
            "error")
        return redirect(url_for('index'))
    form = NewPassword()
    error = None
    if form.validate_on_submit():
        # null the reset token
        user.token = None
        # set the new password
        user.password = hash_password(form.password.data)
        db.session.commit()
        flash("Your password was updated and you can login with it now.",
              "success")
        return redirect(url_for('login'))
    return render_template('account/reset_newpassword.html',
                           user=user,
                           form=form,
                           error=error)
Пример #2
0
 def __init__(self, username, password, email, is_admin = False, is_verified = False):
     self.username = username
     self.password = hash_password(password)
     self.email = email
     self.new_email = email
     self.is_admin = is_admin
     self.is_verified = is_verified
     self.registered = datetime.utcnow()
Пример #3
0
 def __init__(self, username, password, email, is_admin=False, is_verified=False):
     self.username = username
     self.password = hash_password(password)
     self.email = email
     self.new_email = email
     self.is_admin = is_admin
     self.is_verified = is_verified
     self.registered = datetime.utcnow()
Пример #4
0
def reset_verify(username, token):
    user = User.query.filter_by(username=username).first_or_404()
    if user.token == None:
        flash("%s's account has not requested a password reset." % user.username.capitalize(), "error")
        return redirect(url_for('index'))
    if user.getResetToken() != token:
        flash("This does not seem to be a valid reset link, if you reset your account multiple times make sure you are using the link in the last email you received!", "error")
        return redirect(url_for('index'))
    form = NewPassword()
    error = None
    if form.validate_on_submit():
        # null the reset token
        user.token = None
        # set the new password
        user.password = hash_password(form.password.data)
        db.session.commit()
        flash("Your password was updated and you can login with it now.", "success")
        return redirect(url_for('login'))
    return render_template('account/reset_newpassword.html', user = user, form = form, error = error)
Пример #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(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)
Пример #6
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)