This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/db/users.go
2021-02-02 15:34:10 -05:00

37 lines
922 B
Go

package db
import (
"golang.org/x/crypto/bcrypt"
log "github.com/sirupsen/logrus"
"reichard.io/imagini/graph/model"
)
func (dbm *DBManager) CreateUser(user *model.User) error {
log.Info("[db] Creating user: ", user.Username)
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(*user.Password), bcrypt.DefaultCost)
if err != nil {
log.Error(err)
return err
}
stringHashedPassword := string(hashedPassword)
user.Password = &stringHashedPassword
err = dbm.db.Create(&user).Error
return err
}
func (dbm *DBManager) User (user *model.User) (model.User, error) {
var foundUser model.User
var count int64
err := dbm.db.Where(&user).First(&foundUser).Count(&count).Error
return foundUser, err
}
func (dbm *DBManager) DeleteUser (user model.User) error {
return nil
}
func (dbm *DBManager) UpdatePassword (user model.User, pw string) {
}