forked from izghua/go-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
252 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Created by GoLand. | ||
* User: xzghua@gmail.com | ||
* Date: 2019-05-11 | ||
* Time: 00:17 | ||
*/ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
"github.com/izghua/go-blog/common" | ||
"github.com/izghua/go-blog/conf" | ||
"github.com/izghua/go-blog/entity" | ||
"github.com/izghua/zgh" | ||
"golang.org/x/crypto/bcrypt" | ||
) | ||
|
||
func GetUserByEmail(email string) (user *entity.ZUsers,err error) { | ||
user = new(entity.ZUsers) | ||
_,err = conf.SqlServer.Where("email = ?",email).Get(user) | ||
return | ||
} | ||
|
||
func GetUserCnt() (cnt int64,err error) { | ||
user := new(entity.ZUsers) | ||
cnt,err = conf.SqlServer.Count(user) | ||
return | ||
} | ||
|
||
func UserStore(ar common.AuthRegister) (user *entity.ZUsers, err error) { | ||
password := []byte(ar.Password) | ||
hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost) | ||
if err != nil { | ||
zgh.ZLog().Error("message","service.UserStore","error",err.Error()) | ||
return | ||
} | ||
userInsert := entity.ZUsers{ | ||
Name: ar.UserName, | ||
Email:ar.Email, | ||
Password: string(hashedPassword), | ||
Status: 1, | ||
} | ||
_,err = conf.SqlServer.Insert(&userInsert) | ||
if err != nil { | ||
zgh.ZLog().Error("message","service.UserStore","error",err.Error()) | ||
return | ||
} | ||
fmt.Println(userInsert.Id) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Created by GoLand. | ||
* User: xzghua@gmail.com | ||
* Date: 2019-05-11 | ||
* Time: 00:43 | ||
*/ | ||
package validate | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/izghua/go-blog/common" | ||
"github.com/izghua/zgh/gin/api" | ||
"net/http" | ||
) | ||
|
||
type AuthRegisterV struct { | ||
} | ||
|
||
func (av *AuthRegisterV) MyValidate() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
appG := api.Gin{C: c} | ||
var json common.AuthRegister | ||
if err := c.ShouldBindJSON(&json); err != nil { | ||
appG.Response(http.StatusOK, 400001000, nil) | ||
return | ||
} | ||
|
||
reqValidate := &AuthRegister{ | ||
Email:json.Email, | ||
Password:json.Password, | ||
UserName: json.UserName, | ||
} | ||
if b := appG.Validate(reqValidate); !b { | ||
return | ||
} | ||
c.Set("json",json) | ||
c.Next() | ||
} | ||
} | ||
|
||
type AuthRegister struct { | ||
UserName string `valid:"Required;MaxSize(30)"` | ||
Email string `valid:"Required;Email"` | ||
Password string `valid:"Required;MaxSize(30)"` | ||
} | ||
|
||
func (av *AuthRegister) Message() map[string]int { | ||
return map[string]int{ | ||
"Email.Required":407000000, | ||
"Email.Email":407000001, | ||
"Password.Required":407000002, | ||
"Password.MaxSize":407000003, | ||
"UserName.Required":407000012, | ||
"UserName.MaxSize":407000013, | ||
} | ||
} |
Oops, something went wrong.