12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import BaseStore from '@src/stores/base';
- import * as querystring from 'querystring';
- const SENTENCE_TRAIL = 'SENTENCE_TRAIL';
- export default class UserStore extends BaseStore {
- initState() {
- const { token } = querystring.parse(window.location.search.replace('?', ''));
- if (token) {
- this.setToken(token);
- }
- const sentenceTrail = this.getLocal(SENTENCE_TRAIL);
- return { login: !!token, sentenceTrail };
- }
-
- sentenceTrail() {
- this.saveLocal(SENTENCE_TRAIL, true);
- this.setState({ sentenceTrail: true });
- }
-
- clearSentenceTrail() {
- this.removeLocal(SENTENCE_TRAIL);
- this.setState({ sentenceTrail: null });
- }
-
- token() {
- return this.apiPost('/auth/token');
- }
-
- login(mobile, mobileVerifyCode, inviteCode) {
- return this.apiPost('/auth/login', { mobile, mobileVerifyCode, inviteCode });
- }
- loginWechat(code) {
- return this.apiGet('/auth/wechat_pc', { code }).then(() => {
- this.setState({ login: true });
- });
- }
-
- logout() {
- return this.apiPost('/auth/logout');
- }
-
- bind(mobile, mobileVerifyCode, inviteCode) {
- return this.apiPost('/auth/bind', { mobile, mobileVerifyCode, inviteCode });
- }
-
- validInviteCode(code) {
- return this.apiGet('/auth/valid/invite_code', { code });
- }
-
- validMobile(mobile) {
- return this.apiGet('/auth/valid/mobile', { mobile });
- }
- }
- export const User = new UserStore({ key: 'user', local: true });
|