Add token repositorie
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package services
|
||||
|
||||
import(
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"os"
|
||||
"time"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
|
||||
@@ -11,13 +11,13 @@ import(
|
||||
"git.dynamicdiscord.de/kalipso/zineshop/repositories"
|
||||
)
|
||||
|
||||
var(
|
||||
var (
|
||||
Users UserService = UserService{}
|
||||
)
|
||||
|
||||
type UserService struct {}
|
||||
type UserService struct{}
|
||||
|
||||
func (u *UserService) Register(name string, email string, password string) (models.User, error) {
|
||||
func (u *UserService) Register(name string, email string, password string, isAdmin bool) (models.User, error) {
|
||||
//hash pw
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (u *UserService) Register(name string, email string, password string) (mode
|
||||
return models.User{}, err
|
||||
}
|
||||
|
||||
user := models.User{Name: name, Email: email, Password: string(hash)}
|
||||
user := models.User{Name: name, Email: email, Password: string(hash), IsAdmin: isAdmin}
|
||||
_, err = repositories.Users.Create(user)
|
||||
|
||||
if err != nil {
|
||||
@@ -35,7 +35,7 @@ func (u *UserService) Register(name string, email string, password string) (mode
|
||||
return user, nil
|
||||
}
|
||||
|
||||
//return jwt tokenstring on success
|
||||
// return jwt tokenstring on success
|
||||
func (u *UserService) Login(email string, password string) (string, error) {
|
||||
//lookup requested user
|
||||
user, err := repositories.Users.GetByEmail(email)
|
||||
|
||||
Reference in New Issue
Block a user