summaryrefslogtreecommitdiffstats
path: root/TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'TwoStepsAuthenticator.TestWebsite/Controllers/HomeController.cs')
-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");
+ }
+ }
+}