Skip to content

Commit

Permalink
cu
Browse files Browse the repository at this point in the history
  • Loading branch information
Twoguini committed Dec 22, 2023
1 parent fa56d0a commit 6f80c11
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/queries/usersGrades.js → src/queries/getUsersGrades.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createClient } from '@supabase/supabase-js';
import { myApplicationKey, myApplicationURL } from '../secrets.js';
import { is } from 'type-is';

const db = createClient(
myApplicationURL,
Expand All @@ -9,7 +10,8 @@ const db = createClient(
const { data, error } = await db
.from('students')
.select('nome, grade')
.order('grade', {ascending: false})
.not('grade', 'is', null)
.order('grade', {ascending: false})
;

export {
Expand Down
Empty file added src/queries/postUsersGrades.js
Empty file.
24 changes: 24 additions & 0 deletions src/queries/usersSingUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createClient } from "@supabase/supabase-js";
import { myApplicationKey, myApplicationURL } from "../secrets.js";

const db = createClient (
myApplicationURL,
myApplicationKey
);

async function createAcc(username, password){

const { error } = await db
.from('students')
.insert({ nome: username, password: password })

if (error){
console.log(error)
return(false)
}
else {
return(true)
}
};

export default createAcc;
28 changes: 20 additions & 8 deletions src/routes/User.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express'
import ifNull from '../firstInfoValidation/login.js';
import verifyLogIn from '../queries/usersLogin.js';
import createAcc from '../queries/usersSingUp.js';

const users = express.Router()

Expand All @@ -22,14 +23,13 @@ users.post("/", async (req, res) => {
return
}

const dCountExist = await verifyLogIn(username, password)
const dAcountExist = await verifyLogIn(username, password)

if (dCountExist === false){
console.log('Não tem')
if (dAcountExist === false){
errors.push({ text: "Conta não Encontrada" })
res.render('login', { errors: errors })
}
else if (dCountExist === true){
else if (dAcountExist === true){
req.flash("success_msg", "Login Efetivado com Sucesso");
res.status(200);
res.redirect('/home');
Expand All @@ -45,7 +45,7 @@ users.get('/signup', (req, res) => {
res.render('signUp');
});

users.post('/signup', (req, res) => {
users.post('/signup', async (req, res) => {
// NOTE: Creating ACC
const username = req.body.User;
const password = req.body.Pass;
Expand All @@ -54,12 +54,24 @@ users.post('/signup', (req, res) => {

if (errors.length > 0) {
res.render("signUp", { errors: errors });

return
}

req.flash("success_msg", "Conta Criada com Sucesso");
res.redirect('/');
const acountCreated = await createAcc(username, password)

console.log(acountCreated)

if(acountCreated === true){

req.flash("success_msg", "Conta Criada com Sucesso");
res.status(201)
res.redirect('/');
}
else{
errors.push({ text: "Não foi Possível Criar a Conta" })
res.render('singUp', { errors: errors })
}

});

export default users;
2 changes: 1 addition & 1 deletion src/routes/WebQuest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import {data, dbGradeError} from '../queries/usersGrades.js';
import {data, dbGradeError} from '../queries/getUsersGrades.js';

const webQuest = express.Router();

Expand Down

0 comments on commit 6f80c11

Please sign in to comment.