Пример #1
0
def profile():
    profile = UserProfile.query.filter_by(user_id=current_user.id).first()
    form = ProfileForm(obj=profile)
    if form.validate_on_submit():
        if profile:
            form.populate_obj(profile)
            db.session.commit()

            flash('Profile Information has been saved!')
            return redirect(url_for('account'))
        new_profile = UserProfile(user_id=current_user.id,
                                  first_name=form.first_name.data,
                                  last_name=form.last_name.data,
                                  birth_date=form.birth_date.data,
                                  address_1=form.address_1.data,
                                  address_2=form.address_2.data,
                                  city=form.city.data,
                                  state=form.state.data,
                                  zip=form.zip.data)

        db.session.add(new_profile)
        db.session.commit()

        flash('Profile Information has been saved!')
        return redirect(url_for('account'))
    return render_template('profile.html', form=form)
Пример #2
0
def settings():
    form = ProfileForm(request.form, current_user)
    if request.method == 'POST' and form.validate():
        form.populate_obj(current_user)
        current_user.password = encrypt_password(current_user.password)
        db.session.commit()
        return redirect('/')
    else:
        return render_template('profile.html', form=form, profile=current_user)