Example #1
0
def users(current = -1):
    if current >= 0:
        users = User.query.all()
        user = User.query.filter(User.user_id == current).first()
        profileform = ProfileForm(obj=user)

        if request.method == 'POST' and profileform.validate_on_submit():
            if profileform.delete.data:
                user.deleted = True

            else:
                if profileform.undelete.data:
                    user.deleted = False

                user.fullname = profileform.fullname.data

                if profileform.password.data:
                    user.password = bcrypt.generate_password_hash(profileform.password.data)

            db.session.commit()
            return redirect('/users/edit/' + str(current))

        return render_custom_template('users.html', users=users, profileform=profileform, current=current)
    else:
        users = User.query.all()
        profileform = ProfileForm()

        if request.method == 'POST' and profileform.validate_on_submit():
            user = User(
                -1,
                profileform.username.data,
                bcrypt.generate_password_hash(profileform.password.data),
                profileform.fullname.data
            )
            db.session.add(user)
            db.session.commit()
            return redirect('/users')

        return render_custom_template('users.html', users=users, profileform=profileform, current=current)
Example #2
0
def profile():
    user = User.query.filter(User.user_id == current_user.user_id).first()

    profileform = ProfileForm(obj=user)

    if request.method == 'POST' and profileform.validate_on_submit():
        user.fullname = profileform.fullname.data

        if profileform.password.data:
            user.password = bcrypt.generate_password_hash(profileform.password.data)

        db.session.commit()
        #login_user(User(user.user_id, user.username, user.password))

        return redirect('/profile')
    else:
        return render_custom_template('profile.html', profileform=profileform)