proxadmin/app/settings/routes.py

54 lines
2.1 KiB
Python
Raw Normal View History

2017-03-13 09:36:21 -04:00
from flask import render_template, redirect, request, url_for, flash, session, abort, current_app
from flask_login import login_required, login_user, logout_user, current_user
from sqlalchemy import desc
from . import settings
2017-05-07 21:33:42 -04:00
from .forms import EditProfileForm, EditProfileAdminForm
2017-03-13 09:36:21 -04:00
from ..email import send_email
from .. import db
2017-05-07 21:33:42 -04:00
from ..models import User
import sys
2017-03-13 09:36:21 -04:00
#PROFILE
@settings.route('/profile', methods=['GET', 'POST'])
@login_required
def profile():
page = { 'title': 'Edit Profile' }
form = EditProfileForm()
if form.validate_on_submit():
current_user.name = form.name.data
current_user.address = form.address.data
current_user.city = form.city.data
current_user.postcode = form.postcode.data
current_user.country = form.country.data
current_user.phone = form.phone.data
2017-05-13 05:46:43 -04:00
current_user.org_account = form.org_account.data
current_user.org_companyname = form.org_companyname.data
current_user.org_regaddress = form.org_regaddress.data
2017-03-13 09:36:21 -04:00
current_user.org_responsible = form.org_responsible.data
2017-05-13 05:46:43 -04:00
current_user.org_vatnum = form.org_vatnum.data
2017-03-13 09:36:21 -04:00
current_user.twofactor = form.twofactor.data
db.session.add(current_user)
db.session.commit()
flash('Info Updated!')
form.name.data = current_user.name
form.address.data = current_user.address
form.city.data = current_user.city
form.postcode.data = current_user.postcode
form.country.data = current_user.country
form.phone.data = current_user.phone
2017-05-13 05:46:43 -04:00
form.org_account.data = current_user.org_account
form.org_companyname.data = current_user.org_companyname
form.org_regaddress.data = current_user.org_regaddress
2017-03-13 09:36:21 -04:00
form.org_responsible.data = current_user.org_responsible
2017-05-24 10:37:52 -04:00
form.org_vatnum.data = current_user.org_vatnum
2017-05-13 05:46:43 -04:00
form.twofactor.data = current_user.twofactor
2017-03-13 09:36:21 -04:00
2017-05-24 10:37:52 -04:00
wallet = "%.2f" % round(current_user.wallet, 3)
2017-06-13 19:24:39 -04:00
#current_app.logger.info('[{}] wallet: {}'.format(current_user.email, wallet))
2017-05-24 10:37:52 -04:00
2017-06-25 10:11:52 -04:00
return render_template('settings/profile.html', page=page, form=form, wallet=wallet, cuser=current_user)
2017-03-13 09:36:21 -04:00