You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/controller/auth.go

64 lines
1.6 KiB

package controller
import (
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
)
5 years ago
func CheckPass(username string, password string) string {
account := config.GetAccount()
if account == nil {
account = make(map[string]string)
}
if account["Username"] == "" && account["Password"] == "" {
account["Username"] = "admin"
account["Password"] = "admin123"
}
if username == account["Username"] && password == account["Password"] {
sessionId := tools.Md5(username)
info := make(map[string]string)
info["username"] = username
config.SetUserInfo(sessionId, info)
return sessionId
}
return ""
}
func CheckKefuPass(username string, password string) (models.User, models.User_role, bool) {
info := models.FindUser(username)
var uRole models.User_role
if info.Name == "" || info.Password != tools.Md5(password) {
return info, uRole, false
}
uRole = models.FindRoleByUserId(info.ID)
return info, uRole, true
}
5 years ago
func AuthLocal(username string, password string) string {
account := config.GetAccount()
if account == nil {
account = make(map[string]string)
}
5 years ago
if account["Username"] == "" && account["Password"] == "" {
account["Username"] = "admin"
account["Password"] = "admin123"
}
5 years ago
if username == account["Username"] && password == account["Password"] {
5 years ago
sessionId := tools.Md5(username)
info := make(map[string]string)
info["username"] = username
config.SetUserInfo(sessionId, info)
return sessionId
}
return ""
}
5 years ago
//验证是否已经登录
5 years ago
func AuthCheck(uid string) map[string]string {
info := config.GetUserInfo(uid)
return info
}