Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const app = express();
- const Employee = require("../models/employee");
- const mysql = require("mysql");
- const db = mysql.createConnection({
- host: "127.0.0.1",
- user: "root",
- password: ""
- });
- db.connect(err => {
- if (err) {
- console.log(err);
- }
- console.log("SQL server active from the accountServices side");
- });
- exports.createAccount = (req, res, err) => {
- const { name, email, password, password2, phonenumber } = req.body;
- if (!name || !email || !password || !password2) {
- errors.push({ msg: "Please enter all fields" });
- }
- if (password != password2) {
- errors.push("There was an error with your password!");
- }
- if (password < 6) {
- errors.push("Please keep passwords at least 6 characters long! ");
- }
- if (errors.length > 0) {
- res.render("register", {
- errors,
- name,
- email,
- password,
- password2
- });
- } else {
- let query = `SELECT COUNT(email) FROM employee WHERE email = '${email}'`;
- db.query(query, function(err, result) {
- if (err) throw err;
- if (result.count > 1) {
- errors.push("Email already in use!");
- }
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement