以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  移动版检测是否登陆  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=114845)

--  作者:yifan3429
--  发布时间:2018/2/23 18:14:00
--  移动版检测是否登陆
下面的使用的内部函数调用  会直接进入网页  不会被登陆与否监控  要怎么检测后必须登陆呢

Dim wb As New WeUI \'定义一个基于weui框架的网页生成器
Dim e As RequestEventArgs = args(0)
\'Dim u As String = e.cookies("name")
Dim s As String = e.cookies("部门")
\'Dim x As String = e.cookies("岗位")
\'For Each dr As DataRow In DataTables("财务流水").sqlSelect("[部门] = \'" & s & "\'","日期 Desc")
With wb.AddTable("","Table1")
    \'.MergeCols = 2 \'合并左边2列
    .Alternate = 3
    Dim nms() As String = {"经手人","编号","科目","摘要","收入","支出","日期" }
    .Head.AddRow(nms)
    .body.AddRow("汇总","","","",DataTables("财务流水").sqlcompute("sum(收入)","[部门] = \'" & s & "\'"),DataTables("财务流水").sqlcompute("sum(支出)","[部门] = \'" & s & "\'"))
    For Each r As DataRow In DataTables("财务流水").sqlSelect("[部门] = \'" & s & "\'", "", "日期 Desc")
        With .Body.AddRow(r("经手人"),r("编号"),r("科目"),r("摘要"))
            .AddCell(Format(r("收入"),"#0.00"))
            .AddCell(Format(r("支出"),"#0.00"))
            .AddCell(Format(r("日期"),"MM月dd日"))
        End With
    Next
End With
e.WriteString(wb.Build)

如何让下面的身份验证能生效
\'身份验证
Dim Verified As Boolean \'用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") \'从cookie中获取用户名
Dim Password As String = e.Cookies("password") \'从cookie中获取用户密码
If e.Path = "logon.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
    End If
End If
\'Dim dr As DataRow  自定义窗口使用 密码是明码
\'dr = DataTables("用户表").Find("name = \'" & UserName & "\'")
\'If dr IsNot Nothing AndAlso Password = dr("password") Then
\'Verified  = True
Dim dr As DataRow
dr = DataTables("用户表").Find("name = \'" & UserName & "\'")
If dr IsNot Nothing AndAlso dr("config").contains(MD5Encrypt(password)) Then
    Verified  = True
    For Each u As UserInfo In users
        output.show(u.name)
        If u.name = username Then
            \'msgbox(u.group)
            \'msgbox(u.Roles)
            wb.AppendCookie("部门",u.group)
            wb.AppendCookie("岗位",u.Roles)
            wb.AppendCookie("name",u.name)
        End If
    Next
End If

If Verified AndAlso e.Path = "logon.htm"  Then \'如果用户访问的是登录页,且身份验证成功
    wb.AppendCookie("username",UserName) \'将用户名和密码写入cookie
    wb.AppendCookie("password",Password)
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
End If

--  作者:有点甜
--  发布时间:2018/2/23 18:19:00
--  
你的身份验证的代码,要写到httprequest事件的,每次都要检测一次的。
--  作者:yifan3429
--  发布时间:2018/2/23 18:21:00
--  

下面代码是写到httprequest事件的


\'身份验证
Dim Verified As Boolean \'用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") \'从cookie中获取用户名
Dim Password As String = e.Cookies("password") \'从cookie中获取用户密码
If e.Path = "logon.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
    End If
End If
\'Dim dr As DataRow  自定义窗口使用 密码是明码
\'dr = DataTables("用户表").Find("name = \'" & UserName & "\'")
\'If dr IsNot Nothing AndAlso Password = dr("password") Then
\'Verified  = True
Dim dr As DataRow
dr = DataTables("用户表").Find("name = \'" & UserName & "\'")
If dr IsNot Nothing AndAlso dr("config").contains(MD5Encrypt(password)) Then
    Verified  = True
    For Each u As UserInfo In users
        output.show(u.name)
        If u.name = username Then
            \'msgbox(u.group)
            \'msgbox(u.Roles)
            wb.AppendCookie("部门",u.group)
            wb.AppendCookie("岗位",u.Roles)
            wb.AppendCookie("name",u.name)
        End If
    Next
End If

If Verified AndAlso e.Path = "logon.htm"  Then \'如果用户访问的是登录页,且身份验证成功
    wb.AppendCookie("username",UserName) \'将用户名和密码写入cookie
    wb.AppendCookie("password",Password)
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
End If

我输入http://127.0.0.1 就会要求输入登陆  
如果输入http://127.0.0.1/xkf1.htm   直接进入网页也可以 不会有要求登陆

[此贴子已经被作者于2018/2/23 18:23:18编辑过]

--  作者:有点蓝
--  发布时间:2018/2/23 20:16:00
--  
如果已经登录过,登录信息保存在Cookie,自然不会再验证登录。

先关闭浏览器,然后重新打开,第一次直接输入http://127.0.0.1/xkf1.htm也不会要求登录吗?

--  作者:yifan3429
--  发布时间:2018/2/24 11:40:00
--  
http://127.0.0.1/xkf1.htm
链接我发总到一台新的电脑打开就不会检测是否登陆
我通过企业微信菜单链接也是一样不会提醒需要登陆

--  作者:有点蓝
--  发布时间:2018/2/24 11:47:00
--  
……
msgbox(Verified) \'这里提示什么值
If Verified AndAlso e.Path = "logon.htm"  Then \'如果用户访问的是登录页,且身份验证成功
    wb.AppendCookie("username",UserName) \'将用户名和密码写入cookie
    wb.AppendCookie("password",Password)
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'这里代码不完整,截图看看
    e.WriteString(wb.Build) \'生成网页
    msgbox(e.Path) \'这里能够弹出来吗,提示什么内容?
    Return \'必须的
End If
[此贴子已经被作者于2018/2/24 11:48:10编辑过]

--  作者:yifan3429
--  发布时间:2018/2/24 18:23:00
--  
刚才更新了 2018版  不见了httprequest 服务器
图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20180224182148.png
图片点击可在新窗口打开查看
代码也不见了  怎么找回
[此贴子已经被作者于2018/2/24 18:34:41编辑过]

--  作者:有点甜
--  发布时间:2018/2/25 9:42:00
--  

检查一下更新,看是否升级到最新版了。

 

如果还有问题,先退回旧版使用。


--  作者:yifan3429
--  发布时间:2018/2/25 12:00:00
--  
已经是最新的版本了
旧版文件没有了
[此贴子已经被作者于2018/2/25 12:06:53编辑过]

--  作者:yifan3429
--  发布时间:2018/2/25 12:07:00
--  
截图
图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20180225120625.png
图片点击可在新窗口打开查看