2016-10-21 16:35:26 +08:00
|
|
|
|
using Bootstrap.Admin.Models;
|
2016-10-23 15:46:18 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Security.Principal;
|
2016-11-06 12:28:53 +08:00
|
|
|
|
using System;
|
2016-10-21 16:35:26 +08:00
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Security;
|
2016-10-20 17:55:29 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers
|
|
|
|
|
{
|
2016-10-21 16:35:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-10-20 17:55:29 +08:00
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
2016-10-21 16:35:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2016-10-20 17:55:29 +08:00
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2016-11-01 15:57:41 +08:00
|
|
|
|
var v = new ContentModel();
|
|
|
|
|
v.Url = "/Content/html/dummy.html";
|
2016-10-21 16:35:26 +08:00
|
|
|
|
return View(v);
|
2016-10-20 17:55:29 +08:00
|
|
|
|
}
|
2016-10-21 16:35:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-11-06 02:11:03 +08:00
|
|
|
|
/// <returns></returns>
|
2016-11-06 12:28:53 +08:00
|
|
|
|
public ActionResult Lock(LockModel model)
|
2016-11-06 02:11:03 +08:00
|
|
|
|
{
|
2016-11-06 12:28:53 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(model.Password))
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Login", new { userName = model.UserName, password = model.Password });
|
|
|
|
|
}
|
|
|
|
|
var user = UserHelper.RetrieveUsersByName(User.Identity.Name);
|
|
|
|
|
model.UserName = user.UserName;
|
|
|
|
|
model.DisplayName = user.DisplayName;
|
|
|
|
|
return View(model);
|
2016-11-06 02:11:03 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-10-23 15:46:18 +08:00
|
|
|
|
/// <param name="userName"></param>
|
2016-10-21 16:35:26 +08:00
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
/// <param name="remember"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[AllowAnonymous]
|
2016-10-23 15:46:18 +08:00
|
|
|
|
public ActionResult Login(string userName, string password, string remember)
|
2016-10-20 17:55:29 +08:00
|
|
|
|
{
|
2016-10-23 15:46:18 +08:00
|
|
|
|
//UNDONE: 本方法有严重安全漏洞,发布前需要修正
|
|
|
|
|
var model = new LoginModel();
|
|
|
|
|
model.UserName = userName;
|
|
|
|
|
if (LgbPrincipal.IsAdmin(userName) || UserHelper.Authenticate(userName, password))
|
2016-10-21 16:35:26 +08:00
|
|
|
|
{
|
2016-11-01 13:58:26 +08:00
|
|
|
|
LgbPrincipal.SavePrincipalCookie(new LgbUser() { RealUserName = userName });
|
2016-10-23 15:46:18 +08:00
|
|
|
|
FormsAuthentication.RedirectFromLoginPage(userName, false);
|
2016-10-21 16:35:26 +08:00
|
|
|
|
}
|
2016-10-23 15:46:18 +08:00
|
|
|
|
return View(model);
|
2016-10-20 17:55:29 +08:00
|
|
|
|
}
|
2016-10-21 16:35:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2016-11-01 13:58:26 +08:00
|
|
|
|
[AllowAnonymous]
|
2016-10-21 16:35:26 +08:00
|
|
|
|
public ActionResult Logout()
|
|
|
|
|
{
|
|
|
|
|
FormsAuthentication.SignOut();
|
|
|
|
|
return RedirectToAction("Login");
|
|
|
|
|
}
|
2016-11-06 16:01:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public ActionResult Register(string userName, string displayName, string password)
|
|
|
|
|
{
|
|
|
|
|
var result = UserHelper.RegisterUser(userName, displayName, password);
|
|
|
|
|
if (result) return RedirectToAction("Login");
|
|
|
|
|
else return View();
|
|
|
|
|
}
|
2016-10-20 17:55:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|