以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- web用户名验证 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=172898) |
|
-- 作者:小试牛刀 -- 发布时间:2021/11/6 11:18:00 -- web用户名验证 老师你好我想问一下我用ajax已经可以提出了用户名跟密码,怎么样像这个一样验证呀,老师Dim sb As New StringBuilder 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" AndAlso e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then UserName = e.PostValues("username") Password = e.PostValues("password") End If \'验证用户身份 If UserName = "张三" AndAlso Password = "888" Then Verified = True ElseIf Username = "李四" AndAlso Password="999" Then Verified = True End If If Verified AndAlso e.Path = "logon.htm" Then \'如果用户访问的是登录页,且身份验证成功 e.Appendcookie("username",UserName) \'将用户名和密码写入cookie e.Appendcookie("password",Password) e.WriteString("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页 Return \'必须的 ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面 e.WriteString("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面 Return \'必须的 End If Select Case e.path Case "logon.htm" sb.AppendLine("<form action=\'logon.htm\' enctype=\'multipart/form-data\' method=\'post\' id=\'form1\' name=\'form1\'>") If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then \'判断是否是验证失败后的重新登录 sb.AppendLine("用户名或密码错误!</br></br>") sb.AppendLine("户名: <input name=\'username\' id=\'username\' value=\'" & UserName & "\'\'><br/><br/>") sb.AppendLine("密码: <input type=\'password\' name=\'password\' id=\'password\' value =\'" & Password & "\'><br/><br/>") Else sb.AppendLine("户名: <input name=\'username\' id=\'username\'><br/><br/>") sb.AppendLine("密码: <input type=\'password\' name=\'password\' id=\'password\'><br/><br/>") End If sb.AppendLine("<input type=\'submit\' name=\'sumbit\' id=\'sumbit\' value=\'登录\'>") sb.AppendLine("<input type=\'reset\' name=\'reset\' id=\'reset\' value=\'重置\'>") sb.AppendLine("</form>") e.WriteString(sb.ToString) Case "exit.htm" e.Appendcookie("username", "") \'清除cookie中原来的用户名和密码 e.Appendcookie("password", "") e.WriteString("<meta http-equiv=\'refresh\' c>") \'跳转到登录页 Case "", "default.htm" sb.AppendLine("这是首页<br/><br/>") sb.AppendLine("<a href=\'order.htm\'>订购产品<a><br/>") sb.AppendLine("<a href=\'product.htm\'>产品列表<a><br/>") sb.AppendLine("<a href=\'exit.htm\'>退出登录<a><br/>") e.WriteString(sb.Tostring) Case "order.htm" e.WriteString("这是订购页") Case "product.htm" e.WriteString("这是产品页") End Select |
|
-- 作者:小试牛刀 -- 发布时间:2021/11/6 11:19:00 -- Dim str As String Select Case e.path Case "dt" Dim json As String = e.PlainText Dim jo As JObject = JObject.Parse(json) str=jo("username") e.writestring(str) End Select 我已经提出了用户名跟密码了
|
|
-- 作者:有点蓝 -- 发布时间:2021/11/6 11:46:00 -- Dim str As String Select Case e.path Case "dt" Dim json As String = e.PlainText Dim jo As JObject = JObject.Parse(json) str=jo("username") dim dr as datarow = datatables("用户").find("名称=\'" & str & "\'") if dr isnot nothing andalso dr("密码") = jo("密码") then e.writestring(“成功”) else e.writestring(“失败”) end if End Select 前端js var res = ajax提交返回的数据 if (res = "成功") {处理成功的操作} else{处理失败的操作}
|
|
-- 作者:小试牛刀 -- 发布时间:2021/11/6 12:00:00 -- 处理成功能不能这样写就不用在ajax里面写了
|
|
-- 作者:有点蓝 -- 发布时间:2021/11/6 12:07:00 -- 不能。使用了ajax就只能在ajax里获取返回数据,和做其它后续的处理。先网上搜索学学ajax的原理了 |
|
-- 作者:小试牛刀 -- 发布时间:2021/11/6 13:48:00 --
var res = ajax;
if (res = "成功") {
window.location.href = \'http://127.0.0.1/index.html\';
}
else{
window.location.href = \'http://127.0.0.1/logon.html\';
}
}这样可以吗
|
|
-- 作者:有点蓝 -- 发布时间:2021/11/6 13:54:00 -- 提问题不要问可不可以。请测试,然后反馈测试的结果和问题 |
|
-- 作者:小试牛刀 -- 发布时间:2021/11/6 13:57:00 -- <!DOCTYPE html> <html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>页面测试</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script>
</head>
<body>
<div>
<p>用户名称:<input type="text" /></p>
<p>用户密码:<input type="password" /></p>
<p>上传文件:<input type="file" id="t" multiple></p>
<input type="submit" />
</div>
<p></p>
</body>
<script>
var res = ajax;
if (res = "成功") {
window.location.href = \'http://127.0.0.1/index.html\';
}
else{
window.location.href = \'http://127.0.0.1/logon.html\';
}
}
$(\'input:eq(3)\').click(function(){
var obj={
username:$(\'input:eq(0)\').val(),
password:$(\'input:eq(1)\').val()
};
$.ajax({
url:\'dt\',
method:\'post\',
data:JSON.stringify(obj),
success:function(res){
$(\'div+p\').html(res)
},
contentType:\'application/json\'
})
})
</script> </html> 他现在跳转不了呀老师
|
|
-- 作者:有点蓝 -- 发布时间:2021/11/6 14:08:00 -- 先网上搜索学学ajax的原理了,连什么是ajax还不懂。估计连js代码还看不懂,根本不知道代码在哪提交和接收返回数据的,先学一下js基础。这里没有时间给你们重头做科普的。 使用了框架的先过2遍框架文档,先不考虑Foxtable,做些静态页面例子,学会先把框架用起来,熟悉了在考虑结合Foxtable使用。瞎猫碰死耗子一样乱用是没有用的,更加浪费时间 success:function(res){ if (res = "成功") {
window.location.href = \'http://127.0.0.1/index.html\';
}
else{
window.location.href = \'http://127.0.0.1/logon.html\';
}
}, |
|
-- 作者:小试牛刀 -- 发布时间:2021/11/13 14:11:00 -- 语法错误 (操作符丢失) 在查询表达式 \'(单号=\'ak12\'+or+店铺名称=\'ak12\')\' 中。 |