aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/auth/fortee
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
parent29721ab9971c401d5fb5d2a2cfd730b156a8e195 (diff)
downloadiosdc-japan-2024-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.tar.gz
iosdc-japan-2024-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.tar.zst
iosdc-japan-2024-albatross-f926ef682de637b717d3b0cc0eaee43c59e83c95.zip
feat(backend): allow login/signup with email address
Diffstat (limited to 'backend/auth/fortee')
-rw-r--r--backend/auth/fortee/fortee.go18
-rw-r--r--backend/auth/fortee/generated.go6
2 files changed, 17 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.
diff --git a/backend/auth/fortee/generated.go b/backend/auth/fortee/generated.go
index e2fd920..53529f9 100644
--- a/backend/auth/fortee/generated.go
+++ b/backend/auth/fortee/generated.go
@@ -221,6 +221,9 @@ type PostLoginResponse struct {
HTTPResponse *http.Response
JSON200 *struct {
LoggedIn bool `json:"loggedIn"`
+ User *struct {
+ Username string `json:"username"`
+ } `json:"user,omitempty"`
}
}
@@ -274,6 +277,9 @@ func ParsePostLoginResponse(rsp *http.Response) (*PostLoginResponse, error) {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest struct {
LoggedIn bool `json:"loggedIn"`
+ User *struct {
+ Username string `json:"username"`
+ } `json:"user,omitempty"`
}
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err