def create(): """ Register a new user """ # create the form form = UserAddForm(request.form, schools=[ g.school, ], next=request.args.get('next')) # submit if form.validate_on_submit(): # This is a honeypot and we act like it was successful if form.captcha.data: flash(_("Welcome to the website!"), 'success') return redirect(form.next.data or url_for('schools.home')) u = User(password=form.new_password.data) form.populate_obj(u) u.save() login_user(u) flash(_("Welcome %(user)s!", user=u.display_name), 'success') return redirect(form.next.data or url_for_school('schools.home', user_school=True)) # Our simple custom captcha implementation gotcha = 'which letter in this sentence is uppercase?' idx = randint(0, len(gotcha) - 1) form.gotcha.label = gotcha[:idx].lower() + gotcha[idx:].capitalize() session['gotcha'] = gotcha[idx] return render_template('user/create.html', title=_('Create an account'), form=form)
def detail(id): """ Show a single userproposal, redirecting to the appropriate school if necessary """ u = User.objects.get_or_404(id=id) c = get_school_context(u) if not g.school == c: flash(_("You've been redirected to the school the user is following.")) return redirect(url_for_school('users.detail', school=c, id=u.id), code=301) return render_template('user/detail.html', title=u.display_name, user=u)
def detail(id): """ Show a single userproposal, redirecting to the appropriate school if necessary """ u = User.objects.get_or_404(id=id) c = get_school_context(u) if not g.school==c: flash(_("You've been redirected to the school the user is following.")) return redirect(url_for_school('users.detail', school=c, id=u.id), code=301) return render_template('user/detail.html', title = u.display_name, user = u)
def detail(id): """ Show a detail of an event """ e = Event.objects.get_or_404(id=id) c = get_school_context(e) if not g.school==c: flash(_("You've been redirected to the school where the class is happening.")) return redirect(url_for_school('events.detail', school=c, id=e.id), code=301) # Passing some permissions related functions on to Jinja current_app.jinja_env.globals['can_edit'] = can_edit return render_template('event/detail.html', title = e.title, event = e, other_events = []) #other_events(e))
def login(): if current_user.is_authenticated(): return redirect(url_for('proposals.make')) form = LoginForm(username=request.args.get('username', None), next=request.args.get('next', None)) if form.validate_on_submit(): user, authenticated = authenticate_user(form.username.data, form.password.data) if user and authenticated: remember = request.form.get('remember') == 'y' if login_user(user, remember=remember): flash(_("Logged in"), 'success') # redirects to specified page OR the homepage for the user's school return redirect(form.next.data or url_for_school('schools.home', user_school=True)) else: flash(_('Sorry, invalid login'), 'error') return render_template('auth/login.html', title='login', form=form)
def detail(id): """ Show a single discussion, redirecting to the appropriate school if necessary """ d = Discussion.objects.get_or_404(id=id) context = get_school_context(d) if not g.school==context: flash(_("You've been redirected to where the discussion was created.")) return redirect(url_for_school('discussions.detail', school=context, id=d.id), code=301) other_schools = [school for school in d.schools if not school==context] comments = Comment.objects.filter(discussion=d).order_by('-created') # Passing some permissions related functions on to Jinja #current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal return render_template('discussion/detail.html', title = d.title, discussion = d, comments = comments, other_schools = other_schools)
def detail(id): """ Show a single proposal, redirecting to the appropriate school if necessary """ p = Proposal.objects.get_or_404(id=id) c = get_school_context(p) if not g.school==c: flash(_("You've been redirected to where the proposal was made.")) return redirect(url_for_school('proposals.detail', school=c, id=p.id), code=301) other_schools = [school for school in p.schools if not school==c] # Passing some permissions related functions on to Jinja current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal current_app.jinja_env.globals['can_organize_proposal'] = can_organize_proposal return render_template('proposal/detail.html', title = p.title, proposal = p, other_schools = other_schools, events = p.events, discussions = p.discussions)
def detail(id): """ Show a single collection, redirecting to the appropriate school if necessary """ c = Collection.objects.get_or_404(id=id) context = get_school_context(c) if not g.school==context: flash(_("You've been redirected to where the proposal was made.")) return redirect(url_for_school('collections.detail', school=context, id=c.id), code=301) other_schools = [school for school in c.schools if not school==context] # Passing some permissions related functions on to Jinja #current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal #current_app.jinja_env.globals['can_organize_proposal'] = can_organize_proposal return render_template('collection/detail.html', title = c.title, collection = c, proposals = c.all_proposals(), events = c.all_events(), other_schools = other_schools)
def detail(id): """ Show a single discussion, redirecting to the appropriate school if necessary """ d = Discussion.objects.get_or_404(id=id) context = get_school_context(d) if not g.school == context: flash(_("You've been redirected to where the discussion was created.")) return redirect(url_for_school('discussions.detail', school=context, id=d.id), code=301) other_schools = [school for school in d.schools if not school == context] comments = Comment.objects.filter(discussion=d).order_by('-created') # Passing some permissions related functions on to Jinja #current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal return render_template('discussion/detail.html', title=d.title, discussion=d, comments=comments, other_schools=other_schools)
def login(): if current_user.is_authenticated(): return redirect(url_for('proposals.make')) form = LoginForm(username=request.args.get('username', None), next=request.args.get('next', None)) if form.validate_on_submit(): user, authenticated = authenticate_user(form.username.data, form.password.data) if user and authenticated: remember = request.form.get('remember') == 'y' if login_user(user, remember=remember): flash(_("Logged in"), 'success') # redirects to specified page OR the homepage for the user's school return redirect( form.next.data or url_for_school('schools.home', user_school=True)) else: flash(_('Sorry, invalid login'), 'error') return render_template('auth/login.html', title='login', form=form)
def create(): """ Register a new user """ # create the form form = UserAddForm(request.form, schools=[g.school,], next=request.args.get('next')) # submit if form.validate_on_submit(): # This is a honeypot and we act like it was successful if form.captcha.data: flash(_("Welcome to the website!"), 'success') return redirect(form.next.data or url_for('schools.home')) u = User(password=form.new_password.data) form.populate_obj(u) u.save() login_user(u) flash(_("Welcome %(user)s!", user=u.display_name), 'success') return redirect(form.next.data or url_for_school('schools.home', user_school=True)) # Our simple custom captcha implementation gotcha = 'which letter in this sentence is uppercase?' idx = randint(0, len(gotcha)-1) form.gotcha.label = gotcha[:idx].lower() + gotcha[idx:].capitalize() session['gotcha'] = gotcha[idx] return render_template('user/create.html', title=_('Create an account'), form=form)