Esempio n. 1
0
def sign_up():
    data_form = request.json
    mobile = data_form.get('mobile', None)
    password1 = data_form.get('password1', None)
    password2 = data_form.get('password2', None)
    verify_code = data_form.get('verify_code', None)
    if mobile and password1 and password2 and verify_code:
        if password1 != password2:
            return jsonify({
                "success": False,
                "message": "password is not correct"
            })
        if verify_code != int(session.get(str(mobile), None)):
            return jsonify({
                "success": False,
                "message": "verify_code is not correct"
            })
        if User.find_one(mobile=int(mobile)):
            return jsonify({
                "success": False,
                "message": "mobile is already exist"
            })
        user = User(mobile, password1)
        user.save()
        login_user(load_user(user.id), remember=True)
        return jsonify({"success": True, 'redirect_url': 'admin_panel'})
    else:
        return jsonify({
            "success": False,
            "message": "data form is not correct"
        })
Esempio n. 2
0
def update_user(user: User, **params):
    if not params:
        return errors.error_response(200,
                                     "Nothing to update missing properties")

    if current_user.id != user.id and current_user.role != UserRoles.admin:
        return errors.forbidden("User can modify only his properties.")

    try:
        user.update(params)
        user.save()
    except SaveError as err:
        return errors.internal_error(err.messages)

    return {}, 204