You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user.go 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright © 2023 OpenIM open source community. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package api
  15. import (
  16. "github.com/gin-gonic/gin"
  17. "github.com/OpenIMSDK/OpenKF/server/internal/common"
  18. "github.com/OpenIMSDK/OpenKF/server/internal/common/response"
  19. requestparams "github.com/OpenIMSDK/OpenKF/server/internal/params/request"
  20. "github.com/OpenIMSDK/OpenKF/server/internal/service"
  21. "github.com/OpenIMSDK/OpenKF/server/pkg/log"
  22. )
  23. // AdminRegister
  24. // @Tags user
  25. // @Summary AdminRegister
  26. // @Description Create a new admin
  27. // @Produce application/json
  28. // @Param data body param.RegisterAdminParams true "RegisterAdminParams"
  29. // @Success 200 {object} response.Response{msg=string} "Success"
  30. // @Router /api/v1/register/admin [post].
  31. func AdminRegister(c *gin.Context) {
  32. var params requestparams.RegisterAdminParams
  33. err := c.ShouldBindJSON(&params)
  34. if err != nil {
  35. response.FailWithCode(common.INVALID_PARAMS, c)
  36. return
  37. }
  38. svc := service.NewUserService(c)
  39. _, _, err = svc.CreateAdmin(&params)
  40. if err != nil {
  41. log.Debug("AdminRegister error", err)
  42. response.FailWithCode(common.ERROR, c)
  43. return
  44. }
  45. response.Success(c)
  46. }
  47. // StaffRegister
  48. // @Tags user
  49. // @Summary StaffRegister
  50. // @Description Create a new staff
  51. // @Produce application/json
  52. // @Param data body param.RegisterStaffParams true "RegisterStaffParams"
  53. // @Success 200 {object} response.Response{msg=string} "Success"
  54. // @Router /api/v1/register/staff [post].
  55. func StaffRegister(c *gin.Context) {
  56. var params requestparams.RegisterStaffParams
  57. err := c.ShouldBindJSON(&params)
  58. if err != nil {
  59. response.FailWithCode(common.INVALID_PARAMS, c)
  60. return
  61. }
  62. svc := service.NewUserService(c)
  63. _, _, err = svc.CreateStaff(&params)
  64. if err != nil {
  65. log.Debug("AdminRegister error", err)
  66. response.FailWithCode(common.ERROR, c)
  67. return
  68. }
  69. response.Success(c)
  70. }
  71. // AccountLogin
  72. // @Tags user
  73. // @Summary AccountLogin
  74. // @Description login with account
  75. // @Produce application/json
  76. // @Param data body param.AccountLogin true "AccountLogin"
  77. // @Success 200 {object} response.Response{msg=string} "Success"
  78. // @Router /api/v1/login/account [post].
  79. func AccountLogin(c *gin.Context) {
  80. var params requestparams.LoginParamsWithAccount
  81. err := c.ShouldBindJSON(&params)
  82. if err != nil {
  83. response.FailWithCode(common.INVALID_PARAMS, c)
  84. return
  85. }
  86. svc := service.NewUserService(c)
  87. u, err := svc.LoginWithAccount(&params)
  88. if err != nil {
  89. log.Debug("AdminRegister error", err)
  90. response.FailWithCode(common.ERROR, c)
  91. return
  92. }
  93. response.SuccessWithData(u, c)
  94. }