From e170afe2a5bba9ead60e407f47bd0c19288a014e Mon Sep 17 00:00:00 2001 From: hole-thu Date: Sat, 12 Nov 2022 23:52:51 +0800 Subject: [PATCH] email login --- src/UserAction.js | 2 +- src/infrastructure/widgets.css | 5 +- src/infrastructure/widgets.js | 97 ++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/src/UserAction.js b/src/UserAction.js index 9ca271a..d1d4f80 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -19,7 +19,7 @@ import { save_attentions } from './Attention'; import './UserAction.css'; const REPOSITORY = 'https://git.thu.monster/newthuhole/'; -const EMAIL = 'hole_thu@riseup.net'; +export const EMAIL = 'hole_thu@riseup.net'; export const TokenCtx = React.createContext({ value: null, diff --git a/src/infrastructure/widgets.css b/src/infrastructure/widgets.css index 6ead413..ed5d7b2 100644 --- a/src/infrastructure/widgets.css +++ b/src/infrastructure/widgets.css @@ -239,10 +239,11 @@ a.app-switcher-item, margin: 0.25em 1em; text-align: left; } -.thuhole-login-popup-info ul { +.thuhole-login-popup-info ul, +.thuhole-login-popup-info ol { margin: 0.75em 1em; text-align: left; - font-size: 75%; + font-size: 80%; } /* override ant design */ .thuhole-login-popup input, diff --git a/src/infrastructure/widgets.js b/src/infrastructure/widgets.js index 709b140..b3dab2e 100644 --- a/src/infrastructure/widgets.js +++ b/src/infrastructure/widgets.js @@ -4,11 +4,13 @@ import ReactDOM from 'react-dom'; import TimeAgo from 'react-timeago'; import chineseStrings from 'react-timeago/lib/language-strings/zh-CN'; import buildFormatter from 'react-timeago/lib/formatters/buildFormatter'; +import copy from 'copy-to-clipboard'; import './global.css'; import './widgets.css'; import { get_json, API_VERSION_PARAM } from './functions'; +import { EMAIL } from '../UserAction'; function pad2(x) { return x < 10 ? '0' + x : '' + x; @@ -55,31 +57,87 @@ export function GlobalTitle(props) { ); } +async function sha256_hex(text, l = null) { + let hash_buffer = await window.crypto.subtle.digest('SHA-256' , new TextEncoder().encode(text)); + let hex_str = Array.from(new Uint8Array(hash_buffer)).map((b) => b.toString(16).padStart(2, '0')).join(''); + return l ? hex_str.slice(0, l) : hex_str +} + class LoginPopupSelf extends Component { constructor(props) { super(props); this.state = { - loading_status: 'idle', + token_phrase: '', }; - - this.input_token_ref = React.createRef(); } - setThuhole(e, tar, ref) { - console.log(tar); + setThuhole(e) { e.preventDefault(); - tar.href = '/_login?p=thuhole&token=' + ref.current.value; - console.log(tar); alert('T大树洞已经没有啦😭'); } + copy_token_hash(event) { + const { token_phrase } = this.state; + if (!token_phrase) { + alert('不可以为空'); + return; + } + + sha256_hex(token_phrase + 'hole' + new Date().toDateString(), 16) + .then((token) => sha256_hex(token + 'hole', 16)) + .then((token_hash) => copy('|' + token_hash + '|')); + } + + use_token(event) { + const { token_phrase } = this.state; + if (!token_phrase) { + alert('不可以为空'); + return; + } + + sha256_hex(token_phrase + 'hole' + new Date().toDateString(), 16) + .then((token) => { + localStorage['TOKEN'] = 'sha256:' + token; + window.location.reload(); + }); + } + render() { + const { token_phrase } = this.state; return (

- 通过第三方验证登陆新T树洞 +

直接邮箱登陆

+

+

+ this.setState({token_phrase: event.target.value})} /> +

+
+
    +
  1. + 输入任意独特内容或 + this.setState({token_phrase: window.crypto.randomUUID()})}> + 使用随机值 + + ,以生成token。请务必保存好输入的内容,并避免泄漏。 +
  2. +
  3. + 点击此处 + 复制token的哈希,通过你的清华邮箱发送到 + {EMAIL}。不同设备在同一天输入相同内容即可,请勿重复发件。 +
  4. +
  5. + 后台每15分钟查收一次邮件,等待一段时间后 + 点击此处 + 使用此token登陆。 +
  6. +
+
+
+

+

第三方认证登陆

- -
{ - this.setThuhole(e, e.target, this.input_token_ref); - }} + onClick={this.setThuhole} >  T大树洞 @@ -111,12 +165,6 @@ class LoginPopupSelf extends Component {  清华大水群

-

- -