From efd34b970d0d1f88fa7d7e9d69e569f039867ca2 Mon Sep 17 00:00:00 2001
From: nsfisis
Date: Tue, 4 Mar 2025 23:39:26 +0900
Subject: rm registration token
---
backend/api/generated.go | 10 ++++------
backend/api/handler.go | 9 ++-------
backend/auth/auth.go | 28 ++--------------------------
backend/db/models.go | 5 -----
backend/db/query.sql.go | 14 --------------
backend/fixtures/dev.sql | 3 ---
backend/query.sql | 6 ------
backend/schema.sql | 6 ------
frontend/app/.server/api/client.ts | 9 +--------
frontend/app/.server/api/schema.d.ts | 2 --
frontend/app/.server/auth.ts | 9 +--------
frontend/app/routes/login.tsx | 11 +----------
openapi/api-server.yaml | 3 ---
13 files changed, 11 insertions(+), 104 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,
diff --git a/frontend/app/.server/api/client.ts b/frontend/app/.server/api/client.ts
index edcffc1..fef1508 100644
--- a/frontend/app/.server/api/client.ts
+++ b/frontend/app/.server/api/client.ts
@@ -8,18 +8,11 @@ const apiClient = createClient({
: "http://api-server/phperkaigi/2025/code-battle/api/",
});
-export async function apiPostLogin(
- username: string,
- password: string,
- registrationToken: string | null,
-) {
+export async function apiPostLogin(username: string, password: string) {
const { data, error } = await apiClient.POST("/login", {
body: {
username,
password,
- ...(registrationToken !== null
- ? { registration_token: registrationToken }
- : {}),
},
});
if (error) throw new Error(error.message);
diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts
index 7fd612e..1afed69 100644
--- a/frontend/app/.server/api/schema.d.ts
+++ b/frontend/app/.server/api/schema.d.ts
@@ -321,8 +321,6 @@ export interface operations {
username: string;
/** @example password123 */
password: string;
- /** @example xxxxxxxxxxxxxxxx */
- registration_token?: string;
};
};
};
diff --git a/frontend/app/.server/auth.ts b/frontend/app/.server/auth.ts
index 4df0924..ac8afe8 100644
--- a/frontend/app/.server/auth.ts
+++ b/frontend/app/.server/auth.ts
@@ -14,14 +14,7 @@ authenticator.use(
new FormStrategy(async ({ form }) => {
const username = String(form.get("username"));
const password = String(form.get("password"));
- const registrationToken = String(form.get("registration_token"));
- return (
- await apiPostLogin(
- username,
- password,
- registrationToken === "" ? null : registrationToken,
- )
- ).token;
+ return (await apiPostLogin(username, password)).token;
}),
"default",
);
diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx
index 223a3f5..5ca6217 100644
--- a/frontend/app/routes/login.tsx
+++ b/frontend/app/routes/login.tsx
@@ -3,7 +3,7 @@ import type {
LoaderFunctionArgs,
MetaFunction,
} from "@remix-run/node";
-import { Form, json, useActionData, useLocation } from "@remix-run/react";
+import { Form, json, useActionData } from "@remix-run/react";
import { ensureUserNotLoggedIn, login } from "../.server/auth";
import BorderedContainer from "../components/BorderedContainer";
import InputText from "../components/InputText";
@@ -58,10 +58,6 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function Login() {
- const location = useLocation();
- const searchParams = new URLSearchParams(location.search);
- const registrationToken = searchParams.get("registration_token");
-
const loginErrors = useActionData();
return (
@@ -113,11 +109,6 @@ export default function Login() {
)}
-
ログイン
diff --git a/openapi/api-server.yaml b/openapi/api-server.yaml
index 94083d3..a71bd3f 100644
--- a/openapi/api-server.yaml
+++ b/openapi/api-server.yaml
@@ -20,9 +20,6 @@ paths:
password:
type: string
example: "password123"
- registration_token:
- type: string
- example: "xxxxxxxxxxxxxxxx"
required:
- username
- password
--
cgit v1.2.3-70-g09d2