From c92f84c24f7c60eb48729864a5fe220b6d4df62c Mon Sep 17 00:00:00 2001 From: muerwre Date: Fri, 30 Nov 2018 15:15:52 +0700 Subject: [PATCH] backend: auth bug fix --- backend/routes/auth/check.js | 2 ++ backend/routes/auth/social/vk.js | 10 ++++-- backend/routes/route/post.js | 2 +- src/constants/api.js | 1 - src/modules/Editor.js | 6 +--- src/modules/Shotter.js | 62 -------------------------------- src/utils/api.js | 10 ------ 7 files changed, 12 insertions(+), 81 deletions(-) delete mode 100644 src/modules/Shotter.js diff --git a/backend/routes/auth/check.js b/backend/routes/auth/check.js index be2545d..18d793a 100644 --- a/backend/routes/auth/check.js +++ b/backend/routes/auth/check.js @@ -7,6 +7,8 @@ module.exports = async (req, res) => { const user = await User.findOne({ _id: id, token }); const random_url = await generateRandomUrl(); + console.log('USER', { id, token }); + if (user) { return res.send({ success: true, ...user.toObject(), id: user._id, random_url }); } diff --git a/backend/routes/auth/social/vk.js b/backend/routes/auth/social/vk.js index ad4a0e0..3f1e6e3 100644 --- a/backend/routes/auth/social/vk.js +++ b/backend/routes/auth/social/vk.js @@ -65,9 +65,15 @@ module.exports = async (req, res) => { first_name, last_name, name, photo }).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 { - 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 }); } diff --git a/backend/routes/route/post.js b/backend/routes/route/post.js index 07c37cf..2dc9a2f 100644 --- a/backend/routes/route/post.js +++ b/backend/routes/route/post.js @@ -6,7 +6,7 @@ module.exports = async (req, res) => { const { body, body: { id, token, force } } = req; 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 address = parseString(body.address, 32); diff --git a/src/constants/api.js b/src/constants/api.js index 0bb94a3..3c1dd49 100644 --- a/src/constants/api.js +++ b/src/constants/api.js @@ -2,7 +2,6 @@ export const SERVER = 'http://alpha-map.vault48.org'; export const TEST = 'http://localhost:3000'; export const API = { - COMPOSE: `${SERVER}/engine/composerOrchid.php`, GET_GUEST: `${TEST}/auth`, CHECK_TOKEN: `${TEST}/auth`, GET_MAP: `${TEST}/route`, diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 7636d43..9375f9d 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -3,7 +3,6 @@ import { Poly } from '$modules/Poly'; import { MODES } from '$constants/modes'; import { Stickers } from '$modules/Stickers'; import { Router } from '$modules/Router'; -import { Shotter } from '$modules/Shotter'; import { DEFAULT_LOGO } from '$constants/logos'; import { parseStickerAngle, parseStickerStyle } from '$utils/import'; @@ -42,7 +41,7 @@ export class Editor { this.router = new Router({ map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints }); - this.shotter = new Shotter({ map }); + // this.shotter = new Shotter({ map }); this.switches = { [MODES.POLY]: { @@ -54,9 +53,6 @@ export class Editor { toggle: this.clearMode, start: this.routerSetStart, }, - [MODES.SHOTTER]: { - start: this.shotter.makeShot, - }, [MODES.STICKERS]: { toggle: this.clearSticker, }, diff --git a/src/modules/Shotter.js b/src/modules/Shotter.js deleted file mode 100644 index 756b657..0000000 --- a/src/modules/Shotter.js +++ /dev/null @@ -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); - } -} diff --git a/src/utils/api.js b/src/utils/api.js index a9e42ae..d2772b9 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -2,22 +2,12 @@ import axios from 'axios/index'; import { API } from '$constants/api'; -const report = console.warn; - export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, { params: { 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 getMergedImage = ({ placement, callback }) => ( - axios.get(API.COMPOSE, { - params: { placement } - }) - .then(callback) - .catch(report) -); - export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, { params: { name } }).then(result => (result && result.data));