Beispiel #1
0
def account():
    username_form = UpdateUsernameForm()
    password_form = UpdatePasswordForm()
    profile_pic_form = UpdateProfilePicForm()

    if password_form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            password_form.new_password.data).decode("utf-8")

        msg = Message('Password Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your password has been updated! Please reply to this e-mail if you did not request this change."
        mail.send(msg)

        current_user.modify(password=hashed)
        current_user.save()

        return redirect(url_for('users.account'))

    if username_form.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        current_user.username = username_form.username.data

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('users.account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('users.account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           password_form=password_form,
                           profile_pic_form=profile_pic_form,
                           image=image)
Beispiel #2
0
def account():
    username_form = UpdateUsernameForm()

    if username_form.validate_on_submit():
        # current_user.username = username_form.username.data
        mongo_lock.acquire()
        current_user.modify(username=username_form.username.data)
        current_user.save()
        mongo_lock.release()
        return redirect(url_for('users.account'))

    mongo_lock.acquire()
    user = User.objects(username=current_user.username).first()
    mongo_lock.release()

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           user=user)
def account():
    username_form = UpdateUsernameForm()
    profile_pic_form = UpdateProfilePicForm()

    if username_form.validate_on_submit():
        # current_user.username = username_form.username.data

        temp = User.objects(username=current_user.username).first()

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           profile_pic_form=profile_pic_form,
                           image=image)