本文整理汇总了Python中openspending.model.account.Account.by_login_hash方法的典型用法代码示例。如果您正苦于以下问题:Python Account.by_login_hash方法的具体用法?Python Account.by_login_hash怎么用?Python Account.by_login_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.account.Account
的用法示例。
在下文中一共展示了Account.by_login_hash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_login_hash [as 别名]
def verify():
if request.method == 'GET':
loginhash = request.args.get('login')
if not loginhash:
message = "Invalid URL. Please contact system administrator."
return render_template('account/message.jade', message=message)
account = Account.by_login_hash(loginhash)
if not account:
message = "This URL is no longer valid. If you have an account, you can reset your password at the " + \
" <a href='" + url_for('account.trigger_reset') + "'>password reset page</a>. Or you can register at \
<a href='" + url_for('account.login') + "'>login page</a>"
return render_template('account/message.jade', message=message)
#request.form.loginhash = {"data":loginhash}
values = {'loginhash': loginhash, "csrf_token": generate_csrf_token()}
return render_template('account/verify.jade', account=account, form_fill=values)
else:
loginhash = request.form.get('loginhash')
if not loginhash:
message = "We cannot find your unique URL"
return render_template('account/message.jade', message=message)
account = Account.by_login_hash(loginhash)
if not account:
message = "We could not find your account"
return render_template('account/message.jade', message=message)
password1 = request.form.get('password1')
password2 = request.form.get('password2')
# Check if passwords match, return error if not
if password1 != password2:
error = "Your passwords do not match"
return render_template('account/verify.jade', loginhash=loginhash, account=account, error=error)
account.password = generate_password_hash(password1)
#reset that hash but don't send it.
account.reset_loginhash()
account.verified = True
db.session.commit()
flash_success("Password saved and you are now verified. Thank you.")
login_user(account, remember=True)
return redirect(url_for('home.index'))