Guest User

Untitled

a guest
Jul 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. module.exports = function(sequelize, Sequelize) {
  2. var User = sequelize.define('User', {
  3. id: {
  4. type: Sequelize.INTEGER(11),
  5. allowNull: true,
  6. primaryKey: true,
  7. autoIncrement: true
  8. },
  9. user_id: {
  10. type: Sequelize.STRING(255),
  11. allowNull: true,
  12. defaultValue: ''
  13. }
  14. }
  15.  
  16. User.prototype.getJWT = function () {
  17. let expiration_time = parseInt(CONFIG.jwt_expiration);
  18. return "Bearer "+jwt.sign({user_id:this.user_id, role:this.role}, CONFIG.jwt_encryption, {expiresIn: expiration_time});
  19. }
  20. return User
  21. }
  22.  
  23. User.create(body).then((user)=>{
  24. if (user) {
  25. console.log(user);
  26. user = user.toWeb()
  27. user.token = user.getJWT();
  28. user.message = "Successfully created new user";
  29.  
  30. res.json(user);
  31. }
  32.  
  33. }).catch(e=>{
  34. console.log(e);
  35. })
Add Comment
Please, Sign In to add comment