mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-04 00:06:22 +00:00
⚡ implement user authentication and database initialization, add models for user, comment, label, and OIDC configuration
This commit is contained in:
32
internal/service/user.go
Normal file
32
internal/service/user.go
Normal file
@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/snowykami/neo-blog/internal/dto"
|
||||
"github.com/snowykami/neo-blog/internal/repo"
|
||||
"github.com/snowykami/neo-blog/pkg/constant"
|
||||
"github.com/snowykami/neo-blog/pkg/resps"
|
||||
"github.com/snowykami/neo-blog/pkg/utils"
|
||||
)
|
||||
|
||||
type UserService interface {
|
||||
UserLogin(dto *dto.UserLoginReq) (*dto.UserLoginResp, error)
|
||||
UserRegister(dto *dto.UserRegisterReq) (*dto.UserRegisterResp, error)
|
||||
}
|
||||
|
||||
type userService struct{}
|
||||
|
||||
func NewUserService() UserService {
|
||||
return &userService{}
|
||||
}
|
||||
|
||||
func (s *userService) UserLogin(dto *dto.UserLoginReq) (*dto.UserLoginResp, error) {
|
||||
user, err := repo.User.GetByUsernameOrEmail(dto.Username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
return nil, errors.New(resps.ErrNotFound)
|
||||
}
|
||||
utils.Password.VerifyPassword(dto.Password, user.Password, utils.Env.Get(constant.EnvVarPasswordSalt, "default_salt"))
|
||||
}
|
Reference in New Issue
Block a user