// ShowLogin 登陆显示
func (c *UserController) ShowLogin() {
username := c.Ctx.GetCookie("username")
if username != "" {
c.Data["username"] = username
c.Data["check"] = "checked"
} c.TplName = "login.html"
} // HandleLogin 登陆处理
func (c *UserController) HandleLogin() {
username := c.GetString("username")
password := c.GetString("password")
remember := c.GetString("remember")
beego.Info(remember)
if username == "" || password == "" {
beego.Info("数据不能为空!")
c.Redirect("/login", 302)
return
}
o := orm.NewOrm()
user := models.User{}
user.UserName = username
err := o.Read(&user, "UserName")
beego.Info(user)
if err != nil {
beego.Info("账号不存在", err)
c.Redirect("/login", 302)
} else {
if user.Password == password {
// c.Ctx.WriteString("登录成功")
if remember == "on" {
c.Ctx.SetCookie("username",username,time.Second*3600)
}else{
c.Ctx.SetCookie("username",username,-1)
}
c.SetSession("username",username) c.Redirect("/index",302)
} else {
c.Ctx.WriteString("密码错误")
c.Redirect("/login", 302)
}
} } // HandleLogout 退出登录
func (c *UserController) HandleLogout() {
c.DelSession("username")
c.Redirect("/",302)
}

在router.go路由配置文件里面加入,注意如果路径是 /article_list,"/article/*"是匹配不到的

package routers

import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
) func init() {
beego.InsertFilter("/article/*",beego.BeforeRouter, filterFunc)
} var filterFunc = func(ctx *context.Context){
username := ctx.Input.Session("username")
if username==nil{
ctx.Redirect(302,"/login")
}
}

beego登录退出与检查登录过滤器的更多相关文章

  1. flask 实现登录 登出 检查登录状态 的两种方法的总结

    这里我是根据两个项目的实际情况做的总结,方法一(来自项目一)的登录用的是用户名(字符串)和密码,前后端不分离,用form表单传递数据:方法二用的是手机号和密码登录,前后端分离,以json格式传递数据, ...

  2. selenium+python+eclipse 实现 “问卷星”网站,登录与检查登录示例!

    1.使用selenium+python+eclipse实现的登录"问卷星",问卷星访问地址:https://www.sojump.com/ 2.实现步骤:1)进入链接---首页-- ...

  3. 【ASP.NET】UCenter实现多站点同步登录退出

    利用UCenter实现discuz论坛和应用网站同步登录和退出功能 测试环境:Discuz! X3.2.UCenter 1.6..Net Framework 4.0 进入Discuz 后台的UCent ...

  4. asp.net 使用IHttpModule 做权限检查 登录超时检查(转)

    IHttpModule 权限 检查 登录超时检查 这样就不需要每个页面都做一次检查 也不需要继承任何父类. using System;using System.Collections.Generic; ...

  5. ac命令根据/var/log/wtmp文件登录退出时间计算用户连接时间

    ac命令根据/var/log/wtmp文件登录退出时间计算用户连接时间

  6. mysql基础:登录退出,修改用户密码,添加删除用户

    今天刚开始学习mysql,最先接触用户管理,给大家分享下 注:mysql中命令的大小写都可以的 ==========登录退出相关=================== root@jack-deskto ...

  7. MySQL数据库基础(一)(启动/停止、登录/退出、语法规范及最基础操作)

    1.启动/停止MySQL服务 启动:net start mysql    停止:net stop mysql 2.MySQL登录/退出 登录:mysql 参数:如果连接的是本地服务器,一般用命令:my ...

  8. [转] 从零构建 vue2 + vue-router + vuex 开发环境到入门,实现基本的登录退出功能

    这是一个创建于 738 天前的主题,其中的信息可能已经有所发展或是发生改变. 前言 vue2 正式版已经发布将近一个月了, 国庆过后就用在了公司的两个正式项目上, 还有一个项目下个月也会采用 vue2 ...

  9. php session 登录退出验证

    login.html 负责收集用户填写的登录信息 <html><head><title></title></head><body> ...

随机推荐

  1. 题解【洛谷P1596】[USACO10OCT]Lake Counting

    题面 \(\text{Flood Fill}\) 模板题. \(\text{Flood Fill}\) 可以快速求出一个图中连通块的个数. 大概就是遍历每一个点,如果它没有被遍历过且是一个新连通块,那 ...

  2. 原型链污染(Node.js污染,javasrcipt原型链污染的)

    学习链接: https://www.jianshu.com/p/6e623e9debe3 关于NJS  https://xz.aliyun.com/t/7184 相关题是 GYCTF  ez_expr ...

  3. 关于2008R2的序列号

    windows server 2008 r2 企业版序列号 BX4WB-3WTB8-HCRC9-BFFG3-FW26F P63JV-9RWW2-DJW7V-RHTMT-W8KWJ MDB49-7MYG ...

  4. burpsuite各个板块儿详细讲解

    burpsuite实战指南,想要的都在这里:https://t0data.gitbooks.io/burpsuite/content/

  5. Codeforces 577A - Multiplication Table

    Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i ...

  6. @HystrixCommand 不能被导包

    添加pom文件 <dependency>  <groupId>com.netflix.hystrix</groupId>  <artifactId>hy ...

  7. 2020牛客寒假算法基础集训营5 B.牛牛战队的比赛地 (二分/三分)

    https://ac.nowcoder.com/acm/contest/3006/B 三分做法 #include<bits/stdc++.h> #define inf 0x3f3f3f3f ...

  8. SpringBoot学习- 1、SpringSuit创建项目

    SpringBoot学习足迹 前言:最近一次开发java后台应用还是三年前的2017年,主要使用SSH开发小型外包项目和公司的一个产品,感觉再不回顾下可能就要彻底忘记了,准备做一个后台管理项目练练手, ...

  9. C# Timer 控件的用法

    一.主要的属性 在 Windows 窗体应用程序中,定时器控件(Timer)与其他的控件略有不同,它并不直接显示在窗体上,而是与其他控件连用. Enabled 属性: 用于设置该Timer控件是否可用 ...

  10. JDBC未知列

    Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4. MySQLSyntaxErrorException: Unk ...