diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-06-06 16:23:01 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-06-06 16:23:01 -0700 |
commit | 299fd439688e9e4a220c862b92ec82e82bdf0ab0 (patch) | |
tree | 52489fda9952d9aa7ccd59fab795e6862e24753b /samples/OAuthAuthorizationServer/Controllers/HomeController.cs | |
parent | e76823bc716477d3d5e26d17d0df7a2314bc2d82 (diff) | |
parent | dbbc823b7580d4e7d5251539a8dcace730df2e3f (diff) | |
download | DotNetOpenAuth-299fd439688e9e4a220c862b92ec82e82bdf0ab0.zip DotNetOpenAuth-299fd439688e9e4a220c862b92ec82e82bdf0ab0.tar.gz DotNetOpenAuth-299fd439688e9e4a220c862b92ec82e82bdf0ab0.tar.bz2 |
Merging OAuth 2.0 work into what will become DotNetOpenAuth 4.0.
Diffstat (limited to 'samples/OAuthAuthorizationServer/Controllers/HomeController.cs')
-rw-r--r-- | samples/OAuthAuthorizationServer/Controllers/HomeController.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/samples/OAuthAuthorizationServer/Controllers/HomeController.cs b/samples/OAuthAuthorizationServer/Controllers/HomeController.cs new file mode 100644 index 0000000..1311caa --- /dev/null +++ b/samples/OAuthAuthorizationServer/Controllers/HomeController.cs @@ -0,0 +1,54 @@ +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.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(); + } + } +} |