home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / LoginAction.asp < prev    next >
Text File  |  2006-10-25  |  5KB  |  107 lines

  1. <!--#Include File="Include/Top_inc.asp"-->
  2. <%
  3. '***********************************************************************
  4. '   Application: SelectSurveyASP Advanced v8.1.11
  5. '   Author: Aaron Baril for ClassApps.com
  6. '   Page Description: This page works with Login.asp, and is the page that
  7. '                     checks the user's password and logs the user into the
  8. '                     application.  A user is known to be logged into the
  9. '                     application when the appropriate cookie has been set
  10. '                     on his/her machine.
  11. '
  12. '   COPYRIGHT NOTICE                                
  13. '
  14. '   See attached Software License Agreement
  15. '
  16. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  17. '***********************************************************************
  18. %>
  19. <!--#Include File="Include/Config_inc.asp"-->
  20. <!--#Include File="Include/Utility_inc.asp"-->
  21. <!--#Include File="Include/adovbs_inc.asp"-->
  22. <!--#Include File="Include/Constants_inc.asp"-->
  23. <!--#Include File="Include/CurrentUser_inc.asp"-->
  24. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  25. <%
  26.     Dim strSQL
  27.     Dim rsLogin
  28.     Dim flgValidLogin
  29.     Dim lngSecurityLevel
  30.     
  31.     'Initialization
  32.     Set rsLogin = Server.CreateObject("ADODB.Recordset")
  33.     strSQL = "SELECT username, user_password, active_yn " & _
  34.               "FROM sur_user " & _
  35.              "WHERE username = " & SQLEncode(Request.Form("txtUserName")) & _
  36.              " AND user_password = " & SQLEncode(Request.Form("txtPassword"))
  37.     rsLogin.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  38.     
  39.     'If there are no records returned, the login credentials were not valid
  40.     If rsLogin.EOF = True Then
  41.         flgValidLogin = False    
  42.     Else
  43.         rsLogin.MoveFirst
  44.     
  45.         'Make sure the user is active
  46.         If rsLogin("active_yn") = SUR_BOOLEAN_POSITIVE Then
  47.             flgValidLogin = True
  48.         Else
  49.             'Since the login failed due to an inactive account, set a cookie indicating inactive and
  50.             'redirect the user to the login page
  51.             Response.Cookies(SUR_APPLICATION_LOGIN_COOKIE)(SUR_COOKIE_LOGIN) = SUR_LOGIN_INACTIVE
  52.                 
  53.             'If the Survey ID or EID were passed to the login page as part of the querystring, include 
  54.             'it when redirecting back to the Login page
  55.             If Len(Request.Form("SurveyID")) > 0 Then
  56.                 Response.Redirect "Login.asp?SurveyID=" & Request.Form("SurveyID")
  57.             ElseIf Len(Request.Form("EID")) > 0 Then
  58.                 Response.Redirect "Login.asp?EID=" & Request.Form("EID")
  59.             Else
  60.                 Response.Redirect "Login.asp"
  61.             End If
  62.         End If
  63.     End If
  64.     rsLogin.Close
  65.     Set rsLogin = Nothing
  66.     
  67.     'If the login was successful, create a cookie that indicates that the user has
  68.     'been validated successfully; otherwise, create a cookie that says that the login failed
  69.     If flgValidLogin = False Then
  70.         Response.Cookies(SUR_APPLICATION_LOGIN_COOKIE)(SUR_COOKIE_LOGIN) = SUR_LOGIN_FAILED
  71.         
  72.         'Since the login failed, redirect the user to the login page.
  73.         'If the Survey ID or EID were passed to the login page as part of the querystring, include 
  74.         'it when redirecting back to the Login page
  75.         If Len(Request.Form("SurveyID")) > 0 Then
  76.             Response.Redirect "Login.asp?SurveyID=" & Request.Form("SurveyID")
  77.         ElseIf Len(Request.Form("EID")) > 0 Then
  78.             Response.Redirect "Login.asp?EID=" & Request.Form("EID")
  79.         Else
  80.             Response.Redirect "Login.asp"
  81.         End If
  82.     Else 'Valid login
  83.         'Clear out the session when first logging in.  This is necessary if a user accesses the application with 
  84.         'report sharing or takes a survey anonymously, and then tries to log in.
  85.         Session.Abandon
  86.         
  87.         Response.Cookies(SUR_APPLICATION_LOGIN_COOKIE)(SUR_COOKIE_LOGIN) = SUR_LOGIN_VALIDATED
  88.         Response.Cookies(SUR_APPLICATION_COOKIE)(SUR_USERNAME) = Request.Form("txtUserName")
  89.  
  90.         'If a survey ID or EID were passed to this page, redirect the user to take that survey
  91.         If Len(Request.Form("SurveyID")) > 0 Then
  92.             Response.Redirect "TakeSurvey.asp?SurveyID=" & Request.Form("SurveyID")
  93.         ElseIf Len(Request.Form("EID")) > 0 Then
  94.             Response.Redirect "TakeSurvey.asp?EID=" & Request.Form("EID")
  95.         Else
  96.             'If the user is has "Create" or "Admin" permission, redirect to the MySurveysList page; otherwise, redirect to the 
  97.             'TakeSurveyList page
  98.             lngSecurityLevel = GetSecurityLevel()
  99.             If lngSecurityLevel = SUR_SECURITY_LEVEL_CREATE Or lngSecurityLevel = SUR_SECURITY_LEVEL_ADMIN Then
  100.                 Response.Redirect "SurveyList.asp"
  101.             Else
  102.                 Response.Redirect SUR_APPLICATION_DEFAULT_HOME_PAGE
  103.             End If
  104.         End If
  105.     End If
  106. %>
  107.