-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from SCCapstone/JO-14
Sign Up, Log in, Log Out, and Admin View Restricted Function
- Loading branch information
Showing
27 changed files
with
4,811 additions
and
8,703 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.