Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User.js
- const mongoose = require('mongoose');
- var bcrypt = require('bcryptjs');
- const userSchema = mongoose.Schema({
- userName: {
- type: String,
- required: true
- },
- email: {
- type: String,
- required: true
- },
- password: {
- type: String,
- required: true,
- bcrypt: true
- },
- type: {
- type: String,
- required: true
- },
- dateJoined: {
- type: Date,
- default: Date.now
- }
- });
- var User = module.exports = mongoose.model('User', userSchema);
- // Fetch events
- module.exports.getUsers = function(callback, limit) {
- User.find(callback).limit(limit);
- }
- // Fetch single event
- module.exports.getUserByUsername = function(username, callback) {
- var query = {username: username};
- User.find(query, callback);
- }
- // Register Students
- module.exports.registerStudent = function(newUser, newStudent, callback) {
- bcrypt.hash(newUser.password, 15, function(err, hash) {
- if(err) throw err;
- newUser.password = hash;
- console.log('Student is regiestered');
- async.parallel([newUser.save, newStudent.save], callback);
- });
- }
- // Register Faculty
- module.exports.registerFaculty = function(newUser, newFaculty, callback) {
- bcrypt.hash(newUser.password, 15, function(err, hash) {
- if(err) throw err;
- newUser.password = hash;
- console.log('Faculty is regiestered');
- async.parallel([newFaculty.save, newStudent.save], callback);
- });
- }
- Student.js
- const mongoose = require('mongoose');
- const studentSchema = mongoose.Schema({
- firstName: {
- type: String,
- required: true
- },
- LastName: {
- type: String,
- required: true
- },
- userName: {
- type: String,
- required: true
- },
- email: {
- type: String,
- required: true
- },
- events: [{
- eventId: {type: [mongoose.Schema.Types.ObjectId]},
- eventTitle: {type: String}
- }]
- });
- var Student = module.exports = mongoose.model('Student', studentSchema);
- // Fetch events
- module.exports.getStudent = function(callback, limit) {
- Student.find(callback).limit(limit);
- }
- // Fetch single event
- module.exports.getStudentByUsername = function(username, callback) {
- var query = {username: username};
- Student.find(query, callback);
- }
- Faculty.js
- const mongoose = require('mongoose');
- const facultySchema = mongoose.Schema({
- firstName: {
- type: String,
- required: true
- },
- LastName: {
- type: String,
- required: true
- },
- userName: {
- type: String,
- required: true
- },
- email: {
- type: String,
- required: true
- },
- events: [{
- eventId: {type: [mongoose.Schema.Types.ObjectId]},
- eventTitle: {type: String}
- }]
- });
- var Faculty = module.exports = mongoose.model('Faculty', facultySchema);
- // Fetch events
- module.exports.getFaculty = function(callback, limit) {
- User.find(callback).limit(limit);
- }
- // Fetch single event
- module.exports.getFacultyByUsername = function(username, callback) {
- var query = {username: username};
- User.find(query, callback);
- }
- signup.handlebars
- <div class="container">
- <h4 class="center">New User Registration</h4>
- <form action="/users/signup" method="post">
- <input type="hidden" value="student" id="type">
- <div class="row">
- <div class="input-field col s6">
- <input id="firstName" type="text" class="validate" name="firstName" value="{{firstName}}">
- <label for="firstName">First Name</label>
- </div>
- <div class="input-field col s6">
- <input id="lastName" type="text" class="validate" name="lastName" value="{{lastName}}">
- <label for="lastName">Last Name</label>
- </div>
- </div>
- <div class="row">
- <div class="input-field col s6">
- <input id="email" type="email" class="validate" name="email" value="{{email}}">
- <label for="email">Email</label>
- </div>
- <div class="input-field col s6">
- <input id="ernumber" type="text" class="validate" name="ernumber" value="{{ernumber}}">
- <label for="ernumber">Enrollment Number</label>
- </div>
- </div>
- <div class="row">
- <div class="input-field col s6">
- <input id="password" type="password" class="validate" name="password">
- <label for="password">Password</label>
- </div>
- <div class="input-field col s6">
- <input id="repassword" type="password" class="validate" name="repassword">
- <label for="repassword">Retype Password</label>
- </div>
- </div>
- <div class="row center-align">
- <button type="submit" class="btn btn-large green waves-effect waves-light">Register</button>
- <button type="reset" class="btn btn-large btn-flat">Reset</button>
- </div>
- </form>
- </div>
Add Comment
Please, Sign In to add comment