[FIX]密码改为密文存储
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/go-pripro/shop/pkg/gredis"
|
||||
"github.com/go-pripro/shop/pkg/logging"
|
||||
"github.com/go-pripro/shop/service/cache_service"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type Employee struct {
|
||||
@@ -25,11 +26,19 @@ type Employee struct {
|
||||
PageSize int
|
||||
}
|
||||
|
||||
func (syncEmployee *Employee) EncodePassword(password string) string {
|
||||
if hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost); err == nil {
|
||||
return string(hash)
|
||||
}
|
||||
return string(rune(0))
|
||||
}
|
||||
|
||||
func (syncEmployee *Employee) Add() error {
|
||||
encodePassword := syncEmployee.EncodePassword(syncEmployee.Password)
|
||||
employee := map[string]interface{}{
|
||||
"avatar_url": syncEmployee.AvatarUrl,
|
||||
"username": syncEmployee.Username,
|
||||
"password": syncEmployee.Password,
|
||||
"password": encodePassword,
|
||||
"department": syncEmployee.Department,
|
||||
"position": syncEmployee.Position,
|
||||
"state": syncEmployee.State,
|
||||
@@ -43,10 +52,12 @@ func (syncEmployee *Employee) Add() error {
|
||||
}
|
||||
|
||||
func (syncEmployee *Employee) Edit() error {
|
||||
encodePassword := syncEmployee.EncodePassword(syncEmployee.Password)
|
||||
|
||||
return models.EditEmployee(syncEmployee.ID, map[string]interface{}{
|
||||
"avatar_url": syncEmployee.AvatarUrl,
|
||||
"username": syncEmployee.Username,
|
||||
"password": syncEmployee.Password,
|
||||
"password": encodePassword,
|
||||
"department": syncEmployee.Department,
|
||||
"position": syncEmployee.Position,
|
||||
"state": syncEmployee.State,
|
||||
|
||||
Reference in New Issue
Block a user