1 Star 0 Fork 435

xflash/go-admin

forked from go-admin/go-admin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
auth.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
package controller
import (
"bytes"
"fmt"
"github.com/chenhg5/go-admin/context"
"github.com/chenhg5/go-admin/modules/auth"
"github.com/chenhg5/go-admin/modules/menu"
"github.com/chenhg5/go-admin/template"
"net/http"
)
func Auth(ctx *context.Context) {
password := ctx.Request.FormValue("password")
username := ctx.Request.FormValue("username")
if user, ok := auth.Check(password, username); ok {
auth.SetCookie(ctx, user)
menu.Unlock()
ctx.Json(http.StatusOK, map[string]interface{}{
"code": 200,
"msg": "登录成功",
"url": Config.PREFIX + Config.INDEX,
})
return
}
ctx.Json(http.StatusBadRequest, map[string]interface{}{
"code": 400,
"msg": "登录失败",
})
return
}
func Logout(ctx *context.Context) {
auth.DelCookie(ctx)
ctx.Response.Header.Add("Location", Config.PREFIX+"/login")
ctx.SetStatusCode(302)
}
func ShowLogin(ctx *context.Context) {
defer GlobalDeferHandler(ctx)
tmpl, name := template.GetComp("login").GetTemplate()
buf := new(bytes.Buffer)
fmt.Println(tmpl.ExecuteTemplate(buf, name, struct {
AssertRootUrl string
}{Config.PREFIX}))
ctx.WriteString(buf.String())
ctx.Response.Header.Add("Content-Type", "text/html; charset=utf-8")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xflash/go-admin.git
git@gitee.com:xflash/go-admin.git
xflash
go-admin
go-admin
v0.0.2

搜索帮助