def change_password(request): if 'logged' not in request.session: return HTTPFound(location='/signin') if request.is_xhr: csrf_token = request.params['csrf_token'] is_token = (csrf_token == unicode(request.session.get_csrf_token())) if is_token: admin = AdminModel(request) id = ObjectId(request.params['id']) password = request.params['password'] try: admin.change_password(id, password) return {'ok': 1} except Exception as e: return {'ok': 0, 'msg': e.message} else: return {'ok': 0, 'msg': 'Not authorized.'} else: return {'ok': 0, 'msg': 'Not ajax request'}
def app_change_password(request): admin = AdminModel(request) id = request.session['id'] password = request.params['password'] try: admin.change_password(ObjectId(id), password) return {'ok': 1} except Exception as e: return {'ok': 0, 'msg': e.message}