voting without an account redirects to login
This commit is contained in:
parent
c04cf3889e
commit
ce7957e0bf
3 changed files with 11 additions and 4 deletions
|
@ -28,9 +28,9 @@ let calcVote = function(up,down) {
|
|||
var rating = -Math.log((1 / ((((upPadded - downPadded) / (upPadded + downPadded)) + 1) / 2)) - 1) / Math.log(Math.E);
|
||||
|
||||
rating = Math.min(rating,10);
|
||||
rating = Math.max(rating,-10);
|
||||
rating = Math.max(rating,-1);
|
||||
|
||||
rating = (rating + 10) / 2;
|
||||
rating = (rating + 11) / 1.1;
|
||||
|
||||
return rating * Math.log(totalPadded);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ export async function GET({ url, cookies }) {
|
|||
|
||||
var user = await tokenBackend({token});
|
||||
|
||||
if (!user) return;
|
||||
if (!user) return new Response('fail');
|
||||
|
||||
var id = url.searchParams.get('post');
|
||||
var vote = url.searchParams.get('vote');
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').PageLoad} */
|
||||
export async function load({ fetch, params, url }) {
|
||||
var search = url.searchParams;
|
||||
|
@ -7,7 +9,12 @@ export async function load({ fetch, params, url }) {
|
|||
var id = params.post;
|
||||
|
||||
if (voteType) {
|
||||
await fetch(`/api/vote?post=${id}&vote=${voteType}`);
|
||||
var voteRes = await fetch(`/api/vote?post=${id}&vote=${voteType}`);
|
||||
var voteJson = await voteRes.text();
|
||||
|
||||
if (voteJson == 'fail') {
|
||||
throw redirect(302, '/account');
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
|
Loading…
Reference in a new issue