def POST_password(self, uid): user = db.select('users', what='password', where='id=$uid', vars=locals())[0] form = get_password_form(user) set_passwd_form = 'curr_password' not in [ inp.name for inp in list(form.inputs) ] i = web.input() if form.validates(i): if set_passwd_form or auth.check_password(user, i.curr_password): enc_password = auth.encrypt_password(i.password) db.update('users', password=enc_password, verified=True, where='id=$uid', vars=locals()) helpers.set_msg('Password %s.' % ('saved' if set_passwd_form else 'changed')) raise web.seeother('/%s/preferences' % uid) else: helpers.set_msg('Invalid Password', 'error') form.note = 'Current Password invalid.' form.valid = False return self.GET(uid, password_form=form)
def GET(self, form=None): i = web.input() if check_secret_token(i.get('email', ''), i.get('token', '')): form = form or forms.passwordform() return render.set_password(form, i.email) else: helpers.set_msg('Invalid token', msg_type='error') raise web.seeother('/u/forgot_password', absolute=True)
def POST(self): i = web.input() form = forms.passwordform() if form.validates(i): password = encrypt_password(i.password) db.update('users', password=password, verified=True, where='email=$i.email', vars=locals()) helpers.set_msg('Login with your new password.') raise web.seeother('/login') else: return self.GET(form)
def POST(self): i = web.input() form = forms.passwordform() if form.validates(i): password = encrypt_password(i.password) db.update('users', password=password, verified=True, where='email=$i.email', vars=locals()) helpers.set_login_cookie(i.email) helpers.set_msg('Password stored') raise web.seeother('/c/', absolute=True) else: return self.GET(form)
def GET(self, form=None): i = web.input() email = i.get('email', '') email_exists = bool(helpers.get_user_by_email(email)) if email_exists and check_secret_token(email, i.get('token', '@')): form = form or forms.passwordform() return render.set_password(form, i.email) else: if email_exists: msg = 'Invalid token' else: msg = 'No user account exists with this email' helpers.set_msg(msg, msg_type='error') raise web.seeother('/u/forgot_password', absolute=True)
def POST(self, uid): if web.input('m', _method='GET'): return self.POST_password(uid) form = forms.userinfo() i = web.input() if form.validates(i): i.pop('submit') db.update('users', where='id=$uid', vars=locals(), **i) helpers.set_msg('User information updated.') raise web.seeother('/%s' % uid) else: return self.GET(uid, info_form=form)
def POST(self, uid): i = web.input('m', _method='GET') if i.m == 'password': return self.POST_password(uid) form = forms.userinfo() i = web.input(_method='POST') if form.validates(i): if 'submit' in i: i.pop('submit') db.update('users', where='id=$uid', vars=locals(), **i) helpers.set_msg('User information updated.') raise web.seeother('/%s/preferences' % uid) else: return self.GET(uid, info_form=form)
def POST_password(self, uid): user = db.select('users', what='password', where='id=$uid', vars=locals())[0] form = get_password_form(user) i = web.input() if form.validates(i): if ('curr_password' not in form) or auth.check_password(user, i.curr_password): enc_password = auth.encrypt_password(i.password) db.update('users', password=enc_password, verified=True, where='id=$uid', vars=locals()) helpers.set_msg('Password saved.') else: helpers.set_msg('Invalid Password', 'error') raise web.seeother('/%s' % uid) else: return self.GET(uid, password_form=form)
def POST(self, uid): i = web.input("m", _method="GET") if i.m == "password": return self.POST_password(uid) form = forms.userinfo() i = web.input(_method="POST") if form.validates(i): if "submit" in i: i.pop("submit") db.update("users", where="id=$uid", vars=locals(), **i) helpers.set_msg("User information updated.") raise web.seeother("/%s/preferences" % uid) else: return self.GET(uid, info_form=form)
def POST_password(self, uid): user = db.select("users", what="password", where="id=$uid", vars=locals())[0] form = get_password_form(user) set_passwd_form = "curr_password" not in [inp.name for inp in list(form.inputs)] i = web.input() if form.validates(i): if set_passwd_form or auth.check_password(user, i.curr_password): enc_password = auth.encrypt_password(i.password) db.update("users", password=enc_password, verified=True, where="id=$uid", vars=locals()) helpers.set_msg("Password %s." % ("saved" if set_passwd_form else "changed")) raise web.seeother("/%s/preferences" % uid) else: helpers.set_msg("Invalid Password", "error") form.note = "Current Password invalid." form.valid = False return self.GET(uid, password_form=form)
def POST_password(self, uid): user = db.select('users', what='password', where='id=$uid', vars=locals())[0] form = get_password_form(user) set_passwd_form = 'curr_password' not in [inp.name for inp in list(form.inputs)] i = web.input() if form.validates(i): if set_passwd_form or auth.check_password(user, i.curr_password): enc_password = auth.encrypt_password(i.password) db.update('users', password=enc_password, verified=True, where='id=$uid', vars=locals()) helpers.set_msg('Password %s.' % ('saved' if set_passwd_form else 'changed')) raise web.seeother('/%s/preferences' % uid) else: helpers.set_msg('Invalid Password', 'error') form.note = 'Current Password invalid.' form.valid = False return self.GET(uid, password_form=form)
def POST(self): i = web.input() wyrform = forms.wyrform() if wyrform.validates(i): auth.assert_login(i) try: status = self.save_and_send_msg(i, wyrform) except CaptchaException: msg, msg_type = helpers.get_delete_msg() return render.writerep(wyrform, msg) else: if status: p = db.select('politician', what='firstname, middlename, lastname', where='id=$self.pol', vars=locals())[0] polstr = '<a href="/p/%s">%s %s %s</a>' % (self.pol, p.firstname, p.middlename, p.lastname) helpers.set_msg('Your message has been sent to %s.' % polstr) else: helpers.set_msg('Sorry, your message has NOT been sent.', 'error') raise web.seeother('/') else: return self.GET(wyrform)
def send_msg(self, i, wyrform, pform=None): pol = self.pol captcha_src = (not i.get('captcha')) and get_captcha_src(pol) if captcha_src: set_captcha(wyrform, captcha_src) msg = 'Please fill in the captcha verification below' helpers.set_msg(msg, msg_type='note') raise CaptchaException email = '*****@*****.**' % (self.msg_id) try: msg_sent = writerep(pol=pol, prefix=i.prefix, lname=i.lname, fname=i.fname, addr1=i.addr1, addr2=i.addr2, city=i.city, zipcode=i.zipcode, zip4=i.zip4, phone=web.numify(i.phone), email=email, subject=i.ptitle, msg=i.msg, captcha=i.get('captcha', '')) except: msg_sent = False if not pform: update_user_details(i) return msg_sent
def POST(self): def pol_link(polid): p = db.select('politician', what='firstname, middlename, lastname', where='id=$polid', vars=locals())[0] return '<a href="/p/%s">%s %s %s</a>' % (polid, p.firstname or '', p.middlename or '', p.lastname or '') i = web.input() wf = forms.wyrform() pols = getpols(i.zip5, i.zip4, i.addr1+i.addr2) captcha_needed = require_captcha(i, pols) if not wf.validates(i) or captcha_needed: if captcha_needed: wf.valid, wf.note = False, 'Please fill the captcha below' wf.fill(i) return self.GET(wf) else: uid = auth.assert_login(i) update_user_details(i, uid) env = simplejson.loads(i.get('captcha_env', '{}')) status = writerep.send_msgs(uid, i, source_id='wyr', pols=pols, env=env) pol_str = ", ".join([pol_link(p) for p in pols]) helpers.set_msg('Your message has been sent to %s' % pol_str) raise web.seeother('/')
def POST(self): i = web.input() form = forms.forgot_password() if form.validates(i): token = get_secret_token(i.email) reset_url = set_password_url(i.email, token) subject = 'Reset your watchdog.net password' msg = """\ You asked to reset your password on watchdog.net. You can do so at: %s but you have to do it within the next 7 days. Thanks, watchdog.net """ % (reset_url) web.sendmail(config.from_address, i.email, subject, msg) helpers.set_msg('Check your email to reset your password.') raise web.seeother('/u/forgot_password', absolute=True) else: return self.GET(form)
def POST(self): i = web.input() form = forms.forgot_password() if form.validates(i): token = get_secret_token(i.email) reset_url = set_password_url(i.email, token) subject = 'Reset your watchdog.net password' msg = """\ You asked to reset your password on watchdog.net. You can do so at: %s but you have to do it within the next 7 days. Thanks, watchdog.net """ % (reset_url) web.sendmail(config.from_address, i.email, subject, msg ) helpers.set_msg('Check your email to reset your password.') raise web.seeother('/u/forgot_password', absolute=True) else: return self.GET(form)