Make English the repository working language (#5)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,7 @@ export function authMiddleware(auth: AuthService): MiddlewareHandler<AppEnv> {
|
||||
const token = getCookie(c, SESSION_COOKIE);
|
||||
const user = token ? auth.authenticate(token) : null;
|
||||
if (!user) {
|
||||
throw new HttpError(401, "unauthorized", "未登录或登录已过期。");
|
||||
throw new HttpError(401, "unauthorized", "Not signed in or the sign-in has expired.");
|
||||
}
|
||||
c.set("user", user);
|
||||
await next();
|
||||
@@ -51,7 +51,11 @@ export const jsonOnlyWrites: MiddlewareHandler = async (c, next) => {
|
||||
if (WRITE_METHODS.has(c.req.method)) {
|
||||
const contentType = c.req.header("content-type");
|
||||
if (contentType && !contentType.toLowerCase().startsWith("application/json")) {
|
||||
throw new HttpError(415, "unsupported_media_type", "写请求仅接受 application/json。");
|
||||
throw new HttpError(
|
||||
415,
|
||||
"unsupported_media_type",
|
||||
"Write requests only accept application/json.",
|
||||
);
|
||||
}
|
||||
}
|
||||
await next();
|
||||
|
||||
@@ -81,7 +81,7 @@ export class AuthService {
|
||||
const row = this.deps.users.findById(userId);
|
||||
const ok = row !== null && (await verifyPassword(password, row.passwordHash));
|
||||
if (!row || !ok) {
|
||||
throw new HttpError(401, "invalid_credentials", "用户名或密码错误。");
|
||||
throw new HttpError(401, "invalid_credentials", "Incorrect username or password.");
|
||||
}
|
||||
this.deps.authSessions.deleteExpired(this.now().toISOString());
|
||||
return { user: toUserInfo(row), token: this.issueSession(row.userId) };
|
||||
@@ -91,10 +91,10 @@ export class AuthService {
|
||||
async changePassword(userId: string, oldPassword: string, newPassword: string): Promise<void> {
|
||||
const row = this.deps.users.findById(userId);
|
||||
if (!row || !(await verifyPassword(oldPassword, row.passwordHash))) {
|
||||
throw new HttpError(400, "password_mismatch", "当前密码不正确。");
|
||||
throw new HttpError(400, "password_mismatch", "Current password is incorrect.");
|
||||
}
|
||||
if (newPassword.length < MIN_PASSWORD_LENGTH) {
|
||||
throw new HttpError(400, "invalid_password", "密码至少 8 个字符。");
|
||||
throw new HttpError(400, "invalid_password", "Password must be at least 8 characters.");
|
||||
}
|
||||
this.deps.users.updatePassword(userId, await hashPassword(newPassword), false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user