forked from gergely/calendar-social
Add a view for the first steps after the initial login
This commit is contained in:
@@ -109,6 +109,20 @@ class CalendarSocialApp(Flask):
|
||||
|
||||
self.route(*args, **kwargs)(attr)
|
||||
|
||||
self.before_request(self.goto_first_steps)
|
||||
|
||||
@staticmethod
|
||||
def goto_first_steps():
|
||||
"""Check if the current user has a profile and if not, redirect to the first steps page
|
||||
"""
|
||||
|
||||
if current_user.is_authenticated and \
|
||||
not current_user.profile and \
|
||||
request.endpoint != 'first_steps':
|
||||
return redirect(url_for('first_steps'))
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def timezone(self):
|
||||
"""The default time zone of the app
|
||||
@@ -358,5 +372,32 @@ class CalendarSocialApp(Flask):
|
||||
|
||||
return redirect(url_for('event_details', event_uuid=invitation.event.event_uuid))
|
||||
|
||||
@staticmethod
|
||||
@route('/first-steps', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def first_steps():
|
||||
"""View to set up a new registrant’s profile
|
||||
"""
|
||||
|
||||
from .forms import FirstStepsForm
|
||||
from .models import db, Profile
|
||||
|
||||
if current_user.profile:
|
||||
return redirect(url_for('hello'))
|
||||
|
||||
form = FirstStepsForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
profile = Profile(user=current_user, display_name=form.display_name.data)
|
||||
db.session.add(profile)
|
||||
|
||||
current_user.settings['timezone'] = str(form.time_zone.data)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('hello'))
|
||||
|
||||
return render_template('first-steps.html', form=form)
|
||||
|
||||
|
||||
app = CalendarSocialApp(__name__)
|
||||
|
Reference in New Issue
Block a user