2016-01-05 17:14:10 +08:00
|
|
|
|
using System;
|
2016-07-19 15:18:45 +08:00
|
|
|
|
using System.Configuration;
|
2015-11-30 17:44:42 +08:00
|
|
|
|
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;
|
2016-01-02 23:16:22 +08:00
|
|
|
|
using OpenAuth.Mvc.Models;
|
2015-11-30 17:44:42 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class LoginController : Controller
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
private string _appKey = ConfigurationManager.AppSettings["SSOAppKey"];
|
2015-11-30 17:44:42 +08:00
|
|
|
|
|
|
|
|
|
// GET: Login
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
ViewBag.AppKey = _appKey;
|
2015-11-30 17:44:42 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Index(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
var result = AuthUtil.Login(_appKey, username, password);
|
2016-07-11 18:21:26 +08:00
|
|
|
|
if (result.Success)
|
|
|
|
|
return Redirect("/home/index?Token=" + result.Token);
|
2016-07-08 18:51:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-14 11:22:16 +08:00
|
|
|
|
var response = new Response
|
2016-07-08 18:51:48 +08:00
|
|
|
|
{
|
2016-10-14 11:22:16 +08:00
|
|
|
|
Status = false,
|
|
|
|
|
Message = "登陆失败"
|
2016-07-08 18:51:48 +08:00
|
|
|
|
};
|
|
|
|
|
return View(response);
|
|
|
|
|
}
|
2015-11-30 17:44:42 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2016-10-14 11:22:16 +08:00
|
|
|
|
var response = new Response
|
2016-01-02 23:16:22 +08:00
|
|
|
|
{
|
2016-10-14 11:22:16 +08:00
|
|
|
|
Status = false,
|
|
|
|
|
Message = e.Message
|
2016-01-02 23:16:22 +08:00
|
|
|
|
};
|
|
|
|
|
return View(response);
|
2015-11-30 17:44:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-01 17:30:24 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开发者登陆
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ActionResult LoginByDev()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-19 15:18:45 +08:00
|
|
|
|
var result = AuthUtil.Login(_appKey, "System","123456");
|
2016-07-11 18:21:26 +08:00
|
|
|
|
if (result.Success)
|
|
|
|
|
return Redirect("/home/index?Token=" + result.Token);
|
2016-07-08 18:51:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Index", "Login");
|
|
|
|
|
|
|
|
|
|
}
|
2015-12-01 17:30:24 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
return RedirectToAction("Index", "Login");
|
2015-12-01 17:30:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Logout()
|
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
|
2016-07-08 18:51:48 +08:00
|
|
|
|
AuthUtil.Logout();
|
2015-12-01 17:30:24 +08:00
|
|
|
|
return RedirectToAction("Index", "Login");
|
|
|
|
|
}
|
2015-11-30 17:44:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|