def change(self, **params):
engine = cherrypy.engine
if cherrypy.session.get('auth', False):
user = cherrypy.session['user']
oldpasswd = cherrypy.request.params.get('oldpassword')
newpasswd = cherrypy.request.params.get('newpassword')
try:
user.change_password(oldpasswd, newpasswd)
return {'ok': True}
except InvalidCredentials:
return {
'ok': False,
'error': 'Current password invalid.'
}
except UserModelException:
return {
'ok': False,
'error': 'Unknown system error. Contact your Systems Administrator.'
}
elif cherrypy.session.get('token', False):
cherrypy.session['user'] = User(cherrypy.session['username'])
newpassword = cherrypy.request.params.get('newpassword')
try:
cherrypy.session['user'].set_password(newpassword)
return {'ok': True}
except UserModelException:
return {
'ok': False,
'error': 'Unable to change your password. Try again later.'
}
评论列表
文章目录