<%@ LANGUAGE=VBScript %>
<% Option Explicit %>
<!--#include virtual="/NR/Shared/ASPUtils.inc"-->
<!--#include virtual="/NR/system/access/IISAuthentication.inc"-->
<!--#include virtual="/NR/system/access/ManualLogin.inc"-->
<%
'DefaultGuestLogin.asp: logs a user in as the default guest user by removing the
'authentication cookie.
'	Expects 1 parameter:
'	- ReturnUrl: the page to be redirected to when the script ends

Response.Buffer = True
Response.Expires = 0

Dim GUEST_LOGIN_NOT_ENABLED
Dim AutoSession
Dim returnUrl

set AutoSession = Server.CreateObject("ResolutionObjectModel.AutoSession3")


GUEST_LOGIN_NOT_ENABLED = "You have logged out and no default guest access is enabled.  To regain access to Content Management Server please login again."


returnUrl = Request.QueryString("ReturnUrl")

'Remove the authentication cookie by setting its expiry to a past date.
Response.Cookies("CMSAUTHTOKEN").Expires = Date - 1
Response.Cookies("CMSAUTHTOKEN").Path = "/"


If IsUsingIISAuthentication Then
	' Redirect to the originally requested page - logout is not supported from an
	' IIS authenticated session
    ServerSideRedirect(returnUrl)
ElseIf  AutoSession.IsDefaultGuestEnabled Then
	'Redirect to the originally requested page.
	'Since the cookie was cleared, you should now be authenticated as the default guest.
    ServerSideRedirect(returnUrl)
Else
	'Redirect to ManualLogin page explaining that the default guest is not enabled
	call ServerSideRedirect( GetManualLoginRedirectUrl( GUEST_LOGIN_NOT_ENABLED , returnUrl ) )
End If

%>
