Update
This commit is contained in:
@@ -10,7 +10,7 @@ const addAnswer = async ({ request, response, params, state, render }) => {
|
||||
const topicId = params.tId;
|
||||
const questionId = params.qId;
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const body = request.body({ type: "form-data" });
|
||||
const body = request.body({ type: "form" });
|
||||
const formData = await body.value;
|
||||
const answerData = {
|
||||
option: formData.get("option"),
|
||||
|
||||
@@ -15,8 +15,10 @@ const showRegister = ({ render }) => {
|
||||
};
|
||||
|
||||
const register = async ({ request, response, render }) => {
|
||||
const body = request.body({ type: "form-data" });
|
||||
const body = request.body({ type: "form" });
|
||||
console.log(body);
|
||||
const params = await body.value;
|
||||
console.log(params);
|
||||
const userData = {
|
||||
email: params.get("email"),
|
||||
password: params.get("password"),
|
||||
@@ -29,20 +31,18 @@ const register = async ({ request, response, render }) => {
|
||||
render("register.eta", userData);
|
||||
} else {
|
||||
const hashedPassword = await bcrypt.hash(userData.password);
|
||||
const user = await authService.createUser(userData.email, hashedPassword);
|
||||
response.direct("/auth/login");
|
||||
await authService.createUser(userData.email, hashedPassword);
|
||||
response.redirect("/auth/login");
|
||||
}
|
||||
};
|
||||
|
||||
const login = async ({ request, response, state, render }) => {
|
||||
const body = request.body({ type: "form" });
|
||||
const params = await body.value;
|
||||
|
||||
const userDatabase = await authService.findUser(params.get("email"));
|
||||
|
||||
if (userDatabase.length < 1) {
|
||||
response.status = 422;
|
||||
render("login.eta", { error: "User not found!" });
|
||||
render("login.eta", { error: { error: "User not found!" } });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ const login = async ({ request, response, state, render }) => {
|
||||
|
||||
if (!passwordCorrect) {
|
||||
response.status = 422;
|
||||
render("login.eta", { error: "Incorrect password!" });
|
||||
render("login.eta", { errors: { error: "Incorrect password!" } });
|
||||
return;
|
||||
}
|
||||
|
||||
await state.session.set("authenticated", user);
|
||||
response.direct("/topics");
|
||||
await state.session.set("user", user);
|
||||
response.redirect("/topics");
|
||||
};
|
||||
|
||||
export { showLogin, showRegister, register, login };
|
||||
|
||||
@@ -10,7 +10,7 @@ const validationRules = {
|
||||
const addQuestion = async ({ request, response, params, state, render }) => {
|
||||
const topicId = params.tId;
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const body = request.body({ type: "form-data" });
|
||||
const body = request.body({ type: "form" });
|
||||
const formData = await body.value;
|
||||
const topicName = (await topicService.getTopicByTopicId(topicId)).name;
|
||||
const questionData = {
|
||||
|
||||
@@ -8,7 +8,7 @@ const validationRules = {
|
||||
const addTopic = async ({ request, response, render, state }) => {
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const admin = (await state.session.get("user")).admin;
|
||||
const body = request.body({ type: "form-data" });
|
||||
const body = request.body({ type: "form" });
|
||||
const params = await body.value;
|
||||
const topicData = {
|
||||
admin: admin,
|
||||
@@ -46,7 +46,7 @@ const listTopics = async ({ render, state }) => {
|
||||
const user = await state.session.get("user");
|
||||
render("topics.eta", {
|
||||
admin: user.admin,
|
||||
allTopics: await topicService.getAllTopics(),
|
||||
topics: await topicService.getAllTopics(),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user