mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-08 00:16:14 +00:00
46 lines
872 B
C#
46 lines
872 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using SportsStore.WebUI.Infrastructure.Abstract;
|
|
using SportsStore.WebUI.Models;
|
|
|
|
namespace SportsStore.WebUI.Controllers
|
|
{
|
|
public class AccountController : Controller
|
|
{
|
|
IAuthProvider authProvider;
|
|
|
|
public AccountController(IAuthProvider auth)
|
|
{
|
|
authProvider = auth;
|
|
}
|
|
|
|
public ViewResult Login()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Login(LoginViewModel model, string returnUrl)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
if (authProvider.Authenticate(model.UserName, model.Password))
|
|
{
|
|
return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("", "Incorrect username or password");
|
|
return View();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
}
|
|
} |