How to create custom reset password form in 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)
To add a view for the both functions try this code .
{{extend 'layout.html'}}
{{=form}}