-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserRegistration.aspx.cs
169 lines (154 loc) · 4.44 KB
/
UserRegistration.aspx.cs
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Seattle.DoIT.PoliceReports.Web.UserProfileServices;
using System.Threading;
using System.Web.Security;
using Seattle.DoIT.PoliceReports.Web.SsoServices;
namespace Seattle.DoIT.PoliceReports.Web
{
public partial class UserRegistration : System.Web.UI.Page
{
private UserProfile _userProfile;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.User.Identity.IsAuthenticated)
{
SiteNavigator.RedirectToSignInPage();
}
else
{
UserProfile userProfile = UserProfile;
if (userProfile != null)
{
if (userProfile.IsActive)
{
RedirectToDestination();
}
else
{
SiteNavigator.RedirectToAccessDeniedPage();
}
}
else
{
LoadSsoBasicProfile();
}
}
}
private void LoadSsoBasicProfile()
{
try
{
BasicProfile basicProfile = null;
BasicProfileService svc = SsoBasicProfileServiceFactory.Create();
using (svc as IDisposable)
{
basicProfile = svc.GetByUserName(User.Identity.Name);
}
if (basicProfile == null || string.IsNullOrEmpty(basicProfile.Email))
{
throw new Exception("Failed to retrieve email from SSO Basic profile");
}
else
{
UserEmail = basicProfile.Email;
}
}
catch
{
}
}
protected void RegisterButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
RegisterUser();
RedirectToDestination();
}
}
private void RegisterUser()
{
UserProfile newUserProfile = UserProfileFactory.Create(User.Identity.Name, UserEmail);
// Register by adding this user's profile profile for this user
UserProfileService svc = UserProfileServiceFactory.Create();
using (svc as IDisposable)
{
svc.Add(newUserProfile);
}
}
private string GetUserEmail(string userName)
{
// EVM-TBD: hard code for now - but integrated with SSO Basic Profile service later
return userName + "@ericksontest.com";
}
private UserProfile UserProfile
{
get
{
if (_userProfile == null)
{
UserProfileService svc = UserProfileServiceFactory.Create();
using (svc as IDisposable)
{
_userProfile = svc.GetByUserName(User.Identity.Name);
}
}
return _userProfile;
}
}
private bool IsUserRegistered
{
get
{
return UserProfile == null ? false : true;
}
}
private string DestinationUrl
{
get
{
string destUrl = string.Empty;
if (ViewState["DestinationUrl"] != null)
{
destUrl = Convert.ToString(ViewState["DestinationUrl"]);
}
else if (Request["dest"] != null)
{
try
{
destUrl = "~/" + Server.UrlDecode(Request["dest"]);
}
catch
{
destUrl = string.Empty;
}
}
return string.IsNullOrEmpty(destUrl) ? "~/" : destUrl;
}
}
private void RedirectToDestination()
{
SiteNavigator.Redirect(DestinationUrl);
}
protected void AcceptCheckboxIsCheckedValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = AgreeCheckbox.Checked;
}
private string UserEmail
{
get
{
object email = ViewState["UserEmail"];
return email == null ? string.Empty : email.ToString();
}
set
{
ViewState["UserEmail"] = value;
}
}
}
}