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.

mail.go 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // SendCode
  24. // @Tags mail
  25. // @Summary SendCode
  26. // @Description Use email to send verification code
  27. // @Produce application/json
  28. // @Param data body param.SendToParams true "Email address"
  29. // @Success 200 {object} response.Response{msg=string} "Success"
  30. // @Router /api/v1/email/code [post].
  31. func SendCode(c *gin.Context) {
  32. var params requestparams.SendToParams
  33. err := c.ShouldBindJSON(&params)
  34. if err != nil {
  35. response.FailWithCode(common.INVALID_PARAMS, c)
  36. return
  37. }
  38. svc := service.NewMailService(c)
  39. err = svc.SendCode(params.Email)
  40. if err != nil {
  41. log.Debug("SendCode error: ", err)
  42. response.FailWithCode(common.ERROR, c)
  43. return
  44. }
  45. response.Success(c)
  46. }