userService.go 714 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package service
  2. import (
  3. "crypto/sha1"
  4. "fmt"
  5. "io"
  6. "iot_manager_service/app/system/dao"
  7. )
  8. // 用户管理服务
  9. var UserService = new(userService)
  10. type userService struct{}
  11. func (s *userService) GetUserByPasskey(passKey string) (*dao.User, error) {
  12. user := &dao.User{}
  13. err := user.GetUser()
  14. if err != nil {
  15. return nil, err
  16. }
  17. return user, nil
  18. }
  19. func (s *userService) GetOne(tenantId, account, password string) (dao.User, error) {
  20. t := sha1.New()
  21. _, _ = io.WriteString(t, password)
  22. password = fmt.Sprintf("%x", t.Sum(nil))
  23. user := dao.User{
  24. TenantId: tenantId,
  25. Account: account,
  26. Password: password,
  27. }
  28. err := user.GetUser()
  29. if err != nil {
  30. return dao.User{}, err
  31. }
  32. return user, nil
  33. }