user.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @swagger
  3. *
  4. * components:
  5. * schemas:
  6. * User:
  7. * description: User
  8. * type: object
  9. * properties:
  10. * __v:
  11. * type: number
  12. * description: record version
  13. * example: 0
  14. * _id:
  15. * type: string
  16. * description: user ID
  17. * example: 5ae5fccfc5577b0004dbd8ab
  18. * lang:
  19. * type: string
  20. * description: language
  21. * example: 'en_US'
  22. * status:
  23. * type: integer
  24. * description: status
  25. * example: 0
  26. * admin:
  27. * type: boolean
  28. * description: whether the admin
  29. * example: false
  30. * email:
  31. * type: string
  32. * description: E-Mail address
  33. * example: alice@aaa.aaa
  34. * username:
  35. * type: string
  36. * description: username
  37. * example: alice
  38. * name:
  39. * type: string
  40. * description: full name
  41. * example: Alice
  42. * createdAt:
  43. * type: string
  44. * description: date created at
  45. * example: 2010-01-01T00:00:00.000Z
  46. */
  47. module.exports = function(crowi, app) {
  48. const User = crowi.model('User');
  49. const ApiResponse = require('../util/apiResponse');
  50. const actions = {};
  51. const api = {};
  52. actions.api = api;
  53. api.checkUsername = async function(req, res) {
  54. const username = req.query.username;
  55. let valid = false;
  56. await User.findUserByUsername(username)
  57. .then((userData) => {
  58. if (userData) {
  59. valid = false;
  60. }
  61. else {
  62. valid = true;
  63. }
  64. })
  65. .catch((err) => {
  66. valid = false;
  67. });
  68. return res.json(ApiResponse.success({ valid }));
  69. };
  70. return actions;
  71. };