-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.aspx.vb
138 lines (92 loc) · 4.31 KB
/
default.aspx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.Owin.Security.OpenIdConnect
Imports Newtonsoft.Json
Public Class _default
Inherits System.Web.UI.Page
Private addAdminScrip As Boolean = False
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Form.AllKeys.Contains("ActionId") Then
Dim lStrCallbackUrl As String = String.Format("{0}://{1}/default.aspx", Request.Url.Scheme, Request.Url.Authority)
If Request.Form("ActionId") = "342f02ac-8362-4c77-a83c-11ba761fd23b" Then
'LOGIN
Context.GetOwinContext().Authentication.Challenge(
New AuthenticationProperties With {.RedirectUri = lStrCallbackUrl},
OpenIdConnectAuthenticationDefaults.AuthenticationType)
ElseIf Request.Form("ActionId") = "401e81e9-6792-43f8-b755-8bf0cd40379b" Then
'LOGOUT
' Context.GetOwinContext().Authentication.SignOut(
' New AuthenticationProperties With {.RedirectUri = lStrCallbackUrl},
' OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType)
Dim n As Microsoft.Owin.OwinContext = Context.GetOwinContext()
For Each d In n.Request.Cookies
n.Response.Cookies.Delete(d.Key)
Next
Session.Clear()
Session.Abandon()
Response.Redirect(Request.RawUrl)
End If
End If
If User.arsIsAuthenticated() Then
If Session("ArsUser") Is Nothing Then
Session("ArsUser") =
New Ars.User(User.azureOnpremSid)
Else
'Session("ArsUser").SetHttpContext(Context)
End If
'CONFIGURE LOGOUT BUTTON
ActionId.Value = "401e81e9-6792-43f8-b755-8bf0cd40379b"
btnAction.Value = "Logout"
'CHECK USER EXISTS IN DATABASE
If Session("ArsUser").IsAllowed Then
arsMain.Visible = True
arsNav.Visible = True
If Session("ArsUser").IsAdmin Then
addAdminScrip = True
arsNavAdminMenu.Visible = True
End If
Else
arsMessage_AccessDenied.Visible = True
End If
Else
Session.Clear()
'CONFIGURE LOGIN BUTTON
ActionId.Value = "342f02ac-8362-4c77-a83c-11ba761fd23b"
btnAction.Value = "Login"
If Request.QueryString("auth_error") IsNot Nothing Then
'SHOW LOGIN ERROR
arsMessage_AuthErrorMessage.InnerText = Request.QueryString("auth_error")
arsMessage_AuthError.Visible = True
Else
'SHOW PLEASE LOGIN
arsMessage_Login.Visible = True
End If
End If
If User.onpremAuthenticated() = True Then
arsAdAuth.Visible = True
End If
If User.azureAuthenticated() = True Then
arsAzAuth.Visible = True
btnAzAuth.Attributes("data-AzExpTs") =
User.azureAuthenticationExpireTimestamp()
End If
'ADD VERSION TO CSS AND JS FILES
For Each lObjControl In Page.Header.Controls
If lObjControl.GetType() = GetType(System.Web.UI.HtmlControls.HtmlLink) Then
lObjControl.href = Replace(lObjControl.href, ".css", ".css?v=" & Application("appVer"))
End If
If lObjControl.GetType() = GetType(System.Web.UI.LiteralControl) Or lObjControl.GetType() = GetType(System.Web.UI.WebControls.Literal) Then
lObjControl.text = Replace(lObjControl.text, ".js", ".js?=" & Application("appVer"))
End If
Next
End Sub
Private Sub _default_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
If addAdminScrip Then
If Page.Header IsNot Nothing Then
Dim lObjAdminScript As New HtmlGenericControl("script")
lObjAdminScript.Attributes.Add("src", "/inc/js/arsAdmin.js")
Page.Header.Controls.AddAt(6, lObjAdminScript)
End If
End If
End Sub
End Class