-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from SugarMGP/main
feat: 根据用户类型切换登陆方式
- Loading branch information
Showing
3 changed files
with
34 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
package userServices | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"wejh-go/app/apiException" | ||
"wejh-go/app/models" | ||
"wejh-go/app/services/userCenterServices" | ||
) | ||
|
||
func CheckUsername(username string) bool { | ||
user, _ := GetUserByUsername(username) | ||
if user != nil { | ||
return true | ||
} | ||
return false | ||
return user != nil | ||
} | ||
|
||
func CheckWechatOpenID(wechatOpenID string) bool { | ||
user := GetUserByWechatOpenID(wechatOpenID) | ||
if user != nil { | ||
return false | ||
return user != nil | ||
} | ||
|
||
func CheckLogin(username, password string) error { | ||
return userCenterServices.Login(username, password) | ||
} | ||
|
||
func CheckLocalLogin(user *models.User, password string) error { | ||
h := sha256.New() | ||
h.Write([]byte(password)) | ||
pass := hex.EncodeToString(h.Sum(nil)) | ||
|
||
if user.JHPassword != pass { | ||
return apiException.NoThatPasswordOrWrong | ||
} | ||
return true | ||
return nil | ||
} |
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