aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/models/user_model.ts
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-05-15 19:10:07 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-05-15 19:10:07 -0700
commit253d5efbbafe4a44c350fef7dda6d553a70a94c9 (patch)
treeb43a55e1efddc86e25df4bb7d90a99f3c7b52a17 /src/server/authentication/models/user_model.ts
parent36c01920e3874e1484222a7012745b581405f67d (diff)
parent08b6bf8b51ab631c8cfe9c3e12bfb0ae2dd7b4c7 (diff)
merge with master
Diffstat (limited to 'src/server/authentication/models/user_model.ts')
-rw-r--r--src/server/authentication/models/user_model.ts86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
deleted file mode 100644
index 78e39dbc1..000000000
--- a/src/server/authentication/models/user_model.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-//@ts-ignore
-import * as bcrypt from "bcrypt-nodejs";
-//@ts-ignore
-import * as mongoose from 'mongoose';
-
-export type DashUserModel = mongoose.Document & {
- email: String,
- password: string,
- passwordResetToken?: string,
- passwordResetExpires?: Date,
-
- userDocumentId: string;
-
- profile: {
- name: string,
- gender: string,
- location: string,
- website: string,
- picture: string
- },
-
- comparePassword: comparePasswordFunction,
-};
-
-type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void;
-
-export type AuthToken = {
- accessToken: string,
- kind: string
-};
-
-const userSchema = new mongoose.Schema({
- email: String,
- password: String,
- passwordResetToken: String,
- passwordResetExpires: Date,
-
- userDocumentId: String,
-
- facebook: String,
- twitter: String,
- google: String,
-
- profile: {
- name: String,
- gender: String,
- location: String,
- website: String,
- picture: String
- }
-}, { timestamps: true });
-
-/**
- * Password hash middleware.
- */
-userSchema.pre("save", function save(next) {
- const user = this as DashUserModel;
- if (!user.isModified("password")) {
- return next();
- }
- bcrypt.genSalt(10, (err, salt) => {
- if (err) {
- return next(err);
- }
- bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => {
- if (err) {
- return next(err);
- }
- user.password = hash;
- next();
- });
- });
-});
-
-const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) {
- // Choose one of the following bodies for authentication logic.
- // secure
- bcrypt.compare(candidatePassword, this.password, cb);
- // bypass password
- // cb(undefined, true);
-};
-
-userSchema.methods.comparePassword = comparePassword;
-
-const User = mongoose.model("User", userSchema);
-export default User; \ No newline at end of file