summaryrefslogtreecommitdiffstats
path: root/projecttemplates/WebFormsRelyingParty/Setup.aspx.cs
diff options
context:
space:
mode:
Diffstat (limited to 'projecttemplates/WebFormsRelyingParty/Setup.aspx.cs')
-rw-r--r--projecttemplates/WebFormsRelyingParty/Setup.aspx.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/projecttemplates/WebFormsRelyingParty/Setup.aspx.cs b/projecttemplates/WebFormsRelyingParty/Setup.aspx.cs
new file mode 100644
index 0000000..71e64ce
--- /dev/null
+++ b/projecttemplates/WebFormsRelyingParty/Setup.aspx.cs
@@ -0,0 +1,57 @@
+namespace WebFormsRelyingParty {
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.IO;
+ using System.Linq;
+ using System.Web;
+ using System.Web.UI;
+ using System.Web.UI.WebControls;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+ using Microsoft.SqlServer.Management.Common;
+ using Microsoft.SqlServer.Management.Smo;
+
+ public partial class Setup : System.Web.UI.Page {
+ protected void Page_Load(object sender, EventArgs e) {
+ if (!Page.IsPostBack) {
+ openidLogin.Focus();
+ }
+ }
+
+ protected void openidLogin_LoggingIn(object sender, OpenIdEventArgs e) {
+ // We don't actually want to log in... we just want the claimed identifier.
+ e.Cancel = true;
+ if (e.IsDirectedIdentity) {
+ noOPIdentifierLabel.Visible = true;
+ } else {
+ this.CreateDatabase(e.ClaimedIdentifier, openidLogin.Text);
+ this.MultiView1.ActiveViewIndex = 1;
+ }
+ }
+
+ private void CreateDatabase(Identifier claimedId, string friendlyId) {
+ const string SqlFormat = @"
+CREATE DATABASE [{0}] ON (NAME='{0}', FILENAME='{0}')
+GO
+USE ""{0}""
+GO
+{1}
+EXEC [dbo].[AddUser] 'admin', 'admin', '{2}', '{3}'
+GO
+";
+ string databasePath = HttpContext.Current.Server.MapPath("~/App_Data/Database.mdf");
+ string schemaSql = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Admin/CreateDatabase.sql"));
+ string sql = string.Format(CultureInfo.InvariantCulture, SqlFormat, databasePath, schemaSql, claimedId, friendlyId);
+
+ var serverConnection = new ServerConnection(".\\sqlexpress");
+ try {
+ serverConnection.ExecuteNonQuery(sql);
+ var server = new Server(serverConnection);
+ server.DetachDatabase(databasePath, true);
+ } finally {
+ serverConnection.Disconnect();
+ }
+ }
+ }
+}