Spaces:
Sleeping
Sleeping
Download models/User.js from arifian853/mc-server: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/spaces/arifian853/mc-server/resolve/main/models/User.js
- Command line
-
hf download hf://spaces/arifian853/mc-server/models/User.js
-
curl -L -o User.js https://huggingface.co/spaces/arifian853/mc-server/resolve/main/models/User.js
804 Bytes
| const mongoose = require('mongoose'); | |
| const bcrypt = require('bcryptjs'); | |
| const userSchema = new mongoose.Schema({ | |
| username: { | |
| type: String, | |
| required: true, | |
| unique: true, | |
| trim: true | |
| }, | |
| password: { | |
| type: String, | |
| required: true | |
| }, | |
| role: { | |
| type: String, | |
| enum: ['admin'], | |
| default: 'admin' | |
| } | |
| }, { | |
| timestamps: true | |
| }); | |
| // Hash password before saving | |
| userSchema.pre('save', async function() { | |
| if (!this.isModified('password')) return; | |
| const salt = await bcrypt.genSalt(10); | |
| this.password = await bcrypt.hash(this.password, salt); | |
| }); | |
| // Compare password method | |
| userSchema.methods.comparePassword = async function(candidatePassword) { | |
| return bcrypt.compare(candidatePassword, this.password); | |
| }; | |
| module.exports = mongoose.model('User', userSchema); |