def create_user(): data = request.get_json() if User.get_by_username(data.get('username')): return api_error(dict(username=['Username already exists'])) user = User.from_json(data) user.save() return jsonify(UserAdministrationResource(user))
def login(): json = request.get_json() if 'username' in json: user = User.get_by_username(json.get('username').lower()) if user is not None and user.check_password(json.get('password')): login_user(user) return jsonify(CurrentUserResource(user)) return api_error(dict(form=['Invalid username/password.']))
def delete_user(id): user = User.get(id) if not user: return api_error('User not found', 404) if user.id == current_user.id: return api_error('Cannot delete self', 404) user.delete() return '', 202
def delete_user(user_id): user = User.get(user_id) if not user: return form_error('User not found') if user.id == current_user.id: return form_error('Cannot delete self') user.delete() return '', 202
def update_user(user_id): user = User.get_by_id(user_id) if not user: return form_error('User not found') data = request.get_json() if data.get('username') != user.username and User.get_by_username( data.get('username')): return api_error(dict(username=['Username already in use'])) if 'password' in data and len(data.get('password')) > 0: user.set_password(data.get('password')) user.name = data.get('name') user.username = data.get('username') user.phone_number = data.get('phone_number') user.role = data.get('role') user.save() return jsonify(UserAdministrationResource(user))
def update_user(user_id): user = User.get_by_id(user_id) if not user: return api_error('User not found', 404) json = request.get_json() if 'password' in request.json: user.set_password(json.get('password')) user.name = json.get('name') user.email = json.get('email') user.phone_number = json.get('phone_number') user.role = json.get('role') user.save() return jsonify(UserAdministrationResource(user))
def load_user(user_id): return User.get(user_id)
def create_user(): user = User.from_json(request.get_json()) user.save() return jsonify(UserAdministrationResource(user))
def get_user(user_id): return jsonify(UserAdministrationResource(User.get(user_id)))
def get_users(): return jsonify(map(UserAdministrationResource, User.all()))