如何判断用户登录是否登录?????
一、如何判断用户登录成功与否
1.请求接口 post : localhost:8888/admin/doLogin
<form action="/admin/doLogin" method="post" id="myform">
<input type="hidden" name="captchaId" id="captchaId">
<div class="l_title">小米商城后台管理系统-IT营</div>
<dl>
<dd>管理员姓名:<input class="text" type="text" name="username" id="username"></dd>
<dd>管理员密码:<input class="text" type="password" name="password" id="password"></dd>
<dd>验 证 码:<input id="verify" type="text" name="verifyValue">
<img id="captchaImg" src="">
</dd>
<dd><input type="submit" class="submit" name="dosubmit" value=""></dd>
</dl>
</form>
2. 这时候,提交表单走路由routers 【routers/adminRouters.go】
package routers
import (
"ginshop06/controllers/admin"
"ginshop06/middlewares"
"github.com/gin-gonic/gin"
)
func AdminRoutersInit(r *gin.Engine) {
//middlewares.InitMiddleware中间件
adminRouters := r.Group("/admin", middlewares.InitAdminAuthMiddleware)
{
//登录页面路由地址
adminRouters.GET("/login", admin.LoginController{}.Index)
// 验证码接口url
adminRouters.GET("/captcha", admin.LoginController{}.Captcha)
// 登录请求
adminRouters.POST("/doLogin", admin.LoginController{}.DoLogin)
}
}
3. 处理登录提交表单请求 /admin/doLogin
func (con LoginController) DoLogin(c *gin.Context) {
captchaId :=