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

36 lines
906 B
Go
Raw Normal View History

2021-01-16 22:00:17 +00:00
package db
2021-01-10 00:44:02 +00:00
import (
2021-01-12 22:06:27 +00:00
"golang.org/x/crypto/bcrypt"
log "github.com/sirupsen/logrus"
2021-01-18 21:24:28 +00:00
"reichard.io/imagini/internal/models"
2021-01-10 00:44:02 +00:00
)
2021-01-18 21:16:52 +00:00
func (dbm *DBManager) CreateUser(user models.User) (models.User, error) {
2021-01-19 20:50:48 +00:00
log.Info("[db] Creating user: ", user.Username)
2021-01-12 22:06:27 +00:00
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
if err != nil {
log.Error(err)
2021-01-18 21:16:52 +00:00
return user, err
2021-01-12 22:06:27 +00:00
}
user.Password = string(hashedPassword)
2021-01-18 21:16:52 +00:00
err = dbm.db.Create(&user).Error
return user, err
2021-01-10 00:44:02 +00:00
}
2021-01-16 22:00:17 +00:00
func (dbm *DBManager) User (user models.User) (models.User, error) {
2021-01-10 00:44:02 +00:00
var foundUser models.User
var count int64
2021-01-16 22:00:17 +00:00
err := dbm.db.Where(&user).First(&foundUser).Count(&count).Error
2021-01-10 00:44:02 +00:00
return foundUser, err
}
2021-01-16 22:00:17 +00:00
func (dbm *DBManager) DeleteUser (user models.User) error {
2021-01-10 00:44:02 +00:00
return nil
}
2021-01-16 22:00:17 +00:00
func (dbm *DBManager) UpdatePassword (user models.User, pw string) {
2021-01-10 00:44:02 +00:00
}