Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

biakelly

controle de acesso

Recommended Posts

Humm, não seria problema de conexão Xan, na verdade o sistema de login esta funcionando, só não esta rolando o nivel de acesso. Se eu mudar, vou ter que mexer em toda estrutura e não queria fazer isso pois esta tudo ok. Queria adaptar meu sistema de login e incluir o acesso por nível

 

 

O tópico anterior consegui resolver agora este aqui esta me dando dor de cabeça :wacko:

Compartilhar este post


Link para o post
Compartilhar em outros sites

Oi Gil, Tentei algumas opções mas sem sucesso

 

Estou usando assim:

 

Arquivo loggin.asp (quando mando formulário logar ele pega este arquivo)

<!--#include file="../conecta/conexao.asp" -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("usuario"))
If MM_valUsername <> "" Then
  MM_fldUserAuthorization=""
  MM_redirectLoginSuccess="../home/stats.asp"
  MM_redirectLoginFailed="../home/error_login.asp"
  MM_flag="ADODB.Recordset"
  set MM_rsUser = Server.CreateObject(MM_flag)
  MM_rsUser.ActiveConnection = MM_connDUportal_STRING
  MM_rsUser.Source = "SELECT USUARIO, SENHA"
  If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  MM_rsUser.Source = MM_rsUser.Source & " FROM USERS WHERE USUARIO='" & Replace(MM_valUsername,"'","''") &"' AND SENHA='" & Replace(Request.Form("senha"),"'","''") & "'"
  MM_rsUser.CursorType = 0
  MM_rsUser.CursorLocation = 2
  MM_rsUser.LockType = 3
  MM_rsUser.Open
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
	Response.Cookies("User") = MM_valUsername
	Response.Cookies("User").Expires = Date + 30
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And true Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%>

Arquivo para restringir as páginas, restriction.asp

<%
MM_authorizedUsers=""
MM_authFailedURL="login.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
Response.Cookies("User").Expires = Date - 300
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>

Ele esta logando qualquer um que tenha cadastro. Onde altero para restringir o acesso? tenho uma coluna chamada U_ACCESS para restringir.

Compartilhar este post


Link para o post
Compartilhar em outros sites

ainda estou trabalhando nisso :wacko:

 

Mudei assim

 

Arquivo loggin.asp

<!--#include file="../conecta/conexao.asp" -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("usuario"))
If MM_valUsername <> "" Then
  MM_fldUserAuthorization=""
  MM_redirectLoginSuccess="../home/stats.asp"
  MM_redirectLoginFailed="../home/error_login.asp"
  MM_flag="ADODB.Recordset"
  set MM_rsUser = Server.CreateObject(MM_flag)
  MM_rsUser.ActiveConnection = MM_connDUportal_STRING
  MM_rsUser.Source = "SELECT USUARIO, SENHA"
  If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  MM_rsUser.Source = MM_rsUser.Source & " FROM USERS WHERE USUARIO='" & Replace(MM_valUsername,"'","''") &"' AND SENHA='" & Replace(Request.Form("senha"),"'","''") & "'"
  MM_rsUser.CursorType = 0
  MM_rsUser.CursorLocation = 2
  MM_rsUser.LockType = 3
  MM_rsUser.Open
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
	Response.Cookies("User") = MM_valUsername
	Response.Cookies("User").Expires = Date + 30
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And true Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%>

Arquivo para restringir as páginas, restriction.asp

<%
MM_authorizedUsers=""
MM_authFailedURL="login.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
Response.Cookies("User").Expires = Date - 300
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>

ainda sem sucesso :(

Compartilhar este post


Link para o post
Compartilhar em outros sites

Então, no momento que vc enviar os dados do formulario para a pagina que faz o loguim vc deve recuperar a coluna U_ACCESS.

 

Para recuperar ela vc deve usar uma session

session("U_ACCESS") = rs("U_ACCESS")

 

E na pagina que que mostra as modulos do seu sistema vc usa o IF.

 

if SESSION("U_ACCESS") = "1" then
libera os modulos
elseif SESSION("U_ACESS") = "2" then
libera os modulos
end if

Compartilhar este post


Link para o post
Compartilhar em outros sites

Oi Gil eu entendi, mas não estou conseguindo adaptar, se eu fugir muito dos codigo acima outras áreas começam a dar problema no eof bof

Compartilhar este post


Link para o post
Compartilhar em outros sites

Consegui resolver de outra forma UHUUUUU!!:

<%
If Session("U_ACCESS") = "PAGO" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
Response.Cookies("User").Expires = Date - 300
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If

If session("U_ACCESS") < 1 Then 'se não for gerente
	Response.Cookies("User").Expires = Date - 300
	Response.write("<script type=""text/javascript"">alert(""Você não tem autorização para acessa esta página"");</script>")
	Response.Redirect "error_login.asp"
	Response.End
End If
%>

Agora sim esta tudo funcionando e sem bug, alterei o arquivo logging.asp e inseri a session para a coluna U_ACCESS.

 

Ufa, não podia dormir mais um dia sem resolver isso. :D ASP 0 X BIA 1 YEAHHHH!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.