Skip to content

Commit

Permalink
refactor(flat-pages): refactor personal page layout & add email/phone…
Browse files Browse the repository at this point in the history
… binding (#2004)
  • Loading branch information
syt-honey authored Aug 17, 2023
1 parent 719cb00 commit 74e4aeb
Show file tree
Hide file tree
Showing 20 changed files with 899 additions and 230 deletions.
24 changes: 17 additions & 7 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"the-room-has-been-removed": "The room has been removed",
"history": "History",
"begin": "Begin",
"join-options": "Join Options",
"join-options": "Join Room Options",
"create-room-default-title": "The room created by {{name}}",
"turn-on-the-camera": "Camera",
"turn-on-cursor-name": "Show cursor name of others",
Expand Down Expand Up @@ -333,10 +333,19 @@
"user-already-binding": "You have already bound the account",
"user-password-incorrect": "Password is incorrect",
"user-account-or-password-incorrect": "Account or password is incorrect",
"phone": "Phone",
"email": "Email",
"password": "Password",
"set-binding-phone": "Bind Phone",
"set-binding-email": "Bind Email",
"delete-binding-email-tips": "Are you sure to unbind {{email}} ?",
"delete-binding-phone-tips": "Are you sure to unbind {{phone}} ?",
"email-verification-code-invalid": "Email verification code is invalid",
"email-already-exist": "Email already exists",
"email-already-binding": "Email already bound",
"email-failed-to-send-code": "Email verification code send failed",
"email-set-success": "Email set successfully",
"phone-set-success": "Phone set successfully",
"voucher-expired": "The credentials have expired, please log in again",
"check-updates": "Check updates",
"exit-replay": "Exit replay",
Expand Down Expand Up @@ -397,6 +406,7 @@
"incorrect-code": "Incorrect verification code",
"has-reset-password": "Your password has been reset",
"enter-code": "Please enter verification code",
"enter-email": "Please enter your email account",
"enter-email-or-phone": "Please enter your email account or phone number",
"pwd-login": "login with password",
"verify-code-login": "login with verification code",
Expand Down Expand Up @@ -467,7 +477,7 @@
"device-test": "Devices Test",
"close-tip": "Close tip",
"device-test-option": "Device Test Options",
"turn-on-device-test": "Turn on device test on entering room",
"turn-on-device-test": "Device test",
"user-guide-text": "Want to learn more about {{appName}}? ",
"user-guide-button": "Check it out now",
"start-recording": "Start recording",
Expand Down Expand Up @@ -516,22 +526,22 @@
"password-not-match": "Password not match. Please Check",
"update-password": "Update Password",
"set-password": "Set Password",
"password-already-set": "The password is set and you can log in with the password",
"not-set-password": "You have not set a password yet",
"user-account": "Account",
"user-profile": "User Profile",
"user-profile": "My Profile",
"username": "Name",
"avatar": "Avatar",
"upload-avatar": "Upload Avatar",
"upload-avatar-failed": "Upload avatar failed",
"bind-wechat": "Bind WeChat",
"bind-wechat-failed": "Failed to bind WeChat",
"bind-github-failed": "Failed to bind Github",
"bind-google-failed": "Failed to bind Google",
"bind-wechat-not-support-unbind": "Not support unbind WeChat",
"is-bind": "is bind",
"not-bind": "not bind",
"unbind-confirm": "Are you sure to unbind?",
"unbind-success": "Unbind success",
"delete-account": "Delete Account",
"delete-account-desc": "You will not be able to log on to this account after log off. E-mail, mobile phone, third-party accounts will be unbundled",
"confirm-delete-account": "Are you sure to delete your account?",
"quit-all-rooms-before-delete-account": "Please quit all rooms before deleting account.",
"all-off-stage": "Down Stage All",
Expand All @@ -555,7 +565,7 @@
},
"recording-settings": {
"title": "Recording Options",
"auto-recording": "Turn on recording on entering room"
"auto-recording": "Auto recording"
},
"whiteboard-settings": {
"title": "Whiteboard Options",
Expand Down
28 changes: 19 additions & 9 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
"history": "历史记录",
"create-room-default-title": "{{name}} 创建的房间",
"begin": "开始",
"join-options": "加入选项",
"join-options": "加入房间选项",
"turn-on-the-camera": "开启摄像头",
"turn-on-cursor-name": "显示对方光标昵称",
"enter-room-uuid": "请输入房间号",
Expand Down Expand Up @@ -333,10 +333,19 @@
"user-already-binding": "用户已绑定",
"user-password-incorrect": "密码错误",
"user-account-or-password-incorrect": "用户账号或密码错误",
"phone": "手机",
"email": "邮箱",
"password": "密码",
"set-binding-email": "绑定邮箱",
"set-binding-phone": "绑定手机",
"delete-binding-email-tips": "确定要删除关联邮箱 {{email}} 吗?",
"delete-binding-phone-tips": "确定要删除关联手机号 {{phone}} 吗?",
"email-verification-code-invalid": "邮箱验证码错误",
"email-already-exist": "邮箱已存在",
"email-already-binding": "邮箱已绑定",
"email-failed-to-send-code": "邮箱验证码发送失败",
"email-set-success": "邮箱绑定成功",
"phone-set-success": "手机绑定成功",
"replay-does-not-exist": "回放不存在",
"check-updates": "检查更新",
"latest-version-tips": "当前已是最新版本",
Expand Down Expand Up @@ -394,6 +403,7 @@
"incorrect-code": "验证码错误",
"has-reset-password": "密码已重置",
"enter-code": "请输入验证码",
"enter-email": "请输入邮箱",
"enter-email-or-phone": "请输入邮箱或手机号",
"enter-password": "请输入密码",
"enter-new-password": "请输入新密码",
Expand Down Expand Up @@ -467,7 +477,7 @@
"device-test": "设备检测",
"close-tip": "不再提示",
"device-test-option": "设备检测选项",
"turn-on-device-test": "进入房间时检测",
"turn-on-device-test": "设备检测",
"user-guide-text": "想了解更多 {{appName}} 的使用技巧?",
"user-guide-button": "立即查看",
"start-recording": "开始录制",
Expand Down Expand Up @@ -516,22 +526,22 @@
"password-not-match": "密码输入不一致,请检查",
"update-password": "修改密码",
"set-password": "设置密码",
"password-already-set": "已设置,可通过密码登录",
"not-set-password": "未设置密码",
"user-account": "账号安全",
"user-profile": "用户资料",
"user-profile": "我的资料",
"username": "昵称",
"avatar": "头像",
"upload-avatar": "上传头像",
"upload-avatar-failed": "上传头像失败",
"bind-wechat": "绑定微信",
"bind-wechat-failed": "绑定失败",
"bind-wechat-failed": "微信绑定失败",
"bind-github-failed": "Github绑定失败",
"bind-google-failed": "Google绑定失败",
"bind-wechat-not-support-unbind": "暂未支持解绑",
"is-bind": "已绑定",
"not-bind": "未绑定",
"unbind-confirm": "确定解除绑定吗?",
"unbind-success": "解绑成功",
"delete-account": "账号注销",
"delete-account-desc": "注销后你将不能再登录此帐号。邮箱、手机、第三方帐号均将被解绑",
"confirm-delete-account": "确定注销账号吗?",
"quit-all-rooms-before-delete-account": "请先退出所有房间",
"all-off-stage": "全体下台",
Expand All @@ -555,11 +565,11 @@
},
"recording-settings": {
"title": "录制选项",
"auto-recording": "进入房间自动开启录制"
"auto-recording": "自动录制"
},
"whiteboard-settings": {
"title": "笔锋选项",
"pencil-tail": "开启铅笔笔锋"
"pencil-tail": "开启笔锋"
},
"upload-avatar-size-limit": "头像大小不能超过 5MB",
"upload-image-size-limit": "图片大小不能超过 5MB",
Expand Down
19 changes: 10 additions & 9 deletions packages/flat-pages/src/LoginPage/googleLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import { GOOGLE } from "../constants/process";
export const googleLogin: LoginExecutor = (onSuccess, windowsBtn) => {
let timer = NaN;
const authUUID = uuidv4();
const scopes = ["openid", "https://www.googleapis.com/auth/userinfo.profile"];

function getGoogleURL(authUUID: string): string {
const redirectURL = encodeURIComponent(FLAT_SERVER_LOGIN.GOOGLE_CALLBACK);
const scope = encodeURIComponent(scopes.join(" "));
return `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=online&scope=${scope}&client_id=${GOOGLE.CLIENT_ID}&redirect_uri=${redirectURL}&state=${authUUID}`;
}

void (async () => {
try {
Expand All @@ -26,8 +19,10 @@ export const googleLogin: LoginExecutor = (onSuccess, windowsBtn) => {
}

windowsBtn
? windowsBtn.openExternalBrowser(getGoogleURL(authUUID))
: void window.open(getGoogleURL(authUUID));
? windowsBtn.openExternalBrowser(
getGoogleURL(authUUID, FLAT_SERVER_LOGIN.GOOGLE_CALLBACK),
)
: void window.open(getGoogleURL(authUUID, FLAT_SERVER_LOGIN.GOOGLE_CALLBACK));

const googleLoginProcessRequest = async (): Promise<void> => {
try {
Expand All @@ -51,3 +46,9 @@ export const googleLogin: LoginExecutor = (onSuccess, windowsBtn) => {
window.clearTimeout(timer);
};
};

export function getGoogleURL(authUUID: string, redirect_uri: string): string {
const scopes = ["openid", "https://www.googleapis.com/auth/userinfo.profile"];
const scope = encodeURIComponent(scopes.join(" "));
return `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=online&scope=${scope}&client_id=${GOOGLE.CLIENT_ID}&redirect_uri=${redirect_uri}&state=${authUUID}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { Button, Form, Modal, message } from "antd";
import React, { useCallback, useState } from "react";
import {
LoginAccount,
LoginSendCode,
PasswordLoginType,
codeValidator,
emailValidator,
errorTips,
} from "flat-components";
import { BindingEmailPayload, bindingEmail, bindingEmailSendCode } from "@netless/flat-server-api";
import { useLanguage, useTranslate } from "@netless/flat-i18n";

import { useSafePromise } from "../../utils/hooks/lifecycle";

export interface UpdateEmailModelProps {
visible: boolean;
title: string;
onCancel: () => void;
onConfirm: () => void;
onRefresh: () => void;
}

export const UpdateEmailModel: React.FC<UpdateEmailModelProps> = ({
visible,
title,
onCancel,
onConfirm,
onRefresh,
}) => {
const language = useLanguage();
const t = useTranslate();
const sp = useSafePromise();
const emailLanguage = language.startsWith("zh") ? "zh" : "en";

const [form] = Form.useForm<BindingEmailPayload>();
const [isFormValidated, setIsFormValidated] = useState(false);
const [isAccountValidated, setIsAccountValidated] = useState(false);

const type = PasswordLoginType.Email;

const defaultValues = {
email: "",
code: "",
};

const [loading, setLoading] = useState(false);

const clearAll = useCallback((): void => {
onRefresh();
form.resetFields();
}, [form, onRefresh]);

const onOk = useCallback(async () => {
const { email, code } = form.getFieldsValue();

try {
setLoading(true);
await sp(bindingEmail(email, Number(code)));

message.success(t("email-set-success"));
setLoading(false);

setIsFormValidated(false);
clearAll();
onConfirm();
} catch (e) {
setLoading(false);
console.error(e);
errorTips(e);
}
}, [clearAll, form, onConfirm, sp, t]);

const formValidateStatus = useCallback(() => {
setIsFormValidated(
form.getFieldsError().every(field => field.errors.length <= 0) &&
Object.values(form.getFieldsValue()).every(v => !!v),
);

if (form.getFieldValue("email") && !form.getFieldError("email").length) {
setIsAccountValidated(true);
} else {
setIsAccountValidated(false);
}
}, [form]);

const sendVerificationCode = async (): Promise<any> => {
const { email } = form.getFieldsValue();
return bindingEmailSendCode(email, emailLanguage);
};

return (
<Modal
centered
forceRender
footer={[
<Button key="exit-cancel" onClick={onCancel}>
{t("cancel")}
</Button>,
<Button
key="exit-confirm"
disabled={!isFormValidated}
loading={loading}
onClick={onOk}
>
{t("confirm")}
</Button>,
]}
open={visible}
title={title}
width={352}
onCancel={onCancel}
>
<Form
form={form}
initialValues={defaultValues}
name="rebindEmail"
onFieldsChange={formValidateStatus}
>
<Form.Item name="email" rules={[emailValidator]}>
<LoginAccount onlyEmail={true} placeholder={t("enter-email")} />
</Form.Item>

<Form.Item name="code" rules={[codeValidator]}>
<LoginSendCode
isAccountValidated={isAccountValidated}
sendVerificationCode={sendVerificationCode}
type={type}
/>
</Form.Item>
</Form>
</Modal>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const UpdatePasswordModel: React.FC<UpdatePasswordModelProps> = ({
<Modal
centered
forceRender
className="update-password-container"
footer={[
<Button key="exit-cancel" onClick={onCancel}>
{t("cancel")}
Expand Down
Loading

0 comments on commit 74e4aeb

Please sign in to comment.