main / Source / WebService / Web.Admin / Controllers / AccountController.cs

Naethra D ba1cb57 


























































using System;
using System.Web.Mvc;
using System.Web.Security;
using DataUp.Web.Admin.DataLayer;
using DataUp.Web.Admin.ViewModel;

namespace DataUp.Web.Admin.Controllers
{
    public class AccountController : Controller
    {
        IAdminUserRepository adminUserRepository;

        public AccountController(IAdminUserRepository userRepository)
        {
            this.adminUserRepository = userRepository;
        }

        //
        // GET: /Account/LogOn
        public ActionResult LogOn()
        {
            return View();
        }

        //
        // POST: /Account/LogOn
        [HttpPost]
        public ActionResult LogOn(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var membership = new CustomMembershipProvider(adminUserRepository);
                var user = membership.GetUser(model.UserName, model.Password);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    System.Web.HttpContext.Current.Session["User"] = user;
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError(String.Empty, "Incorrect Username or Password");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

        //
        // GET: /Account/LogOff

        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            System.Web.HttpContext.Current.Session.Clear();
            return RedirectToAction("LogOn", "Account");
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.