I have a log in page with 2 forms, one simply has username and password fields which when filled out allow the user to be 'logged in'.
The second is for new users to register, so there are several fields for them to fill out, i.e. name, address, username, password, etc.
I am using the Dreamweaver User Authentication feature, which works great for the first form, but what I want is for when a new user registers they are automatically logged in also.
Here is the code:
Registration page
---------------------
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("U
RL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.
QueryStrin
g)
MM_valUsername=CStr(Reques
t.Form("Em
ail"))
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="c
heckout.as
p"
MM_redirectLoginFailed="re
gistration
.asp"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_fla
g)
MM_rsUser.ActiveConnection
= MM_bath_STRING
MM_rsUser.Source = "SELECT userEmail, userPassword"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM users WHERE userEmail='" & Replace(MM_valUsername,"'"
,"''") &"' AND userPassword='" & Replace(Request.Form("Pass
word"),"'"
,"''") & "'"
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
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorizat
ion") = CStr(MM_rsUser.Fields.Item
(MM_fldUse
rAuthoriza
tion).Valu
e)
Else
Session("MM_UserAuthorizat
ion") = ""
End If
if CStr(Request.QueryString("
accessdeni
ed")) <> "" And false Then
MM_redirectLoginSuccess = Request.QueryString("acces
sdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redir
ectLoginSu
ccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redir
ectLoginFa
iled)
End If
%>
Logged in page
------------------
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="index.as
p"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (true Or CStr(Session("MM_UserAutho
rization")
)="") Or _
(InStr(1,MM_authorizedUser
s,Session(
"MM_UserAu
thorizatio
n"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,
"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("U
RL")
if (Len(Request.QueryString()
) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referr
er)
Response.Redirect(MM_authF
ailedURL)
End If
%>
Many thanks
Chris
Start Free Trial