diff options
author | David Christiansen <coding@davedoes.net> | 2012-06-30 16:06:46 -0700 |
---|---|---|
committer | David Christiansen <coding@davedoes.net> | 2012-06-30 16:06:46 -0700 |
commit | 06401bb049dc29cf4446eb61a4a72317a644ce54 (patch) | |
tree | 7c475929350b31b4b848a1faa57bd0d7cbbf512c /src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs | |
parent | 02ce959db12fec57e846e5ebfa662cd0327ce69c (diff) | |
parent | 3286c37f3a967e7d142534df84604a66be9d176c (diff) | |
download | DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.zip DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.gz DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.bz2 |
Merge pull request #1 from DavidChristiansen/master
Kachow!
Diffstat (limited to 'src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs')
-rw-r--r-- | src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs b/src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs new file mode 100644 index 0000000..d6dd144 --- /dev/null +++ b/src/OAuth/OAuthAuthorizationServer/Controllers/HomeController.cs @@ -0,0 +1,59 @@ +namespace OAuthAuthorizationServer.Controllers { + using System.Configuration; + using System.Data.SqlClient; + using System.IO; + using System.Linq; + using System.Web.Mvc; + using System.Web.Security; + using OAuthAuthorizationServer.Code; + + [HandleError] + public class HomeController : Controller { + public ActionResult Index() { + return View(); + } + + public ActionResult About() { + return View(); + } + + [HttpPost] + public ActionResult CreateDatabase() { + string databasePath = Path.Combine(Server.MapPath(Request.ApplicationPath), "App_Data"); + if (!Directory.Exists(databasePath)) { + Directory.CreateDirectory(databasePath); + } + string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString.Replace("|DataDirectory|", databasePath); + var dc = new DataClassesDataContext(connectionString); + if (dc.DatabaseExists()) { + dc.DeleteDatabase(); + } + try { + dc.CreateDatabase(); + + // Add the necessary row for the sample client. + dc.Clients.InsertOnSubmit(new Client { + ClientIdentifier = "sampleconsumer", + ClientSecret = "samplesecret", + Name = "Some sample client", + }); + dc.Clients.InsertOnSubmit(new Client { + ClientIdentifier = "sampleImplicitConsumer", + Name = "Some sample client used for implicit grants (no secret)", + Callback = "http://localhost:59721/", + }); + + dc.SubmitChanges(); + + // Force the user to log out because a new database warrants a new row in the users table, which we create + // when the user logs in. + FormsAuthentication.SignOut(); + ViewData["Success"] = true; + } catch (SqlException ex) { + ViewData["Error"] = string.Join("<br>", ex.Errors.OfType<SqlError>().Select(er => er.Message).ToArray()); + } + + return this.View(); + } + } +} |