user.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. /** Get controllers */
  3. const userController = require('../controllers/user');
  4. const authMiddleware = require('../middlewares/auth');
  5. /**
  6. * Account routes
  7. * You can create, see, update and delete a user using email a social account (Facebook and Twitter are available now)
  8. *
  9. * @param {Router} - express router
  10. */
  11. module.exports = function (router, passport) {
  12. /**
  13. * Account management
  14. */
  15. router.route('/account')
  16. /** Auth Middleware applied to all routes below */
  17. .all(authMiddleware)
  18. /** GET /account - Get an account profile */
  19. .get(userController.accountGet)
  20. /** PUT /account - Update an account */
  21. .put(userController.accountPut)
  22. /** DELETE /account - Delete an account */
  23. .delete(userController.accountDelete);
  24. /**
  25. * Sign up to create a new account
  26. */
  27. router.route('/signup')
  28. /** GET /signup - UI to create a new account */
  29. .get(userController.signupGet)
  30. /** POST /signup - Create a new account */
  31. .post(userController.signupPost);
  32. /**
  33. * Login page
  34. */
  35. router.route('/login')
  36. /** GET /login - login's UI */
  37. .get(userController.loginGet)
  38. /** POST /login - Login into an account */
  39. .post(userController.loginPost);
  40. /**
  41. * User's password recovery
  42. */
  43. router.route('/forgot')
  44. /** GET /forgot - UI to recover user's password */
  45. .get(userController.forgotGet)
  46. /** POST /forgot - recover user's password */
  47. .post(userController.forgotPost);
  48. /**
  49. * Reset forgoted user's password
  50. * @param {string} token - Token validation
  51. */
  52. router.route('/reset/:token')
  53. /** GET /reset:token - UI to reset user's password */
  54. .get(userController.resetGet)
  55. /** POST /reset:token - reset forgoted user's password */
  56. .post(userController.resetPost);
  57. /**
  58. * Logout
  59. */
  60. router.route('/logout')
  61. /** GET /logout - Logout user **/
  62. .get(userController.logout);
  63. /**
  64. * Disconnect user's social media provider
  65. * @param {string} provider - social media provider (Facebook and Twitter are available now)
  66. */
  67. router.route('/unlink/:provider')
  68. /** GET /unlink/:provider - Disconnect user's social media account */
  69. .get(authMiddleware, userController.unlink);
  70. /**
  71. * Authentication using Facebook
  72. */
  73. router.route('/auth/facebook')
  74. /** GET /auth/facebook - Authentication using Facebook */
  75. .get(passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
  76. /**
  77. * Authentication callback using Facebook
  78. */
  79. router.route('/auth/facebook/callback')
  80. /** GET /auth/facebook/callback - Authentication callback using Facebook */
  81. .get(passport.authenticate('facebook', { successRedirect: '/', failureRedirect: '/login' }));
  82. /**
  83. * Authentication using Twitter
  84. */
  85. router.route('/auth/twitter')
  86. /** GET /auth/twitter - Authentication using Twitter */
  87. .get(passport.authenticate('twitter'));
  88. /**
  89. * Authentication callback using Twitter
  90. */
  91. router.route('/auth/twitter/callback')
  92. /** GET /auth/twitter/callback - Authentication callback using Twitter */
  93. .get(passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/login' }));
  94. /**
  95. * Authentication using Github - Not available rigth now
  96. */
  97. router.route('/auth/github')
  98. /** GET /auth/github - Authentication using Github */
  99. .get(passport.authenticate('github', { scope: [ 'user:email profile repo' ] }));
  100. /**
  101. * Authentication callback using Github - Not available rigth now
  102. */
  103. router.route('/auth/github/callback')
  104. /** GET /auth/github/callback - Authentication callback using Github */
  105. .get(passport.authenticate('github', { successRedirect: '/', failureRedirect: '/login' }));
  106. return router;
  107. }