aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/auth/fortee/fortee.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-17 18:59:55 +0900
committernsfisis <nsfisis@gmail.com>2024-08-17 18:59:55 +0900
commitf926ef682de637b717d3b0cc0eaee43c59e83c95 (patch)
treea6cc6852ecdfe5643d336b77e9956fe6383d53ef /backend/auth/fortee/fortee.go
parent29721ab9971c401d5fb5d2a2cfd730b156a8e195 (diff)
downloadphperkaigi-2025-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.tar.gz
phperkaigi-2025-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.tar.zst
phperkaigi-2025-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.zip
feat(backend): allow login/signup with email address
Diffstat (limited to 'backend/auth/fortee/fortee.go')
-rw-r--r--backend/auth/fortee/fortee.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/backend/auth/fortee/fortee.go b/backend/auth/fortee/fortee.go
index 7f9d816..25ca9c5 100644
--- a/backend/auth/fortee/fortee.go
+++ b/backend/auth/fortee/fortee.go
@@ -14,25 +14,29 @@ var (
ErrLoginFailed = errors.New("fortee login failed")
)
-func LoginFortee(ctx context.Context, username string, password string) error {
+func LoginFortee(ctx context.Context, username string, password string) (string, error) {
client, err := NewClientWithResponses(apiEndpoint, WithRequestEditorFn(addAcceptHeader))
if err != nil {
- return err
+ return "", err
}
res, err := client.PostLoginWithFormdataBodyWithResponse(ctx, PostLoginFormdataRequestBody{
Username: username,
Password: password,
})
if err != nil {
- return err
+ return "", err
}
if res.StatusCode() != http.StatusOK {
- return ErrLoginFailed
+ return "", ErrLoginFailed
}
- if !res.JSON200.LoggedIn {
- return ErrLoginFailed
+ resOk := res.JSON200
+ if !resOk.LoggedIn {
+ return "", ErrLoginFailed
}
- return nil
+ if resOk.User == nil {
+ return "", ErrLoginFailed
+ }
+ return resOk.User.Username, nil
}
// fortee API denies requests without Accept header.