def confirm_reps(token='', msg=None, umi=None, user=None): """ Confirm members of congress and submit message (if message present) @param token: token to identify the user / message @type token: string @return: @rtype: """ form = forms.MessageForm(request.form, append_get_params(url_for_with_prefix('app_router.' + inspect.stack()[0][3], token=token))) moc = umi.members_of_congress context = { 'form': form, 'msg': msg, 'user': user, 'umi': umi, 'legislators': moc } if msg is not None and request.method == 'POST' and form.validate() and request.form.getlist('legislator_choices[]'): if not request.form.get('donotsend', False): legs = [moc[int(i)] for i in request.form.getlist('legislator_choices[]')] msg.queue_to_send(legs) emailer.NoReply.message_queued(user, legs, msg).send() return redirect(url_for_with_prefix('app_router.message_sent', token=token)) else: if msg is not None: form.populate_data_from_message(msg) context['legs_buckets'] = Legislator.get_leg_buckets_from_emails(umi.members_of_congress, json.loads(msg.to_originally)) return render_template_wctx('pages/confirm_reps.html', context=context)
def login(self): form = forms.LoginForm(request.form, url_for_with_prefix('.login')) if request.method == 'POST': admin = form.validate_credentials() if admin: login_user(admin) return redirect(url_for_with_prefix('.index')) return render_template_wctx('pages/admin_login.html', context={'form': form})
def token_or_redirect(**kwargs): msg, umi, user = convert_token(kwargs.get('token', '')) if user is None: return redirect(url_for_with_prefix('app_router.reset_token')) elif msg is not None and msg.needs_captcha_to_send() and viewfunc.__name__ is not 'confirm_with_recaptcha': return redirect(append_get_params(url_for_with_prefix('app_router.confirm_with_recaptcha', **kwargs))) else: kwargs.update({'msg': msg, 'umi': umi, 'user': user}) return viewfunc(**kwargs)
def token_or_redirect(**kwargs): token = kwargs.get('token', '') msg, umi, user = Token.convert_token(token) if user is None: # TODO where to redirect? return redirect(url_for_with_prefix('app_router.reset_token')) else: if msg is not None: if msg.is_already_sent() and viewfunc.__name__ is not 'message_sent': return redirect(url_for_with_prefix('app_router.message_sent', token=token)) elif not msg.is_already_sent() and user.default_info.accept_tos and viewfunc.__name__ not in ['confirm_reps', 'message_sent']: return redirect(url_for_with_prefix('app_router.confirm_reps', token=token)) kwargs.update({'msg': msg, 'umi': umi, 'user': user}) return viewfunc(**kwargs)
def update_user_address(token='', msg=None, umi=None, user=None): form = forms.RegistrationForm(request.form, app_router_path(inspect.stack()[0][3], token=token)) context = { 'form': form, 'verification_token': token, 'msg_email': user.email, 'umi': umi, 'msg': msg } if request.method == 'POST': if form.validate_and_save_to_db(user, msg=msg): district = umi.determine_district(force=True) if district is None: context['district_error'] = True else: if msg is None: token = user.token.reset() emailer.NoReply.address_changed(user).send() else: emailer.NoReply.signup_success(user, msg).send() return redirect(url_for_with_prefix('app_router.confirm_reps', token=token)) return render_template_wctx("pages/update_user_address.html", context=context)
def confirm_reps(token='', msg=None, umi=None, user=None): """ Confirm members of congress and submit message (if message present) @param token: token to identify the user / message @type token: string @return: @rtype: """ form = forms.MessageForm(request.form, append_get_params(url_for_with_prefix('app_router.' + inspect.stack()[0][3], token=token))) moc = umi.members_of_congress context = { 'form': form, 'message': msg, 'user': user, 'umi': umi, 'legislators': moc } if msg is not None and request.method == 'POST' and form.validate(): msg.queue_to_send([moc[i] for i in [v for v in range(0, len(moc)) if request.form.get('legislator_' + str(v))]]) return render_template_wctx('pages/message_sent.html', context=context) else: if msg is not None: form.populate_data_from_message(msg) context['legs_buckets'] = Legislator.get_leg_buckets_from_emails(umi.members_of_congress, json.loads(msg.to_originally)) return render_template_wctx('pages/confirm_reps.html', context=context)
def new_token(token=''): user = User.query.filter_by(tmp_token=token).first() if user is not None: user.create_tmp_token() token = user.token.reset() emailer.NoReply.successfully_reset_token(user).send() return redirect(url_for_with_prefix('app_router.update_user_address', token=token)) else: return 'No user exists for specified token.'
def reset_token(): """ View to allow user to reset their token if it becomes compromised, they can't find the link in their email, or otherwise. """ form = forms.TokenResetForm(request.form, url_for_with_prefix('app_router.' + inspect.stack()[0][3])) context = { 'form': form } if form.validate_on_submit(): context['success'] = True user = User.query.filter_by(email=form.email.data).first() if user: user.create_tmp_token() emailer.NoReply.token_reset(user).send() return render_template_wctx('pages/reset_token.html', context=context)
def update_user_address(token='', msg=None, umi=None, user=None): form = forms.RegistrationForm(request.form, app_router_path(inspect.stack()[0][3], token=token)) context = { 'form': form, 'verification_token': token, 'msg_email': user.email } if request.method == 'POST': # get zip4 so user doesn't have to look it up form.autocomplete_address() form.resolve_zip4() if form.validate_and_save_to_db(user, msg=msg): district = umi.determine_district(force=True) if district is None: context['district_error'] = True else: if msg is None: emailer.NoReply.address_changed(user).send() return redirect(url_for_with_prefix('app_router.confirm_reps', token=token)) return render_template_wctx("pages/update_user_address.html", context=context)
def logout(self): logout_user() return redirect(url_for_with_prefix('admin.login'))
def _handle_view(self, name, **kwargs): if name != 'login' and not self.is_accessible(): return redirect(url_for_with_prefix('admin.login', next=request.url))