added user signup feature
This commit is contained in:
@@ -1,9 +1,27 @@
|
||||
package api
|
||||
|
||||
import "git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
import (
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func (b bookPostCreate) toBook() model.Book {
|
||||
return model.Book{Title: b.Title,
|
||||
return model.Book{
|
||||
Title: b.Title,
|
||||
Author: b.Author,
|
||||
Rating: b.Rating}
|
||||
Rating: b.Rating,
|
||||
}
|
||||
}
|
||||
|
||||
func (u userPostCreate) toUser() (model.User, error) {
|
||||
user := model.User{
|
||||
Name: u.Username,
|
||||
Password: "",
|
||||
}
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return user, err
|
||||
}
|
||||
user.Password = string(hashedPassword)
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user