-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UI text in main-part.tsx files
- Loading branch information
Showing
16 changed files
with
479 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
{ | ||
"HZEGO_YeW": "这是一个测试字符串,表示“Hello World”,可以吗?" | ||
"-dxG-aEe4w": "今天发送的短信验证码已达到最大数量。", | ||
"4sQWoTgfr": "验证码已过期,请刷新页面重试", | ||
"4sdQWoTgfr": "验证码已过期,请刷新页面后重试。", | ||
"8s1R5nChx": "邀请码为空,该社区不对外开放,仅限受邀用户。", | ||
"8s1dX": "系统中不存在邀请码,请检查是否存在大小写问题。", | ||
"8sVG1RXhx": "密码应至少为 6 个字符", | ||
"8sVG1RdXhx": "用户ID已存在", | ||
"8sVG1kqXhx": "用户 ID 至少应为 2 个字符", | ||
"8sVGdXhx": "用户 ID 只能包含字母和数字", | ||
"8saIR-LCjyChx": "邀请码已过期", | ||
"8saIt5r5nGxwwChx": "邀请码已用完", | ||
"CuHqw9m": "{0} 不是有效的电话号码,当前系统仅接受 11 位数字的电话号码。", | ||
"D_9sNBiZj": "您尝试的次数过多,请稍后再试。", | ||
"HZEGO_YeW": "这是一个测试字符串,表示“Hello World”,可以吗?", | ||
"HaU4NMabv": "验证码不正确,请重新输入或刷新图片。", | ||
"K2UEY4ddl": "用户 ID 包含无效单词,请避免使用 {0}", | ||
"RYlJHHwg3": "短信代码不正确。", | ||
"TXdh_K": "密码", | ||
"TdXddh_wK": "电话号码", | ||
"Te3h_wK": "电话号码", | ||
"TqXdd3h_wK": "电话号码", | ||
"TqXddh_K": "验证码", | ||
"TqXdh_K": "确认密码", | ||
"Xddh_wK": "邀请代码", | ||
"Y-svpKvUz": "两个密码不匹配", | ||
"dsdfqw": "用户不存在", | ||
"eqwee": "密码不正确", | ||
"oHQNQ4mRw": "用户身份", | ||
"wCcPJZK": "{0} 不是有效的电子邮件地址", | ||
"wCctGPJZK": "{0} 不应为空" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use server' | ||
|
||
import dao from "@/dao"; | ||
import _ from "lodash"; | ||
import { CommonHandlePass } from "../auth.route"; | ||
import { getImgBase64Result } from "@/services/captcha.service"; | ||
|
||
export type AsyncCreateResponse<T> = { | ||
message?: string, // normal message | ||
error?: string, // error | ||
data?: T | ||
} | ||
|
||
export type CheckRules = { | ||
type: "non-empty" | "valid-email" | "check-fn" | "valid-phone", | ||
name: string, | ||
validateFn?: (val: string) => Promise<string | undefined>, | ||
label?: string | ||
} | ||
|
||
export let validateEachRuleInArr = async (rules: CheckRules[], formData: any): Promise<AsyncCreateResponse<{}> | null> => { | ||
let valid = true; | ||
let lastMsg = '' | ||
for (let rule of rules) { | ||
if (rule.type === "non-empty") { | ||
lastMsg = Dot("wCctGPJZK", "{0} should not be empty", rule.label) | ||
if (!formData[rule.name]) { | ||
valid = false; | ||
break; | ||
} | ||
} | ||
if (rule.type === "valid-email") { | ||
lastMsg = Dot("wCcPJZK", "{0} is not a valid email", rule.label) | ||
if (!formData[rule.name].includes("@")) { | ||
valid = false; | ||
break; | ||
} | ||
} | ||
if (rule.type === "check-fn" && rule.validateFn) { | ||
let result = await rule.validateFn(formData[rule.name]) | ||
if (result) { | ||
lastMsg = result | ||
valid = false; | ||
break; | ||
} | ||
} | ||
if (rule.type === "valid-phone" && rule.validateFn) { | ||
if (formData[rule.name].length != 11) { | ||
lastMsg = Dot("CuHqw9m", "{0} is not a valid phone number, currently system accept 11 digits telephone number only.", rule.label) | ||
valid = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (valid) return null; | ||
return { | ||
error: lastMsg || "invalid form data" | ||
} | ||
} | ||
|
||
export let fn_verifyVCode = (randomID: string, p: CommonHandlePass): any => { | ||
let { getCookie, setCookie, Dot } = p | ||
return { | ||
type: "check-fn", | ||
name: "vcode", | ||
validateFn: async (val) => { | ||
let daoRef = await dao() | ||
let vcodeLabel = randomID | ||
if (!vcodeLabel) { | ||
return Dot("4sQWoTgfr", "Verification code is expired, please refresh the page and try again") | ||
} | ||
let fn_cleanVCode = async () => { | ||
if (vcodeLabel) { | ||
await daoRef.redis.del(vcodeLabel) | ||
} | ||
} | ||
let vcodeValOrderIdx = await daoRef.redis.get(vcodeLabel) | ||
if (_.isNil(vcodeValOrderIdx)) { | ||
await fn_cleanVCode() | ||
return Dot("4sdQWoTgfr", "Verification code is expired, please refresh the page and try again.") | ||
} | ||
let vcodeActualVal = getImgBase64Result(parseInt(vcodeValOrderIdx)) | ||
console.log('vcode', { vcodeActualVal, val }) | ||
if (_.toLower(vcodeActualVal) !== _.toLower(val)) { | ||
await fn_cleanVCode() | ||
return Dot("HaU4NMabv", "Verification code is incorrect, please re-input or refresh the image.") | ||
} | ||
await daoRef.redis.del(vcodeLabel) | ||
return null; | ||
} | ||
} | ||
} |
16 changes: 7 additions & 9 deletions
16
...]/src/parts/user/register/action/auth.tsx → modules/server2/src/routes/auth/auth.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use server' | ||
|
||
import { UserRole } from "@/dao/model"; | ||
import { UserModel } from "@/models/oldjava.model"; | ||
import _ from "lodash"; | ||
import { fn_add_user_into_active, fn_get_system_info_from_redis } from "./user-types"; | ||
import { getSignatureFromStr } from "./auth"; | ||
import { Elb3AuthBody, getUserInfoByUserAcctId } from "./userAction"; | ||
import { logger } from "@/utils/logger"; | ||
|
||
export type SystemInfoBody = { | ||
userCount: number, | ||
userOnlineCount: number, | ||
peakOnlineCount: number, | ||
} | ||
|
||
export type AuthInfo = { | ||
user: UserModel | null, | ||
signedIn: boolean, | ||
furtherUserDetail?: { | ||
userRole: UserRole, | ||
}, | ||
systemInfo: SystemInfoBody | ||
} | ||
export let header_ELB3_auth = "elb3-auth" | ||
export type fn_getCookie = (name: string) => string | ||
|
||
export default async (getCookie: fn_getCookie): Promise<AuthInfo> => { | ||
let systemInfo = await fn_get_system_info_from_redis() | ||
let elb3AuthStr = getCookie(header_ELB3_auth); | ||
if (!_.isEmpty(elb3AuthStr)) { | ||
try { | ||
let [expiredTS, body, singature, version] = elb3AuthStr?.split(".") as string[]; | ||
let crtTime = new Date(); | ||
if (crtTime.getTime() > parseInt(expiredTS)) { | ||
throw new Error("expired"); | ||
} | ||
let c_sig = getSignatureFromStr(body); | ||
if (c_sig != singature) { | ||
throw new Error("signature not match"); | ||
} | ||
let push: Elb3AuthBody = JSON.parse(atob(body)) | ||
let userInfo = await getUserInfoByUserAcctId(push.userAcctId) | ||
await fn_add_user_into_active(push.userAcctId) | ||
return { | ||
systemInfo, | ||
user: userInfo, | ||
signedIn: userInfo != null, | ||
} | ||
} catch (e) { | ||
// unable to decode, meaning it is not a valid elb3-auth | ||
logger.error("decode error" + e) | ||
// if they have elb3-auth, but it is not valid, then we should remove it and redirect the user to /login | ||
} | ||
} else { | ||
// pass through | ||
} | ||
return { | ||
systemInfo, | ||
user: null, | ||
signedIn: false | ||
} | ||
} |
Oops, something went wrong.