mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
backend: auth bug fix
This commit is contained in:
parent
d932fcb287
commit
c92f84c24f
7 changed files with 12 additions and 81 deletions
|
@ -7,6 +7,8 @@ module.exports = async (req, res) => {
|
||||||
const user = await User.findOne({ _id: id, token });
|
const user = await User.findOne({ _id: id, token });
|
||||||
const random_url = await generateRandomUrl();
|
const random_url = await generateRandomUrl();
|
||||||
|
|
||||||
|
console.log('USER', { id, token });
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
return res.send({ success: true, ...user.toObject(), id: user._id, random_url });
|
return res.send({ success: true, ...user.toObject(), id: user._id, random_url });
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,15 @@ module.exports = async (req, res) => {
|
||||||
first_name, last_name, name, photo
|
first_name, last_name, name, photo
|
||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user });
|
console.log('AUTH', auth.toObject());
|
||||||
|
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user, token: auth.token });
|
||||||
} else {
|
} else {
|
||||||
const created = await User.create(user, (err, result) => result.toObject());
|
const created = await User.create(user, (err, result) => {
|
||||||
|
if (err) console.log('ERRRRRR', err);
|
||||||
|
|
||||||
|
console.log('USER', result);
|
||||||
|
return result.toObject();
|
||||||
|
});
|
||||||
|
|
||||||
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user, ...created });
|
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user, ...created });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = async (req, res) => {
|
||||||
const { body, body: { id, token, force } } = req;
|
const { body, body: { id, token, force } } = req;
|
||||||
|
|
||||||
const owner = await User.findOne({ _id: id, token });
|
const owner = await User.findOne({ _id: id, token });
|
||||||
if (!owner) return res.send({ success: false, reason: 'Unauthorized' });
|
if (!owner) return res.send({ success: false, reason: 'unauthorized', id, token });
|
||||||
|
|
||||||
const title = parseString(body.title, 32);
|
const title = parseString(body.title, 32);
|
||||||
const address = parseString(body.address, 32);
|
const address = parseString(body.address, 32);
|
||||||
|
|
|
@ -2,7 +2,6 @@ export const SERVER = 'http://alpha-map.vault48.org';
|
||||||
export const TEST = 'http://localhost:3000';
|
export const TEST = 'http://localhost:3000';
|
||||||
|
|
||||||
export const API = {
|
export const API = {
|
||||||
COMPOSE: `${SERVER}/engine/composerOrchid.php`,
|
|
||||||
GET_GUEST: `${TEST}/auth`,
|
GET_GUEST: `${TEST}/auth`,
|
||||||
CHECK_TOKEN: `${TEST}/auth`,
|
CHECK_TOKEN: `${TEST}/auth`,
|
||||||
GET_MAP: `${TEST}/route`,
|
GET_MAP: `${TEST}/route`,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Poly } from '$modules/Poly';
|
||||||
import { MODES } from '$constants/modes';
|
import { MODES } from '$constants/modes';
|
||||||
import { Stickers } from '$modules/Stickers';
|
import { Stickers } from '$modules/Stickers';
|
||||||
import { Router } from '$modules/Router';
|
import { Router } from '$modules/Router';
|
||||||
import { Shotter } from '$modules/Shotter';
|
|
||||||
import { DEFAULT_LOGO } from '$constants/logos';
|
import { DEFAULT_LOGO } from '$constants/logos';
|
||||||
|
|
||||||
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
|
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
|
||||||
|
@ -42,7 +41,7 @@ export class Editor {
|
||||||
this.router = new Router({
|
this.router = new Router({
|
||||||
map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints
|
map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints
|
||||||
});
|
});
|
||||||
this.shotter = new Shotter({ map });
|
// this.shotter = new Shotter({ map });
|
||||||
|
|
||||||
this.switches = {
|
this.switches = {
|
||||||
[MODES.POLY]: {
|
[MODES.POLY]: {
|
||||||
|
@ -54,9 +53,6 @@ export class Editor {
|
||||||
toggle: this.clearMode,
|
toggle: this.clearMode,
|
||||||
start: this.routerSetStart,
|
start: this.routerSetStart,
|
||||||
},
|
},
|
||||||
[MODES.SHOTTER]: {
|
|
||||||
start: this.shotter.makeShot,
|
|
||||||
},
|
|
||||||
[MODES.STICKERS]: {
|
[MODES.STICKERS]: {
|
||||||
toggle: this.clearSticker,
|
toggle: this.clearSticker,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import axios from 'axios';
|
|
||||||
import { getMergedImage } from '$utils/api';
|
|
||||||
|
|
||||||
export class Shotter {
|
|
||||||
constructor({ map }) {
|
|
||||||
this.tiles = [];
|
|
||||||
this.tilesLoaded = 0;
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
latLngToTile = latlng => {
|
|
||||||
const z = this.map.getZoom();
|
|
||||||
const x = parseInt(Math.floor(((latlng.lng + 180) / 360) * (1 << z)), 10);
|
|
||||||
const y = parseInt(Math.floor((1 - (Math.log(Math.tan((latlng.lat * Math.PI) / 180)
|
|
||||||
+ 1 / Math.cos((latlng.lat * Math.PI) / 180)) / Math.PI)) / 2 * (1 << z)), 10);
|
|
||||||
return { x, y, z };
|
|
||||||
};
|
|
||||||
|
|
||||||
tileToLatLng = point => {
|
|
||||||
const z = this.map.getZoom();
|
|
||||||
const lng = (((point.x / (2 ** z)) * 360) - 180);
|
|
||||||
|
|
||||||
const n = Math.PI - ((2 * Math.PI * point.y) / (2 ** z));
|
|
||||||
const lat = (180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
|
|
||||||
|
|
||||||
return { lat, lng };
|
|
||||||
};
|
|
||||||
|
|
||||||
getTilePlacement() {
|
|
||||||
const { innerHeight, innerWidth } = window;
|
|
||||||
const { _southWest, _northEast } = this.map.getBounds();
|
|
||||||
|
|
||||||
const sw = this.latLngToTile(_southWest);
|
|
||||||
const ne = this.latLngToTile(_northEast);
|
|
||||||
|
|
||||||
const zsw = this.tileToLatLng(sw);
|
|
||||||
const zne = this.tileToLatLng(ne);
|
|
||||||
|
|
||||||
const rsw = this.map.latLngToContainerPoint(zsw);
|
|
||||||
const msw = this.map.latLngToContainerPoint(_southWest);
|
|
||||||
|
|
||||||
return {
|
|
||||||
min_x: sw.x,
|
|
||||||
min_y: ne.y,
|
|
||||||
max_x: ne.x,
|
|
||||||
max_y: sw.y,
|
|
||||||
sh_x: (rsw.x - msw.x),
|
|
||||||
sh_y: ((innerHeight + rsw.y) - msw.y),
|
|
||||||
size: 256,
|
|
||||||
width: innerWidth,
|
|
||||||
height: innerHeight,
|
|
||||||
zoom: this.map.getZoom(),
|
|
||||||
provider: 'dgis',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
makeShot = () => {
|
|
||||||
const placement = this.getTilePlacement();
|
|
||||||
|
|
||||||
getMergedImage(placement);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,22 +2,12 @@ import axios from 'axios/index';
|
||||||
|
|
||||||
import { API } from '$constants/api';
|
import { API } from '$constants/api';
|
||||||
|
|
||||||
const report = console.warn;
|
|
||||||
|
|
||||||
export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, {
|
export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, {
|
||||||
params: { id, token }
|
params: { id, token }
|
||||||
}).then(result => (result && result.data && { ...result.data, id, token }));
|
}).then(result => (result && result.data && { ...result.data, id, token }));
|
||||||
|
|
||||||
export const getGuestToken = () => axios.get(API.GET_GUEST).then(result => (result && result.data));
|
export const getGuestToken = () => axios.get(API.GET_GUEST).then(result => (result && result.data));
|
||||||
|
|
||||||
export const getMergedImage = ({ placement, callback }) => (
|
|
||||||
axios.get(API.COMPOSE, {
|
|
||||||
params: { placement }
|
|
||||||
})
|
|
||||||
.then(callback)
|
|
||||||
.catch(report)
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
|
export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
|
||||||
params: { name }
|
params: { name }
|
||||||
}).then(result => (result && result.data));
|
}).then(result => (result && result.data));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue