feat: Added basic user authorization

This commit is contained in:
2025-08-20 01:24:49 +03:00
parent b72066f19e
commit fb4902dea6
15 changed files with 396 additions and 2 deletions

36
modules/auth/plain.go Normal file
View 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
}