Commit 8c0ad0cf authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

ex01 finished

parent a82832bf
......@@ -4,15 +4,14 @@ const { register } = require("../services/register");
var router = express.Router();
router.post("/login", (req, res) => {
const {email, password} = req.body
const result = login(email, password);
res.send(result);
const {email, password} = req.body;
const result = login(email, password, res);
})
router.post("/register", async (req, res) => {
const {email, username, firstName, lastName, password, repeatPassword} = req.body;
const result = register(email, username, firstName, lastName, password, repeatPassword);
res.send(result);
const result = await register(email, username, firstName, lastName, password, repeatPassword);
res.json(result);
})
module.exports = router;
\ No newline at end of file
const { getMaxListeners } = require("process");
const { writeUsers, readUsers } = require("../db/db");
const Users = require("../models/user");
const login = (email, password) => {
try {
console.log(Users.find({email: "pif"}));
} catch (err) {
return {
success: false,
error: err || 'error' }
}
const login = (email, password, res) => {
Users.findOne({'email': email}, function(err, result) {
if (err) throw (err);
if (result != "") {
if (result.email == email) {
if (result.password == password) {
return res.json({ success: true, data: result});
} else {
return res.json({ success: false, error: 'Password do not match'});
}
}
}
return res.json({ success: false, error: 'Email not registered'});
});
}
module.exports = {
......
const Users = require("../models/user");
const register = (email, username, firstName, lastName, password, repeatPassword) =>{
const register = async (email, username, firstName, lastName, password, repeatPassword) =>{
if (password == repeatPassword) {
try {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment