web2py自定义重置密码
web2py custom reset password
如何在 Web2Py 中创建自定义重置密码表单?
request_reset_password
def request_reset_password():
site_url = 'www.site.com/myproject/'
auth.settings.request_reset_password_next = URL('account', args='request sent')
auth.messages.reset_password ='please click this link http://' + site_url+ 'account/reset_password'+ '/?key='+'%(key)s to reset your password'
form= auth.request_reset_password()
form.custom.submit['_data-theme'] = 'e'
form.custom.submit['_data-ajax'] = 'false'
return dict(form=form)
reset_password
def reset_password():
user = db.auth_user
if request.vars.key:
key = request.vars.key
users = db(user.reset_password_key == key).select()
if not users:
session.flash='Invalid password reset'
#redirect(next)
form=FORM(INPUT(_name='password', _type="password", requires=[IS_NOT_EMPTY()]),INPUT(_type='submit', _value='Click to perform password reset'))
if form.accepts(request,session):
key= request.vars.key if request.vars.key else _error()
password= request.vars.password if request.vars.password else _error()
users = db(user.reset_password_key == key).select()
if not users:
session.flash='Invalid password reset'
#redirect(next)
users[0].update_record(password=CRYPT(key=auth.settings.hmac_key)(password)[0],reset_password_key='')
#session.flash='Password was reset'
#redirect(next)
return dict(form=form)
要为这两个函数添加视图,请尝试此代码。
{{extend 'layout.html'}}
{{=form}}
以上代码运行完美
如何在 Web2Py 中创建自定义重置密码表单?
request_reset_password
def request_reset_password():
site_url = 'www.site.com/myproject/'
auth.settings.request_reset_password_next = URL('account', args='request sent')
auth.messages.reset_password ='please click this link http://' + site_url+ 'account/reset_password'+ '/?key='+'%(key)s to reset your password'
form= auth.request_reset_password()
form.custom.submit['_data-theme'] = 'e'
form.custom.submit['_data-ajax'] = 'false'
return dict(form=form)
reset_password
def reset_password():
user = db.auth_user
if request.vars.key:
key = request.vars.key
users = db(user.reset_password_key == key).select()
if not users:
session.flash='Invalid password reset'
#redirect(next)
form=FORM(INPUT(_name='password', _type="password", requires=[IS_NOT_EMPTY()]),INPUT(_type='submit', _value='Click to perform password reset'))
if form.accepts(request,session):
key= request.vars.key if request.vars.key else _error()
password= request.vars.password if request.vars.password else _error()
users = db(user.reset_password_key == key).select()
if not users:
session.flash='Invalid password reset'
#redirect(next)
users[0].update_record(password=CRYPT(key=auth.settings.hmac_key)(password)[0],reset_password_key='')
#session.flash='Password was reset'
#redirect(next)
return dict(form=form)
要为这两个函数添加视图,请尝试此代码。
{{extend 'layout.html'}}
{{=form}}
以上代码运行完美