- App
- SignUp
- SignIn
- General info
- API
- Front
- Vuelidate
- Persisted-state
- Token in front
- Vuex
- VueRouter
- Technologies
- Pratice
- Difficulty
- Contact
This App is an E-commerce, you can:
- signup
- signin (token)
- add a product to your cart
- add a product to sell
- visualize the product and detail
- sort the product list by categorie
- edit your cart (qty)
- edit your profil (change email, name..)
- edit your product (change price, add promotion)
- have acces to your order history
- ....
Handle error :
var mailformat = /^[\w-]+@([\w-]+\.)+[\w-]{2,4}$/g; switch (true) { case userObject.firstName.length < 3: alert("first name error: min 3 character"); break; case userObject.lastName.length < 3: alert("last name error: min 3 character"); break; case userObject.url.length < 10: alert("url profile picture require"); break; case userObject.password < 8: alert("password minimun 8 character"); break; case !userObject.email.match(mailformat): alert("email incorrect"); break; case userObject.password !== this.state.confirmPassword: alert("confirm password error"); break; default:Handle if an user already use this email Back-End:
/*********************** Check if user with this email already exist *************************/ await app.use("/users/sign-up", (req, res, next) => { console.log(req.body.email); connection.query( `SELECT * FROM users WHERE email = '${req.body.email}'`, (err, results) => { if (err) throw err; if (results.length > 0) { res.status(200).send("this EMAIL already exist"); } else { next(); } } ); });Api, Back-end (token, bcrypt)
await app.post("/users/sign-in", function(req, res) { let password = req.body.password; let email = req.body.email; let hash = ""; connection.query(sqlRequestUsers.mailUser, [email], function(err, results) { if (err) throw err; // handle email error if (!Array.isArray(results) || !results.length) { res.send("Sorry, email incorrect"); } else { let name = results[0].name; let id = results[0].id; /******* TOKEN *******/ let token = jwt.sign( { email: email, name: name, id: id }, config.secret ); hash = results[0].password; // handle password error bcrypt.compare(password, hash, function(err, result) { if (result == true) { // get the decoded payload ignoring signature, no secretOrPrivateKey needed var decoded = jwt.decode(token); // get the decoded payload and header var decoded = jwt.decode(token, { complete: true }); res.status(200).send({ auth: true, token: token, email: email, id: id, }); } else { res.send("password error"); } }); } }); }); 
