feat: Added basic user authorization
This commit is contained in:
36
modules/auth/plain.go
Normal file
36
modules/auth/plain.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user