OpenAuth.Net/OpenAuth.Mvc/Controllers/LoginController.cs

93 lines
2.6 KiB
C#
Raw Normal View History

using System;
2016-07-19 15:18:45 +08:00
using System.Configuration;
using System.Web.Mvc;
2016-10-14 11:22:16 +08:00
using Infrastructure;
2016-07-08 18:51:48 +08:00
using OpenAuth.App.SSO;
using System.Web;
namespace OpenAuth.Mvc.Controllers
{
public class LoginController : Controller
{
2016-07-19 15:18:45 +08:00
private string _appKey = ConfigurationManager.AppSettings["SSOAppKey"];
// GET: Login
public ActionResult Index()
{
2016-07-19 15:18:45 +08:00
ViewBag.AppKey = _appKey;
return View();
}
[HttpPost]
2016-10-28 19:02:02 +08:00
public string Index(string username, string password)
{
var resp = new LoginResult();
try
{
2016-07-19 15:18:45 +08:00
var result = AuthUtil.Login(_appKey, username, password);
if (result.Code == 200)
2016-10-28 19:02:02 +08:00
{
var cookie = new HttpCookie("Token", result.Token)
{
Expires = DateTime.Now.AddDays(10)
};
Response.Cookies.Add(cookie);
resp.Result = "/home/index";
///拿掉地址栏Token因为特别不安全。
///小王xxx系统的地址是多少。。。然后账号就
2016-10-28 19:02:02 +08:00
}
2016-07-08 18:51:48 +08:00
else
{
2017-10-12 16:38:46 +08:00
resp.Message = "登录失败";
2016-07-08 18:51:48 +08:00
}
}
catch (Exception e)
{
resp.Code = 500;
2016-10-28 19:02:02 +08:00
resp.Message = e.Message;
}
2016-10-28 19:02:02 +08:00
return JsonHelper.Instance.Serialize(resp);
}
2015-12-01 17:30:24 +08:00
/// <summary>
2017-10-12 16:38:46 +08:00
/// 开发者登录
2015-12-01 17:30:24 +08:00
/// </summary>
public ActionResult LoginByDev()
{
try
{
var result = AuthUtil.Login(_appKey, "System", "123456");
if (result.Code == 200)
{
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 18:51:48 +08:00
else
{
return RedirectToAction("Index", "Login");
}
2015-12-01 17:30:24 +08:00
}
catch (Exception e)
{
return RedirectToAction("Index", "Login");
2015-12-01 17:30:24 +08:00
}
}
public ActionResult Logout()
{
2016-07-08 18:51:48 +08:00
AuthUtil.Logout();
2015-12-01 17:30:24 +08:00
return RedirectToAction("Index", "Login");
}
}
}