Example #1
0
    def update_user(user_id, **kwargs):
        user = UserModel.get_user_by_id(user_id)

        for key in user:
            if key in kwargs:
                user[key] = kwargs[key]

        UserModel.delete_user(user_id)
        UserModel.register_user(user)

        return UserModel.get_user_by_id(user_id)
Example #2
0
 def post(self):
     try:
         requested_data = request.get_json()
         if UserModel.get_user_by_username(requested_data["username"]):
             return {"msg": "Username already exists"}, 400
         if UserModel.get_user_by_email(requested_data["email"]):
             return {"msg": "Email already exists"}, 400
         user_schema = UserSchema()
         result: dict = user_schema.load(requested_data)
         UserModel.register_user(**result)
         return {"msg": "Registration successful"}, 201
     except ValidationError as err:
         return jsonify(err.messages, 400)
Example #3
0
    def register_user(name: str, email: str, password: str, age: int) -> dict:
        user_id = UserModel.id_generator()

        new_user = {
            "id": user_id,
            "name": name,
            "email": email,
            "password": password,
            "age": age
        }

        if UserModel.check_user(email):
            return None

        UserModel.register_user(new_user)

        new_user.pop("password")

        return new_user
Example #4
0
def create_user():
    if (not request.json or not 'name' in request.json
            or not 'email' in request.json or not 'password' in request.json
            or not 'confirm_password' in request.json
            or not 'role' in request.json):
        return jsonify({'message': 'All fields are required'}), 400

    data = request.get_json() or {}
    if data['password'] != data['confirm_password']:
        return jsonify({'message': 'Passwords do not match'}), 422
    password = generate_password_hash(data['password'])
    register_user = UserModel.register_user(data['name'], data['email'],
                                            password, data['role'])
    if register_user == "Email already exists":
        return jsonify({"message": register_user}), 403
    return jsonify({"message": register_user}), 201
def create_user(current_user):
    if (not request.json or not 'name' in request.json
            or not 'email' in request.json or not 'password' in request.json
            or not 'confirm_password' in request.json
            or not 'role' in request.json):
        return jsonify({'message': 'Wrong params for json'}), 422

    data = request.get_json() or {}
    validate = ValidateInput.validate_input()
    if not validate(data):
        abort(422)

    if data['password'] != data['confirm_password']:
        return jsonify({'message': 'Passwords do not match'}), 422
    password = generate_password_hash(data['password'])
    register_user = UserModel.register_user(data['name'], data['email'],
                                            password, data['role'])
    return jsonify({"message": register_user}), 201