OpenAuth.Net/OpenAuth.WebApi/Areas/SSO/Controllers/CheckController.cs

70 lines
1.9 KiB
C#
Raw Normal View History

// ***********************************************************************
// Assembly : OpenAuth.WebApi
// Author : yubaolee
// Created : 07-11-2016
//
// Last Modified By : yubaolee
// Last Modified On : 07-11-2016
// Contact :
// File: CheckController.cs
// ***********************************************************************
2016-07-08 18:51:48 +08:00
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
using OpenAuth.App.SSO;
2016-07-08 18:51:48 +08:00
namespace OpenAuth.WebApi.Areas.SSO.Controllers
{
/// <summary>
/// sso验证
/// <para>其他站点通过后台Post来认证</para>
/// <para>或使用静态类OpenAuth.App.SSO.AuthUtil访问</para>
/// </summary>
2016-07-08 18:51:48 +08:00
public class CheckController : Controller
{
2016-07-19 11:44:48 +08:00
private AuthorizeApp _app;
2016-07-08 18:51:48 +08:00
public CheckController()
{
2016-07-19 11:44:48 +08:00
_app = AutofacExt.GetFromFac<AuthorizeApp>();
2016-07-08 18:51:48 +08:00
}
public bool GetStatus(string token = "", string requestid = "")
{
if (new UserAuthSessionService().GetCache(token))
{
return true;
}
return false;
}
public string GetUser(string token = "", string requestid = "")
{
string userName = GetUserName(token, requestid);
if (!string.IsNullOrEmpty(userName))
{
2016-07-19 11:44:48 +08:00
return JsonHelper.Instance.Serialize(_app.GetAccessedControls(userName));
}
return string.Empty;
}
public string GetUserName(string token, string requestid = "")
2016-07-08 18:51:48 +08:00
{
var user = new UserAuthSessionService().Get(token);
if (user != null)
{
return user.UserName;
2016-07-08 18:51:48 +08:00
}
return string.Empty;
}
[HttpPost]
public string Login(PassportLoginRequest request)
{
return JsonHelper.Instance.Serialize(SSOAuthUtil.Parse(request));
}
2016-07-08 18:51:48 +08:00
}
}