summaryrefslogtreecommitdiffstats
path: root/TwoStepsAuthenticator.TestWebsite/Controllers
diff options
context:
space:
mode:
authorGuillaume <guillaumelacasa@hotmail.com>2013-06-12 22:12:40 +0200
committerGuillaume <guillaumelacasa@hotmail.com>2013-06-12 22:12:40 +0200
commitb06c0faaf8881f9447f3fd682feffcf3ddae1990 (patch)
tree5e1b02b441e672171d2438e09880484131991a2f /TwoStepsAuthenticator.TestWebsite/Controllers
parent9cfb653f0b1ddcdc221a3abcb9e16769e0ab1d71 (diff)
downloadTwoStepsAuthenticator-b06c0faaf8881f9447f3fd682feffcf3ddae1990.zip
TwoStepsAuthenticator-b06c0faaf8881f9447f3fd682feffcf3ddae1990.tar.gz
TwoStepsAuthenticator-b06c0faaf8881f9447f3fd682feffcf3ddae1990.tar.bz2
Test site ok
Diffstat (limited to 'TwoStepsAuthenticator.TestWebsite/Controllers')
-rw-r--r--TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs b/TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs
new file mode 100644
index 0000000..c926019
--- /dev/null
+++ b/TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Security;
+using TwoStepsAuthenticator.TestWebsite.Users;
+
+namespace TwoStepsAuthenticator.TestWebsite.Controllers
+{
+ public class HomeController : Controller
+ {
+ //
+ // GET: /Home/
+
+ public ActionResult Index()
+ {
+ return View();
+ }
+
+ [HttpPost]
+ public ActionResult Login(string login, string password)
+ {
+ if (Membership.ValidateUser(login, password))
+ {
+ var user = WebsiteUserStorage.GetUser(login);
+ if (user.DoubleAuthActivated)
+ {
+ Session["AuthenticatedUser"] = user;
+ return View("DoubleAuth", user);
+ }
+ else
+ {
+ FormsAuthentication.SetAuthCookie(login, true);
+ return RedirectToAction("Welcome");
+ }
+ }
+ return RedirectToAction("Index");
+ }
+
+ [HttpPost]
+ public ActionResult DoubleAuth(string code)
+ {
+ WebsiteUser user = (WebsiteUser)Session["AuthenticatedUser"];
+ var auth = new TwoStepsAuthenticator.Authenticator();
+ if (auth.CheckCode(user.DoubleAuthKey, code))
+ {
+ FormsAuthentication.SetAuthCookie(user.Login, true);
+ return RedirectToAction("Welcome");
+ }
+
+ return RedirectToAction("Index");
+ }
+
+ [Authorize]
+ public ActionResult Welcome()
+ {
+ return View() ;
+ }
+
+ [Authorize]
+ public ActionResult Logout()
+ {
+ FormsAuthentication.SignOut();
+ return RedirectToAction("Index");
+ }
+ }
+}