def admin_users_edit_post(): payload = get_payload(request) user_id = payload.get('user_id') if user_id: user = User.get(user_id) return_value = success('All profile values have been updated.') else: user = User() user.insert() return_value = success('User created.') if not payload.get('password'): return jsonify(failure('You must set a password for new users')) if not payload.get('email'): return jsonify(failure('You must set an email for new users')) if not payload.get('name'): return jsonify(failure('You must set a name for new users')) for key in payload: if key == 'password': user.set_password(payload[key]) elif key != 'user_id': setattr(user, key, payload[key]) g.user.insert() safe_commit() return jsonify(return_value)
def delete_user(): return_value = success('The user was deleted.') payload = get_payload(request) if not g.user or g.user.id != payload.get('id'): user = User.filter(User.id == payload.get('id')).first() if user: user.delete() safe_commit() else: return_value = failure('That user does not exist.') else: return_value = failure('You cannot delete the current user.') return jsonify(return_value)
def delete_user(): return_value = success('The user was deleted.') payload = get_payload(request) if not g.user or g.user.id != payload.get('id'): user = User.filter(User.id == payload.get('id')).first() if user: user.active = False user.insert() safe_commit() else: return_value = failure('That user does not exist.') else: return_value = failure('You cannot delete the current user.') return jsonify(return_value)
def admin_content_delete(): return_value = success('The content has been deleted.') payload = get_payload(request) content = Content.get(payload.get('id')) if content: content.delete() safe_commit() else: return_value = failure('Content not found.') return jsonify(return_value)
def retrieve_user(): return_value = success('The user was retrieved.') payload = get_payload(request) user = User.get(payload.get('id')) if not user: return_value = failure('That user does not exist.') else: return_value['user'] = user.to_dict(camel_case=True) return_value['user'].pop('password') return_value['user'].pop('openid') return jsonify(return_value)
def update_user(): return_value = success('The user was updated.') payload = get_payload(request) user = User.get(payload.get('id')) if not user: return_value = failure('That user does not exist.') else: if payload.get('password'): user.set_password(payload.get('password')) if payload.get('email'): user.email = payload.get('email') if payload.get('name'): user.name = payload.get('name') safe_commit() return_value['user'] = user.to_dict(camel_case=True) return jsonify(return_value)
def admin_files_delete(): return_value = success('The file has been deleted.') payload = get_payload(request) afile = File.get(payload.get('id')) if afile: try: os.unlink(afile.path) except OSError: pass try: os.unlink(afile.thumbnail_path) except OSError: pass afile.delete() safe_commit() else: return_value = failure('File not found.') return jsonify(return_value)
def update_user(): return_value = success('The user was updated.') payload = get_payload(request) user = User.get(payload.get('id')) if not user: return_value = failure('That user does not exist.') else: if payload.get('password'): hashed_password = generate_password_hash(payload.get('password')) if payload.get('email'): user.email = payload.get('email') if payload.get('name'): user.name = payload.get('name') user.password = hashed_password safe_commit() return_value['user'] = user.to_dict(camel_case=True) return jsonify(return_value)