Guest User

Untitled

a guest
Aug 17th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. User.js
  2. const mongoose = require('mongoose');
  3. var bcrypt = require('bcryptjs');
  4.  
  5. const userSchema = mongoose.Schema({
  6. userName: {
  7. type: String,
  8. required: true
  9. },
  10. email: {
  11. type: String,
  12. required: true
  13. },
  14. password: {
  15. type: String,
  16. required: true,
  17. bcrypt: true
  18. },
  19. type: {
  20. type: String,
  21. required: true
  22. },
  23. dateJoined: {
  24. type: Date,
  25. default: Date.now
  26. }
  27. });
  28.  
  29. var User = module.exports = mongoose.model('User', userSchema);
  30.  
  31. // Fetch events
  32. module.exports.getUsers = function(callback, limit) {
  33. User.find(callback).limit(limit);
  34. }
  35.  
  36. // Fetch single event
  37. module.exports.getUserByUsername = function(username, callback) {
  38. var query = {username: username};
  39. User.find(query, callback);
  40. }
  41.  
  42. // Register Students
  43. module.exports.registerStudent = function(newUser, newStudent, callback) {
  44. bcrypt.hash(newUser.password, 15, function(err, hash) {
  45. if(err) throw err;
  46. newUser.password = hash;
  47. console.log('Student is regiestered');
  48. async.parallel([newUser.save, newStudent.save], callback);
  49. });
  50. }
  51.  
  52. // Register Faculty
  53. module.exports.registerFaculty = function(newUser, newFaculty, callback) {
  54. bcrypt.hash(newUser.password, 15, function(err, hash) {
  55. if(err) throw err;
  56. newUser.password = hash;
  57. console.log('Faculty is regiestered');
  58. async.parallel([newFaculty.save, newStudent.save], callback);
  59. });
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. Student.js
  68. const mongoose = require('mongoose');
  69.  
  70. const studentSchema = mongoose.Schema({
  71. firstName: {
  72. type: String,
  73. required: true
  74. },
  75. LastName: {
  76. type: String,
  77. required: true
  78. },
  79. userName: {
  80. type: String,
  81. required: true
  82. },
  83. email: {
  84. type: String,
  85. required: true
  86. },
  87. events: [{
  88. eventId: {type: [mongoose.Schema.Types.ObjectId]},
  89. eventTitle: {type: String}
  90. }]
  91. });
  92.  
  93. var Student = module.exports = mongoose.model('Student', studentSchema);
  94.  
  95. // Fetch events
  96. module.exports.getStudent = function(callback, limit) {
  97. Student.find(callback).limit(limit);
  98. }
  99.  
  100. // Fetch single event
  101. module.exports.getStudentByUsername = function(username, callback) {
  102. var query = {username: username};
  103. Student.find(query, callback);
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. Faculty.js
  114. const mongoose = require('mongoose');
  115.  
  116. const facultySchema = mongoose.Schema({
  117. firstName: {
  118. type: String,
  119. required: true
  120. },
  121. LastName: {
  122. type: String,
  123. required: true
  124. },
  125. userName: {
  126. type: String,
  127. required: true
  128. },
  129. email: {
  130. type: String,
  131. required: true
  132. },
  133. events: [{
  134. eventId: {type: [mongoose.Schema.Types.ObjectId]},
  135. eventTitle: {type: String}
  136. }]
  137. });
  138.  
  139. var Faculty = module.exports = mongoose.model('Faculty', facultySchema);
  140.  
  141. // Fetch events
  142. module.exports.getFaculty = function(callback, limit) {
  143. User.find(callback).limit(limit);
  144. }
  145.  
  146. // Fetch single event
  147. module.exports.getFacultyByUsername = function(username, callback) {
  148. var query = {username: username};
  149. User.find(query, callback);
  150. }
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. signup.handlebars
  159. <div class="container">
  160. <h4 class="center">New User Registration</h4>
  161.  
  162. <form action="/users/signup" method="post">
  163. <input type="hidden" value="student" id="type">
  164. <div class="row">
  165. <div class="input-field col s6">
  166. <input id="firstName" type="text" class="validate" name="firstName" value="{{firstName}}">
  167. <label for="firstName">First Name</label>
  168. </div>
  169. <div class="input-field col s6">
  170. <input id="lastName" type="text" class="validate" name="lastName" value="{{lastName}}">
  171. <label for="lastName">Last Name</label>
  172. </div>
  173. </div>
  174. <div class="row">
  175. <div class="input-field col s6">
  176. <input id="email" type="email" class="validate" name="email" value="{{email}}">
  177. <label for="email">Email</label>
  178. </div>
  179. <div class="input-field col s6">
  180. <input id="ernumber" type="text" class="validate" name="ernumber" value="{{ernumber}}">
  181. <label for="ernumber">Enrollment Number</label>
  182. </div>
  183. </div>
  184. <div class="row">
  185. <div class="input-field col s6">
  186. <input id="password" type="password" class="validate" name="password">
  187. <label for="password">Password</label>
  188. </div>
  189. <div class="input-field col s6">
  190. <input id="repassword" type="password" class="validate" name="repassword">
  191. <label for="repassword">Retype Password</label>
  192. </div>
  193. </div>
  194. <div class="row center-align">
  195. <button type="submit" class="btn btn-large green waves-effect waves-light">Register</button>
  196. <button type="reset" class="btn btn-large btn-flat">Reset</button>
  197. </div>
  198. </form>
  199.  
  200. </div>
Add Comment
Please, Sign In to add comment