Skip to content

Commit

Permalink
Merge pull request #73 from SCCapstone/JO-14
Browse files Browse the repository at this point in the history
Sign Up, Log in, Log Out, and Admin View Restricted Function
  • Loading branch information
rahulbulusu authored Nov 30, 2022
2 parents e6d1c19 + 02376c1 commit b4ecb58
Show file tree
Hide file tree
Showing 27 changed files with 4,811 additions and 8,703 deletions.
15 changes: 0 additions & 15 deletions backend/data.js

This file was deleted.

18 changes: 18 additions & 0 deletions backend/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const mongoose = require("mongoose");

module.exports = () => {
const connectionParams = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
try {
mongoose.connect(
"mongodb+srv://adminuser:[email protected]/?retryWrites=true&w=majority",
connectionParams
);
console.log("Connected to database successfully");
} catch (error) {
console.log(error);
console.log("Could not connect database!");
}
};
33 changes: 33 additions & 0 deletions backend/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const mongoose = require("mongoose");
const jwt = require("jsonwebtoken");
const Joi = require("joi");
const passwordComplexity = require("joi-password-complexity");

const userSchema = new mongoose.Schema({
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true },
password: { type: String, required: true },
});

userSchema.methods.generateAuthToken = function () {
const token = jwt.sign({ _id: this._id }, process.env.JWTPRIVATEKEY, {
expiresIn: "7d",
});
return token;
};

const User = mongoose.model("user", userSchema);

const validate = (data) => {
const schema = Joi.object({
firstName: Joi.string().required().label("First Name"),
lastName: Joi.string().required().label("Last Name"),
email: Joi.string().required().label("Email"),
password: Joi.string().required().label("Password"),
// password: passwordComplexity.required().label("Password")
});
return schema.validate(data);
};

module.exports = { User, validate };
Loading

0 comments on commit b4ecb58

Please sign in to comment.