check_sub_supplier.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package v1
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/backend/common"
  4. "github.com/allanpk716/ChineseSubFinder/internal/dao"
  5. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
  7. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  8. "github.com/gin-gonic/gin"
  9. "net/http"
  10. )
  11. func (cb ControllerBase) CheckSubSupplierHandler(c *gin.Context) {
  12. var err error
  13. defer func() {
  14. // 统一的异常处理
  15. cb.ErrorProcess(c, "CheckSubSupplierHandler", err)
  16. }()
  17. nowUserInfo := settings.UserInfo{}
  18. err = c.ShouldBindJSON(&nowUserInfo)
  19. if err != nil {
  20. return
  21. }
  22. found, dbUserInfo, err := dao.GetUserInfo()
  23. if err != nil {
  24. return
  25. }
  26. if found == false || dbUserInfo.Username != nowUserInfo.Username || dbUserInfo.Password != nowUserInfo.Password {
  27. c.JSON(http.StatusNoContent, backend.ReplyCommon{Message: "Username or Password Error"})
  28. } else {
  29. nowAccessToken := my_util.GenerateAccessToken()
  30. common.SetAccessToken(nowAccessToken)
  31. c.JSON(http.StatusOK, backend.ReplyLogin{AccessToken: nowAccessToken})
  32. }
  33. }