Browse Source

15分钟自命名临时用户

pull/6/head
hole-thu 5 years ago
parent
commit
e7d57c9d7a
  1. 2
      src/Common.js
  2. 2
      src/Flows.js
  3. 19
      src/Message.css
  4. 32
      src/Message.js
  5. 1
      src/Title.js

2
src/Common.js

@ -142,7 +142,7 @@ export class HighlightedMarkdown extends Component {
<img <img
src={normalize_url(node.attribs.src)} src={normalize_url(node.attribs.src)}
alt={node.alt} alt={node.alt}
referrerpolicy="no-referrer" referrerPolicy="no-referrer"
/> />
</a> </a>
); );

2
src/Flows.js

@ -420,7 +420,7 @@ class FlowSidebar extends PureComponent {
this.setState({ this.setState({
loading_status: 'done', loading_status: 'done',
}); });
alert('设置关注失败'); alert('设置关注失败\n' + e);
console.error(e); console.error(e);
}); });
} }

19
src/Message.css

@ -0,0 +1,19 @@
.input-prepend {
display: inline-block;
background-color: #c9cccf;
border: 1px solid #ced4da;
height: 28px;
padding: 3px;
vertical-align: top;
}
.input-suf {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 90px;
height: 28px;
border: 1px solid #ced4da;
vertical-align: top;
padding: 3px;
}

32
src/Message.js

@ -2,6 +2,8 @@ import React, { PureComponent } from 'react';
import { Time } from './Common'; import { Time } from './Common';
import { get_json } from './infrastructure/functions'; import { get_json } from './infrastructure/functions';
import './Message.css';
export class MessageViewer extends PureComponent { export class MessageViewer extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
@ -9,6 +11,7 @@ export class MessageViewer extends PureComponent {
loading_status: 'idle', loading_status: 'idle',
msg: [], msg: [],
}; };
this.input_suf_ref=React.createRef();
} }
componentDidMount() { componentDidMount() {
@ -32,7 +35,8 @@ export class MessageViewer extends PureComponent {
loading_status: 'done', loading_status: 'done',
msg: json.data, msg: json.data,
start_time: json.start_time, start_time: json.start_time,
salt: json.salt salt: json.salt,
tmp_token: json.tmp_token,
}); });
}) })
.catch((err) => { .catch((err) => {
@ -46,6 +50,20 @@ export class MessageViewer extends PureComponent {
); );
} }
do_set_token() {
if (this.state.loading_status==='loading')
return;
if (!this.input_suf_ref.current.value) {
alert("不建议后缀为空");
return;
}
let tt = this.state.tmp_token + '_' + this.input_suf_ref.current.value;
console.log(tt);
localStorage['TOKEN'] = tt;
alert('已登录为临时用户,过期后需注销重新登陆');
window.location.reload();
}
render() { render() {
if (this.state.loading_status === 'loading') if (this.state.loading_status === 'loading')
return <p className="box box-tip">加载中</p>; return <p className="box box-tip">加载中</p>;
@ -71,8 +89,18 @@ export class MessageViewer extends PureComponent {
<p> <p>
随机盐 <b>{this.state.salt}</b> 随机盐 <b>{this.state.salt}</b>
</p> </p>
<br/>
<div>
<p>15分钟临时token:</p>
<div className="input-prepend">{this.state.tmp_token}_ </div>
<input type="text" className="input-suf" ref={this.input_suf_ref} placeholder="自定义后缀" maxLength={10}/>
<button type="button" disabled={this.state.loading_status==='loading'}
onClick={(e)=>this.do_set_token()}>
使用
</button>
</div>
{this.state.msg.map((msg) => ( {this.state.msg.map((msg) => (
<div className="box" key={msg.timestamp}> <div className="box" key={msg.type + msg.timestamp}>
<div className="box-header"> <div className="box-header">
<Time stamp={msg.timestamp} short={false} /> <Time stamp={msg.timestamp} short={false} />
&nbsp; &nbsp;

1
src/Title.js

@ -100,6 +100,7 @@ class ControlBar extends PureComponent {
search_text: '', search_text: '',
}); });
this.set_mode('list', null); this.set_mode('list', null);
window.location.hash = '';
} }
do_attention() { do_attention() {

Loading…
Cancel
Save