Foxtable(狐表)用户栏目专家坐堂 → 转向问题


  共有2860人关注过本帖树形打印复制链接

主题:转向问题

帅哥哟,离线,有人找我吗?
nxqtxwz
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1495 积分:12175 威望:0 精华:0 注册:2013/3/19 16:41:00
转向问题  发帖心情 Post By:2020/3/11 21:17:00 [只看该作者]

老师您好,下面的代码是想登录服务器后进入登录页面logon.htm,登录通过后进入主菜单。但发现登录后会再次进入登录页面,然后才能进入主菜单。

 

 

Static UserTable As DataTable '定义一个变量,用于存储用户随机身份ID,以及最后一次活动时间.
Static ClearTime As Date
If UserTable Is Nothing Then '创建用于记录登录信息的临时表
    ClearTime = Date.Now()
    Dim dtb As New DataTableBuilder("UserInfos")
    dtb.AddDef("UserName", Gettype(String), 16)
    dtb.AddDef("UserID",Gettype(String),16)
    dtb.AddDef("ActiveTime",Gettype(Date))
    UserTable = dtb.Build(True)
End If
If (Date.Now - ClearTime).TotalMinutes >= 10 Then '清除超过30分钟没有操作的登录信息
    UserTable.DeleteFor("ActiveTime < #" & Date.Now.AddMinutes(-10) & "#")
    ClearTime = Date.Now()
End If
Dim wb As New weui
'身份验证
Dim UserName As String
Dim Password As String
Dim UserID As String
If e.Path = "logon.htm" '验证用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        Dim Verified As Boolean '用于标记用户是否通过了身份验证
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
        Dim mm As DataRow = DataTables("users").Find("name = '" & userName & "'")
        If mm IsNot Nothing AndAlso mm("config") Like "*" & MD5Encrypt(password) & "*" Then
            Verified  = True
        End If
                
        If Verified Then
            UserID = Rand.NextString(16) '生成随机用户ID
            UserName = EncryptText(UserName,"123","123") '将用户名加密.
            Dim dr As DataRow = UserTable.Find("UserName = '" & UserName & "'")
            If  dr IsNot Nothing Then '如果是重复登录,删除以前的登录信息
                dr.Delete()
            End If
            dr = UserTable.AddNew()
            dr("UserName") = UserName
            dr("UserID") = UserId
            dr("ActiveTime") = Date.Now '记录登录时间
            wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
            wb.AppendCookie("userid",UserID)
            wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
            e.WriteString(wb.Build) '生成网页
            Return '必须的
        End If
    End If
Else '其它页面从Cookie提取登录信息进行验证
    UserName = e.Cookies("username")  '从cookie中获取用户名
    UserID = e.Cookies("userid")  '从cookie中获取 随机ID
    Dim dr As DataRow = UserTable.Find("UserName = '" & UserName & "'")
    If dr IsNot Nothing AndAlso dr("UserID") = UserID Then  '如果通过验证,更新活动时候,继续访问其它页面.
        dr("ActiveTime") = Date.Now '更新活动时间
    Else '如果验证失败
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
        e.WriteString(wb.Build) '生成网页
        Return '必须的
    End If
End If


'开始生成网页
Select Case e.path
    Case "","logon.htm" '登录页面
        wb.AddPageTitle("","pageheader","学校信息","由青铜峡市铝业学校开发")
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then '判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 '如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        wb.AddForm("","form1","logon.htm")
        With wb.AddInputGroup("form1","ipg1")
            .AddInput("username","户名","text").Placeholder = "信息平台用户名"
            .AddInput("password","密码","password").Placeholder = "信息平台密码"
           
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "登录", "submit")
        End With


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:109489 积分:557107 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/12 9:42:00 [只看该作者]

这样测试没有问题,请上传实例说明

Static UserTable As DataTable '定义一个变量,用于存储用户随机身份ID,以及最后一次活动时间.
Static ClearTime As Date
If UserTable Is Nothing Then '创建用于记录登录信息的临时表
    ClearTime = Date.Now()
    Dim dtb As New DataTableBuilder("UserInfos")
    dtb.AddDef("UserName", Gettype(String), 200)
    dtb.AddDef("UserID",Gettype(String),16)
    dtb.AddDef("ActiveTime",Gettype(Date))
    UserTable = dtb.Build(True)
End If
If (Date.Now - ClearTime).TotalMinutes >= 10 Then '清除超过30分钟没有操作的登录信息
    UserTable.DeleteFor("ActiveTime < #" & Date.Now.AddMinutes(-10) & "#")
    ClearTime = Date.Now()
End If
Dim wb As New weui
'身份验证
Dim UserName As String
Dim Password As String
Dim UserID As String
If e.Path = "logon.htm" '验证用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        Dim Verified As Boolean '用于标记用户是否通过了身份验证
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
        'Dim mm As DataRow = DataTables("users").Find("name = '" & userName & "'")
        'If mm IsNot Nothing AndAlso mm("config") Like "*" & MD5Encrypt(password) & "*" Then
            Verified  = True
        'End If
        
        If Verified Then
            UserID = Rand.NextString(16) '生成随机用户ID
            UserName = EncryptText(UserName,"123","123") '将用户名加密.
            Dim dr As DataRow = UserTable.Find("UserName = '" & UserName & "'")
            If  dr IsNot Nothing Then '如果是重复登录,删除以前的登录信息
                dr.Delete()
            End If
            dr = UserTable.AddNew()
            dr("UserName") = UserName
            dr("UserID") = UserId
            dr("ActiveTime") = Date.Now '记录登录时间
            wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
            wb.AppendCookie("userid",UserID)
            wb.InsertHTML("<meta http-equiv='Refresh' content='0; url=/default.htm'>") '直接跳转到首页
            e.WriteString(wb.Build) '生成网页
            Return '必须的
        End If
    End If
Else '其它页面从Cookie提取登录信息进行验证
    UserName = e.Cookies("username")  '从cookie中获取用户名
    UserID = e.Cookies("userid")  '从cookie中获取 随机ID
    Dim dr As DataRow = UserTable.Find("UserName = '" & UserName & "'")
    If dr IsNot Nothing AndAlso dr("UserID") = UserID Then  '如果通过验证,更新活动时候,继续访问其它页面.
        dr("ActiveTime") = Date.Now '更新活动时间
    Else '如果验证失败
        wb.InsertHTML("<meta http-equiv='Refresh' content='0; url=/logon.htm'>") '那么直接跳转到登录页面
        e.WriteString(wb.Build) '生成网页
        Return '必须的
    End If
End If


'开始生成网页
Select Case e.path
    Case "","logon.htm" '登录页面
        wb.AddPageTitle("","pageheader","学校信息","由青铜峡市铝业学校开发")
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then '判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 '如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        wb.AddForm("","form1","logon.htm")
        With wb.AddInputGroup("form1","ipg1")
            .AddInput("username","户名","text").Placeholder = "信息平台用户名"
            .AddInput("password","密码","password").Placeholder = "信息平台密码"
            
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "登录", "submit")
        End With
    Case "exit.htm" '退出登录
        wb.DeleteCookie("username") '清除cookie中原来的用户名和密码
        wb.DeleteCookie("password")
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '然后直接跳转到登录页面
    Case "default.htm" '首页
        wb.AddPageTitle("","pageheader","销售系统","由湛江辉迅基于Foxtable开发")
        With wb.AddGrid("","g1")
            .Add("c1","增加订单", "./images/button.png").Attribute = ""
            .Add("c2","客户管理", "./images/cell.png", "http://www.foxtable.com")
            .Add("c12","退出", "./images/exit.png", "exit.htm") '退出登录
        End With
End Select
e.WriteString(wb.Build) '生成网页

 回到顶部
帅哥哟,离线,有人找我吗?
nxqtxwz
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1495 积分:12175 威望:0 精华:0 注册:2013/3/19 16:41:00
  发帖心情 Post By:2020/3/12 9:49:00 [只看该作者]

老师您好,代码运行没有问题。

出现的问题是:登录时进入登录窗口,输入完后按确定又一次进入登录窗口再输入一次用户名和密码确定后才能进到主菜单


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:109489 积分:557107 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/12 10:06:00 [只看该作者]

我测试没有这种情况,登录后直接进入"default.htm" '首页

 回到顶部
帅哥哟,离线,有人找我吗?
nxqtxwz
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1495 积分:12175 威望:0 精华:0 注册:2013/3/19 16:41:00
  发帖心情 Post By:2020/3/12 10:43:00 [只看该作者]

以下是引用有点蓝在2020/3/12 10:06:00的发言:
我测试没有这种情况,登录后直接进入"default.htm" '首页

老师,请你登录一下看看,麻烦了。可以用户名:李四,密码123登录。

http://218.203.157.198:32177/


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:109489 积分:557107 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/12 10:52:00 [只看该作者]

请做个例子上传测试

 回到顶部
帅哥哟,离线,有人找我吗?
nxqtxwz
  7楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1495 积分:12175 威望:0 精华:0 注册:2013/3/19 16:41:00
  发帖心情 Post By:2020/3/12 11:50:00 [只看该作者]

老师,就是进入 default.htm" '首页 时要输入两次用户名,两次密码。用手机登录是这样的。

 

 

老师,请你登录一下看看,麻烦了。可以用户名:李四,密码123登录。

http://218.203.157.198

[此贴子已经被作者于2020/3/12 11:50:48编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
nxqtxwz
  8楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1495 积分:12175 威望:0 精华:0 注册:2013/3/19 16:41:00
  发帖心情 Post By:2020/3/12 12:33:00 [只看该作者]

在浏览器上正常,在微信中要登录两次才能到主页面。

 


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47477 积分:251256 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2020/3/12 12:49:00 [只看该作者]

手机和电脑都测试了,正常

 回到顶部