diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-04 23:39:26 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-04 23:39:26 +0900 |
| commit | efd34b970d0d1f88fa7d7e9d69e569f039867ca2 (patch) | |
| tree | ba1e5a51e2fac9ecbe7b9b3e0e197bdb327f2a4e /backend | |
| parent | bd9c2e8b587c733059d44f642c53536eb7fe1ec9 (diff) | |
| download | iosdc-japan-2025-albatross-efd34b970d0d1f88fa7d7e9d69e569f039867ca2.tar.gz iosdc-japan-2025-albatross-efd34b970d0d1f88fa7d7e9d69e569f039867ca2.tar.zst iosdc-japan-2025-albatross-efd34b970d0d1f88fa7d7e9d69e569f039867ca2.zip | |
rm registration token
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/generated.go | 10 | ||||
| -rw-r--r-- | backend/api/handler.go | 9 | ||||
| -rw-r--r-- | backend/auth/auth.go | 28 | ||||
| -rw-r--r-- | backend/db/models.go | 5 | ||||
| -rw-r--r-- | backend/db/query.sql.go | 14 | ||||
| -rw-r--r-- | backend/fixtures/dev.sql | 3 | ||||
| -rw-r--r-- | backend/query.sql | 6 | ||||
| -rw-r--r-- | backend/schema.sql | 6 |
8 files changed, 8 insertions, 73 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index 7eb5940..af716df 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -311,9 +311,8 @@ type GetGameParams struct { // PostLoginJSONBody defines parameters for PostLogin. type PostLoginJSONBody struct { - Password string `json:"password"` - RegistrationToken *string `json:"registration_token,omitempty"` - Username string `json:"username"` + Password string `json:"password"` + Username string `json:"username"` } // GetTokenParams defines parameters for GetToken. @@ -1186,9 +1185,8 @@ var swaggerSpec = []string{ "16CuzQbfGfc3vKwVWwa1PwdIb7dm7KPhcK+Br0uvHHqnoZmZUlaGZjUjJdmQBXeM/J5I5fG5ZyVSH50P", "T5sg5D4P3OGzFjprFyrN6HWdTKIIi/UGQmY/9bNUDh6zsVjaltSecuq3yjm/2DgCB7plvibTnRJ9aUL8", "zTKsJc7bJfKfariUuAbl4QywpgTlC1sNYy5rmHDDpXpvttjggFSvebh+Qj5iLOWKi3DrbTx7ejo6qyvb", - "AhZEqmw+q/g/sHVBPmz9q9PxxArNNgcig1/PDPfnRGmvTG7y+6T0f3sLaJR0ofXEdj/zhNK1pykLTGmo", - "G9buTXWHh7of8Cz5DA9z55oK0iez4TneMt9VXmx9kEsu1EtK7iH0sDHnWYBpmqb/BQAA//+vy4pZ5ycA", - "AA==", + "T6yubEPmzHR9Vt2fAqW9slDxf2DrUn/Q/05K/7e3b0ZJF0pObOcyTyhde5puwJSGumHc3jR1OKTvcs8S", + "x3Aod66pmHwyG57jDfFd5cWebbnkQr2k5B5CDxtzngWYpmn6XwAAAP//wKRGKaMnAAA=", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handler.go b/backend/api/handler.go index dafcf84..d16b731 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -27,16 +27,11 @@ type GameHubsInterface interface { func (h *Handler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) { username := request.Body.Username password := request.Body.Password - registrationToken := request.Body.RegistrationToken - userID, err := auth.Login(ctx, h.q, username, password, registrationToken) + userID, err := auth.Login(ctx, h.q, username, password) if err != nil { log.Printf("login failed: %v", err) var msg string - if errors.Is(err, auth.ErrInvalidRegistrationToken) { - msg = "登録用 URL が無効です。イベントスタッフにお声がけください" - } else if errors.Is(err, auth.ErrNoRegistrationToken) { - msg = "登録用 URL からログインしてください。登録用 URL は Connpass のイベントページに記載しています" - } else if errors.Is(err, auth.ErrForteeLoginTimeout) { + if errors.Is(err, auth.ErrForteeLoginTimeout) { msg = "ログインに失敗しました" } else { msg = "ユーザー名またはパスワードが誤っています" diff --git a/backend/auth/auth.go b/backend/auth/auth.go index b23884f..f4c5931 100644 --- a/backend/auth/auth.go +++ b/backend/auth/auth.go @@ -15,9 +15,7 @@ import ( ) var ( - ErrInvalidRegistrationToken = errors.New("invalid registration token") - ErrNoRegistrationToken = errors.New("no registration token") - ErrForteeLoginTimeout = errors.New("fortee login timeout") + ErrForteeLoginTimeout = errors.New("fortee login timeout") ) const ( @@ -29,7 +27,6 @@ func Login( queries *db.Queries, username string, password string, - registrationToken *string, ) (int, error) { userAuth, err := queries.GetUserAuthByUsername(ctx, username) if err != nil && !errors.Is(err, pgx.ErrNoRows) { @@ -50,7 +47,7 @@ func Login( } // Authenticate with fortee. - return verifyForteeAccountOrSignup(ctx, queries, username, password, registrationToken) + return verifyForteeAccountOrSignup(ctx, queries, username, password) } func verifyForteeAccountOrSignup( @@ -58,7 +55,6 @@ func verifyForteeAccountOrSignup( queries *db.Queries, username string, password string, - registrationToken *string, ) (int, error) { canonicalizedUsername, err := verifyForteeAccount(ctx, username, password) if err != nil { @@ -71,7 +67,6 @@ func verifyForteeAccountOrSignup( ctx, queries, canonicalizedUsername, - registrationToken, ) } return 0, err @@ -83,12 +78,7 @@ func signup( ctx context.Context, queries *db.Queries, username string, - registrationToken *string, ) (int, error) { - if err := verifyRegistrationToken(ctx, queries, registrationToken); err != nil { - return 0, err - } - // TODO: transaction userID, err := queries.CreateUser(ctx, username) if err != nil { @@ -110,20 +100,6 @@ func signup( return int(userID), nil } -func verifyRegistrationToken(ctx context.Context, queries *db.Queries, registrationToken *string) error { - if registrationToken == nil { - return ErrNoRegistrationToken - } - exists, err := queries.IsRegistrationTokenValid(ctx, *registrationToken) - if err != nil { - return err - } - if !exists { - return ErrInvalidRegistrationToken - } - return nil -} - func verifyForteeAccount(ctx context.Context, username string, password string) (string, error) { ctx, cancel := context.WithTimeout(ctx, forteeAPITimeout) defer cancel() diff --git a/backend/db/models.go b/backend/db/models.go index f6e7ed1..b21fd9b 100644 --- a/backend/db/models.go +++ b/backend/db/models.go @@ -30,11 +30,6 @@ type Problem struct { Description string } -type RegistrationToken struct { - RegistrationTokenID int32 - Token string -} - type Submission struct { SubmissionID int32 GameID int32 diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go index 35b7edd..fdd40dd 100644 --- a/backend/db/query.sql.go +++ b/backend/db/query.sql.go @@ -258,20 +258,6 @@ func (q *Queries) GetUserIDByUsername(ctx context.Context, username string) (int return user_id, err } -const isRegistrationTokenValid = `-- name: IsRegistrationTokenValid :one -SELECT EXISTS ( - SELECT 1 FROM registration_tokens - WHERE token = $1 -) -` - -func (q *Queries) IsRegistrationTokenValid(ctx context.Context, token string) (bool, error) { - row := q.db.QueryRow(ctx, isRegistrationTokenValid, token) - var exists bool - err := row.Scan(&exists) - return exists, err -} - const listGamePlayers = `-- name: ListGamePlayers :many SELECT game_id, game_players.user_id, users.user_id, username, display_name, icon_path, is_admin, created_at FROM game_players JOIN users ON game_players.user_id = users.user_id diff --git a/backend/fixtures/dev.sql b/backend/fixtures/dev.sql index c7d1080..46e745f 100644 --- a/backend/fixtures/dev.sql +++ b/backend/fixtures/dev.sql @@ -12,9 +12,6 @@ VALUES (2, 'password', '$2a$10$4Wl1M4jQs.GwkB4oT32KvuMQtF.EdqKuOc8z8KKOupnuMJRAVk32W'), (3, 'password', '$2a$10$F/TePpu1pyJRWgn0e6A14.VL9D/17sRxT/2DyZ2Oi4Eg/lR6n7JcK'); -INSERT INTO registration_tokens (token) -VALUES ('shah3Iheix6cheig'); - INSERT INTO problems (title, description) VALUES diff --git a/backend/query.sql b/backend/query.sql index dc5f384..fcff758 100644 --- a/backend/query.sql +++ b/backend/query.sql @@ -32,12 +32,6 @@ LIMIT 1; INSERT INTO user_auths (user_id, auth_type) VALUES ($1, $2); --- name: IsRegistrationTokenValid :one -SELECT EXISTS ( - SELECT 1 FROM registration_tokens - WHERE token = $1 -); - -- name: ListGames :many SELECT * FROM games JOIN problems ON games.problem_id = problems.problem_id diff --git a/backend/schema.sql b/backend/schema.sql index dc49363..6a88c6b 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -17,12 +17,6 @@ CREATE TABLE user_auths ( ); CREATE INDEX idx_user_auths_user_id ON user_auths(user_id); -CREATE TABLE registration_tokens ( - registration_token_id SERIAL PRIMARY KEY, - token CHAR(16) NOT NULL -); -CREATE INDEX idx_registration_tokens_token ON registration_tokens(token); - CREATE TABLE problems ( problem_id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, |
