Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nbya
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
nbya
Commits
d37eaed4
Commit
d37eaed4
authored
3 years ago
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User
parent
00b342da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
sys_user.go
app/admin/models/sys_user.go
+11
-10
No files found.
app/admin/models/sys_user.go
View file @
d37eaed4
...
...
@@ -2,6 +2,7 @@ package models
import
(
"go-admin/common/models"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
...
...
@@ -49,13 +50,13 @@ func (e *SysUser) Encrypt() (err error) {
return
}
//var hash []byte
//if hash, err = bcrypt.GenerateFromPassword([]byte(e.Password), bcrypt.DefaultCost); err != nil {
// return
//} else {
// e.Password = string(hash)
var
hash
[]
byte
if
hash
,
err
=
bcrypt
.
GenerateFromPassword
([]
byte
(
e
.
Password
),
bcrypt
.
DefaultCost
);
err
!=
nil
{
return
//}
}
else
{
e
.
Password
=
string
(
hash
)
return
}
}
func
(
e
*
SysUser
)
BeforeCreate
(
_
*
gorm
.
DB
)
error
{
...
...
@@ -64,9 +65,9 @@ func (e *SysUser) BeforeCreate(_ *gorm.DB) error {
func
(
e
*
SysUser
)
BeforeUpdate
(
_
*
gorm
.
DB
)
error
{
var
err
error
if
e
.
Password
!=
""
{
err
=
e
.
Encrypt
()
}
//
if e.Password != "" {
//
err = e.Encrypt()
//
}
return
err
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment