waaa
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import mysql2, { Connection, RowDataPacket, OkPacket, QueryError } from "mysql2";
|
||||
import { getConnection } from "@/db";
|
||||
import { Post, postPlaceholder } from "@/model/Models";
|
||||
import { getPosts, IPost } from "@/controller/Post";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { MPost, MUser, MAuth } from "@/model/Models"
|
||||
import { Sequelize } from "sequelize";
|
||||
import { Elsie_Swash_Caps } from "next/font/google";
|
||||
|
||||
export default async function handler(req:NextApiRequest, res:NextApiResponse) {
|
||||
await MUser.sync();
|
||||
await MAuth.sync();
|
||||
switch (req.method) {
|
||||
case 'POST':
|
||||
case 'GET':
|
||||
const users = await MUser.findAll();
|
||||
// res.status(200).json(posts);
|
||||
let username = req.body.username;
|
||||
let password = req.body.password;
|
||||
console.log(req.body );
|
||||
if(users.length == 0){
|
||||
MUser.create({
|
||||
username: "admin",
|
||||
password: "changeme"
|
||||
})
|
||||
}
|
||||
users.forEach(user => async {
|
||||
if(user.username == username && user.password == password){
|
||||
try{
|
||||
const authtoken = await MAuth.findOne({where : {user_id: user.id}});
|
||||
if(authtoken != null){
|
||||
res.status(200).json({"status":"correct"});
|
||||
console.log(authtoken);
|
||||
}
|
||||
else{
|
||||
res.status(200).json({"status":"no such auth token"});
|
||||
}
|
||||
} catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
console.log(user.password);
|
||||
res.status(200).json({"status":"incorrect"});
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user