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

83 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Web.Mvc;
using OpenAuth.App;
2016-07-08 18:51:48 +08:00
using OpenAuth.App.SSO;
2016-01-02 23:16:22 +08:00
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
public class LoginController : Controller
{
private LoginApp _app;
public LoginController()
{
_app = AutofacExt.GetFromFac<LoginApp>();
}
// GET: Login
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string username, string password)
{
try
{
2016-07-08 18:51:48 +08:00
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", username, password);
if (!string.IsNullOrEmpty(token))
return Redirect("/home/index?Token=" + token);
else
{
var response = new BjuiResponse
{
statusCode = "300",
message = "登陆失败"
};
return View(response);
}
}
catch (Exception e)
{
2016-01-02 23:16:22 +08:00
var response = new BjuiResponse
{
statusCode = "300",
message = e.Message
};
return View(response);
}
}
2015-12-01 17:30:24 +08:00
/// <summary>
/// 开发者登陆
/// </summary>
public ActionResult LoginByDev()
{
try
{
2016-07-08 19:44:56 +08:00
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", "System","123456");
2016-07-08 18:51:48 +08:00
if (!string.IsNullOrEmpty(token))
return Redirect("/home/index?Token=" + token);
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");
}
}
}