65 Star 394 Fork 128

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
manager_auth.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2019-10-20 10:27 . improved dbmanager
package database
import (
"github.com/webx-top/com"
"github.com/webx-top/echo"
"github.com/admpub/nging/application/library/dbmanager"
"github.com/admpub/nging/application/library/dbmanager/driver"
"github.com/admpub/nging/application/model"
)
func authentication(mgr dbmanager.Manager, accountID uint, m *model.DbAccount) (err error, succeed bool) {
ctx := mgr.Context()
auth := mgr.Account()
if accountID > 0 {
auth.Driver = m.Engine
auth.Username = m.User
auth.Password = m.Password
auth.Host = m.Host
auth.Db = m.Name
auth.AccountID = m.Id
auth.AccountTitle = m.Title
if len(m.Options) > 0 {
options := echo.H{}
com.JSONDecode(com.Str2bytes(m.Options), &options)
auth.Charset = options.String(`charset`)
}
if len(auth.Charset) == 0 {
auth.Charset = `utf8mb4`
}
err = mgr.Run(auth.Driver, `login`)
succeed = err == nil
return
}
if accounts, exists := ctx.Session().Get(`dbAccounts`).(driver.AuthAccounts); exists {
ctx.Internal().Set(`dbAccounts`, &accounts)
key := driver.GenKey(auth.Driver, auth.Username, auth.Host, auth.Db, accountID)
data := accounts.Get(key)
if data == nil {
return
}
auth.CopyFrom(data)
err = mgr.Run(auth.Driver, `login`)
succeed = err == nil
return
}
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.3

搜索帮助