Files
status/modules/auth/plain.go

37 lines
713 B
Go

package auth
import (
"git.ostiwe.com/ostiwe-com/status/modules/jwt"
"git.ostiwe.com/ostiwe-com/status/repository"
"golang.org/x/crypto/bcrypt"
)
type Module struct {
userRepository repository.User
}
func New() Module {
return Module{
userRepository: repository.NewUserRepository(),
}
}
func (m *Module) Proceed(login, password string) (*string, error) {
lightweightUser, err := m.userRepository.FindByLogin(login)
if err != nil {
return nil, err
}
err = bcrypt.CompareHashAndPassword([]byte(lightweightUser.Password), []byte(password))
if err != nil {
return nil, err
}
jwtString, err := jwt.CreateByUser(lightweightUser)
if err != nil {
return nil, err
}
return &jwtString, nil
}