now user can login

This commit is contained in:
muerwre 2018-08-28 16:58:36 +07:00
parent e7960a6bf8
commit e19001ca82
25 changed files with 493 additions and 32844 deletions

33
src/utils/api.js Normal file
View file

@ -0,0 +1,33 @@
import axios from 'axios/index';
import { API } from '$constants/api';
const report = console.warn;
export const checkUserToken = ({
callback, fallback, id, token
}) => (
axios.get(API.GET_GUEST, {
params: { action: 'check_token', id, token }
})
.then(result => (result && result.data))
.then(data => ({ ...data, id, token }))
.then(callback)
.catch(fallback)
);
export const getGuestToken = ({ callback }) => (
axios.get(API.GET_GUEST, {
params: { action: 'gen_guest_token' }
})
.then(result => (result && result.data))
.then(callback)
.catch(report)
);
export const getMergedImage = ({ placement, callback }) => (
axios.get(API.COMPOSE, {
params: { placement }
})
.then(callback)
.catch(report)
);

25
src/utils/storage.js Normal file
View file

@ -0,0 +1,25 @@
const canStore = typeof window.localStorage !== 'undefined'
export const storeData = (key, data) => {
if (!canStore) return;
const value = JSON.stringify(data);
localStorage.setItem(key, value);
};
export const getData = key => {
if (!canStore) return;
let result = null;
try {
result = JSON.parse(localStorage.getItem(key));
} catch(e) {
result = null;
}
if (!result) return;
return result;
};