2016-07-19 15:18:45 +08:00
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Web.Mvc;
|
2016-07-08 11:28:38 +08:00
|
|
|
|
using OpenAuth.App.SSO;
|
2017-12-24 17:55:02 +08:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System;
|
2016-07-08 11:28:38 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.WebTest.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class LoginController : Controller
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
private string _appKey = ConfigurationManager.AppSettings["SSOAppKey"];
|
2016-07-08 11:28:38 +08:00
|
|
|
|
// GET: Login
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
ViewBag.AppKey = _appKey;
|
2016-07-08 11:28:38 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Index(string username, string password)
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
var result = AuthUtil.Login(_appKey, username, password);
|
2017-11-28 23:54:49 +08:00
|
|
|
|
if (result.Code == 200)
|
2017-12-24 17:55:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var cookie = new HttpCookie("Token", result.Token)
|
|
|
|
|
{
|
|
|
|
|
Expires = DateTime.Now.AddDays(10)
|
|
|
|
|
};
|
|
|
|
|
Response.Cookies.Add(cookie);
|
|
|
|
|
return Redirect("/home/index");
|
|
|
|
|
///拿掉地址栏Token,因为特别不安全。
|
|
|
|
|
///小王,xxx系统的地址是多少。。。然后账号就
|
|
|
|
|
}
|
2016-07-08 11:28:38 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-07-11 18:21:26 +08:00
|
|
|
|
return View(result);
|
2016-07-08 11:28:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-08 18:51:48 +08:00
|
|
|
|
|
|
|
|
|
public ActionResult Logout()
|
|
|
|
|
{
|
|
|
|
|
AuthUtil.Logout();
|
|
|
|
|
return Redirect("/Home/Index");
|
|
|
|
|
}
|
2016-07-08 11:28:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|