許可權管理的設計和實現(含示範和原代碼)

來源:互聯網
上載者:User
設計 許可權管理的核心,就是對不同許可權的使用者,分配管理對應許可權的資源。

本例以一個網站欄目後台管理模組(資源)的許可權管理為例,實現了不同使用者的許可權管理。

資料庫設計:

帳戶資訊表:
f_i_autoid 自動編碼(主鍵)
f_i_orderid
f_accountid 帳戶編碼
f_accountname 帳戶 (外鍵)
f_password 密碼
f_accounttype
f_username
f_remark
f_datetime


欄目資訊表:
f_i_autoid 自動編碼(主鍵)
f_i_orderid
f_lanmuid 欄目編碼
f_lanmuname 欄目 (外鍵)
f_ishidden
f_remark
f_datetime


許可權表:
f_i_autoid 自動編碼(主鍵)
f_accountname 帳戶 (外鍵)
f_lanmuname 欄目 (外鍵)
f_remark
f_datetime

通過許可權表的 f_accountname 帳戶(外鍵)和 f_lanmuname 欄目(外鍵)把帳戶資訊表
和欄目資訊表聯絡起來,通過給“帳戶”分配“欄目”,或者給“欄目”分配“帳戶”,使帳戶和欄目建立關係(可以是“一對多”“多對一”或者“多對多”)。

然後以當前登陸的帳戶為基準,在許可權表中尋找其可管理的欄目(資源)。

本例實現了一個使用者對多欄目的管理(但是一個欄目只能被一個使用者管理 - 這個通過程式碼的約束來實現)。

以下是部分代碼:
<% Option explicit %>
<!-- #include file="./globals.inc" -->
<!-- #include file="./connects.inc" -->

<html>
<head>
<title>編輯許可權</title>
<link href="./style/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0)">
<script language="javascript">
function openwin(url, l, t, w ,h)
{open(url,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+ w +',height='+ h +',left='+ l +',top='+ t);}

function check_and_submit(frm)
{
SelectAll(frm.SelectedItem);
frm.submit();
}
</script>
</head>

<body topmargin=20 leftmargin=0 background="../images/bg.gif">

<%
Dim sSQL, rs1, rs2, rs3, CurrentAccount

CurrentAccount = request("CurrentAccount")
%>

<form name="frm1" id="frm1" method="post" action="save.asp">
<input name="allowsubmit" type="hidden" value="OK">

<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height=30>
<td colspan=3>
     
帳號資訊:
<input name="accountname" type="hidden" value="<%=CurrentAccount%>">
<%
sSQL = "select * from tabAccountInfo where f_accountname='" & CurrentAccount & "'"
Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.open sSQL, sConn, 1, 1
if rs1.eof and rs1.bof then
response.write("沒有取得該使用者的資訊。")
response.end
else
response.write " [帳號:] <font color=#ff0000>" & rs1("f_accountname") & "</font> [使用者姓名:] " & rs1("f_username") & " [帳號類型:] " & rs1("f_accounttype")
end if
Set rs1 = nothing
%>
</td>
</tr>
<tr height=10><td colspan=3></td></tr>
<tr>
<td width="220" align=center valign="top">
已指派該使用者管理的欄目:<br><br>
<select name="SelectedItem" id="SelectedItem" size=12 multiple="true">
<%
'選擇所有欄目中除去已經分配的欄目:
sSQL = "select f_lanmuname from tabQXB where f_accountname='"& CurrentAccount &"' order by f_lanmuname"
Set rs3 = Server.CreateObject("ADODB.Recordset")
rs3.open sSQL, sConn, 1, 1
if rs3.eof and rs3.bof then
response.write("<option>無</option>") & chr(13)
else
while not rs3.eof
response.write "<option>" & rs3("f_lanmuname") & "</option>" & chr(13)
rs3.movenex



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.