refactor, sketch SSE implementation
This commit is contained in:
21
users/user.go
Normal file
21
users/user.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Username string `gorm:"unique"`
|
||||
Password string
|
||||
}
|
||||
|
||||
func Create(db *gorm.DB, username, password string) error {
|
||||
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
user := User{Username: username, Password: string(hashedPassword)}
|
||||
if err := db.Create(&user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user