Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. const express = require("express");
  2.  
  3. const app = express();
  4. const Employee = require("../models/employee");
  5.  
  6. const mysql = require("mysql");
  7. const db = mysql.createConnection({
  8. host: "127.0.0.1",
  9. user: "root",
  10. password: ""
  11. });
  12.  
  13. db.connect(err => {
  14. if (err) {
  15. console.log(err);
  16. }
  17.  
  18. console.log("SQL server active from the accountServices side");
  19. });
  20.  
  21. exports.createAccount = (req, res, err) => {
  22. const { name, email, password, password2, phonenumber } = req.body;
  23.  
  24. if (!name || !email || !password || !password2) {
  25. errors.push({ msg: "Please enter all fields" });
  26. }
  27. if (password != password2) {
  28. errors.push("There was an error with your password!");
  29. }
  30.  
  31. if (password < 6) {
  32. errors.push("Please keep passwords at least 6 characters long! ");
  33. }
  34. if (errors.length > 0) {
  35. res.render("register", {
  36. errors,
  37. name,
  38. email,
  39. password,
  40. password2
  41. });
  42. } else {
  43. let query = `SELECT COUNT(email) FROM employee WHERE email = '${email}'`;
  44. db.query(query, function(err, result) {
  45. if (err) throw err;
  46. if (result.count > 1) {
  47. errors.push("Email already in use!");
  48. }
  49. });
  50. }
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement