如何判断用户登录是否登录?????
一、如何判断用户登录成功与否
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 routersimport ("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)// 验证码接口urladminRouters.GET("/captcha", admin.LoginController{}.Captcha)// 登录请求adminRouters.POST("/doLogin", admin.LoginController{}.DoLogin)}
}
3. 处理登录提交表单请求 /admin/doLogin
func (con LoginController) DoLogin(c *gin.Context) {captchaId :&