Пример #1
0
    def post(self, request: InertiaRequest, json_body: dict):

        try:
            signup_form = SignUpForm.parse_obj(json_body)

            user_email = auth.AppUserEmail.where(email=signup_form.email).first()
            if not user_email:

                password = auth.AppUserCredential(
                    credential=custom_app_context.hash(
                        signup_form.password.get_secret_value()
                    )
                )

                user = auth.AppUser.create(
                    scopes=["self:read", "self:write"],
                    emails=[auth.AppUserEmail(email=signup_form.email)],
                    credentials=[password],
                )
                user.save()

                request.session.update(
                    {"iss": "app", "email": user.email, "scopes": user.scopes}
                )

                user.session.commit()

        except ValidationError as e:
            return {"errors": e.errors()}

        return request.redirect(request.url_for("Dashboard"))
Пример #2
0
    def post(self, request: InertiaRequest, json_body: dict):

        try:
            login_form = LoginForm.parse_obj(json_body)

            user_email = auth.AppUserEmail.where(
                email=login_form.email).first()
            if user_email:
                user = user_email.user

                for credential in user.credentials:
                    is_valid = custom_app_context.verify(
                        login_form.password.get_secret_value(),
                        credential.credential)

                    if is_valid:
                        request.session.update({
                            "iss": "app",
                            "email": user.email,
                            "scopes": user.scopes
                        })

                        messages.message(request, "Welcome!")
                        break

        except ValidationError as e:
            return {"errors": e.errors()}

        return request.redirect(request.url_for("Dashboard"))
Пример #3
0
 def get(self, request: InertiaRequest):
     return {
         "indexUrl": request.url_for("Index"),
         "signUpUrl": request.url_for("SignUp"),
         "dashboardUrl": request.url_for("Dashboard"),
         "usersUrl": request.url_for("UserList"),
     }
Пример #4
0
    def get(self, request: InertiaRequest):
        user_id = request.path_params["id"]

        return {
            "user": _USERS_INDEX.get(user_id),
            "indexUrl": request.url_for("Index"),
            "signUpUrl": request.url_for("SignUp"),
            "signOutUrl": request.url_for("SignOut"),
            "dashboardUrl": request.url_for("Dashboard"),
            "usersUrl": request.url_for("UserList"),
        }
Пример #5
0
    def get(self, request: InertiaRequest):
        user = request.user

        return {
            "userProfile": {
                "name": user.name
            },
            "indexUrl": request.url_for("Index"),
            "signUpUrl": request.url_for("SignUp"),
            "signOutUrl": request.url_for("SignOut"),
            "dashboardUrl": request.url_for("Dashboard"),
            "usersUrl": request.url_for("UserList"),
        }
Пример #6
0
    def post(self, request: InertiaRequest, json_body: dict):

        if request.session:
            request.session.clear()

        return request.redirect(request.url_for("Index"))
Пример #7
0
    def get(self, request: InertiaRequest):

        if request.user.is_authenticated:
            return request.redirect(request.url_for("Dashboard"),)

        return {}