代码拉取完成,页面将自动刷新
package database
import (
"github.com/webx-top/db"
"github.com/webx-top/echo"
"github.com/admpub/nging/application/dbschema"
"github.com/admpub/nging/application/library/dbmanager"
"github.com/admpub/nging/application/library/dbmanager/driver"
"github.com/admpub/nging/application/model"
)
func addAuth(ctx echo.Context, auth *driver.DbAuth) {
accounts := getAccounts(ctx)
accounts.Add(auth)
ctx.Session().Set(`dbAccounts`, accounts)
}
func getAccounts(ctx echo.Context) driver.AuthAccounts {
if accounts, ok := ctx.Internal().Get(`dbAccounts`).(*driver.AuthAccounts); ok {
return *accounts
}
accounts, ok := ctx.Session().Get(`dbAccounts`).(driver.AuthAccounts)
if !ok {
accounts = driver.AuthAccounts{}
} else {
ctx.Internal().Set(`dbAccounts`, &accounts)
}
return accounts
}
func deleteAuth(ctx echo.Context, auth *driver.DbAuth) {
accounts := getAccounts(ctx)
accounts.Delete(auth)
ctx.Session().Set(`dbAccounts`, accounts)
}
func clearAuth(ctx echo.Context) {
accounts := getAccounts(ctx)
for key := range accounts {
accounts.DeleteByKey(key)
}
ctx.Session().Delete(`dbAccounts`)
}
func getLoginInfo(mgr dbmanager.Manager, accountID uint, m *model.DbAccount, user *dbschema.NgingUser) (err error) {
ctx := mgr.Context()
if !ctx.IsPost() {
return nil
}
auth := mgr.Account()
data := &driver.DbAuth{AccountID: accountID, AccountTitle: m.Title}
ctx.Bind(data)
if len(data.Username) == 0 {
data.Username = `root`
}
if len(data.Host) == 0 {
data.Host = `127.0.0.1`
}
auth.CopyFrom(data)
if ctx.Form(`remember`) == `1` {
if len(m.Title) == 0 {
m.Title = auth.Driver + `://` + auth.Username + `@` + auth.Host + `/` + auth.Db
}
m.Engine = auth.Driver
m.Host = auth.Host
m.User = auth.Username
m.Password = auth.Password
m.Name = auth.Db
err = m.SetOptions()
if err != nil {
return err
}
if accountID < 1 || m.Id < 1 {
m.Uid = user.Id
_, err = m.Add()
} else {
err = m.Edit(accountID, nil, db.Cond{`id`: accountID})
}
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。