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})} /> +
++
- -