sonarqube-badges/router/utils/userUtils.go

27 lines
572 B
Go
Raw Normal View History

2025-03-15 01:49:52 +01:00
package utils
import (
"context"
"crypto/sha1"
"fmt"
"gorm.io/gorm"
"sonarqube-badge/store"
)
func UserExists(ctx context.Context, email string, password string) bool {
db := ctx.Value("db").(*gorm.DB)
passwordHash := sha1.Sum([]byte(password))
user := store.User{}
db.Where("email = ? AND password = ?", email, fmt.Sprintf("%x", passwordHash)).First(&user)
return user.ID != 0
}
func GetUser(ctx context.Context, email string) *store.User {
db := ctx.Value("db").(*gorm.DB)
user := store.User{}
db.Where("email = ?", email).First(&user)
return &user
}