移除自定义LoginInfo类,使用BA.Security.Mvc中的通用类,晚上POST登陆方法

This commit is contained in:
Argo-Lenovo 2016-12-22 13:18:53 +08:00
parent 28d91d56e9
commit febcaf0662
1 changed files with 11 additions and 17 deletions

View File

@ -1,6 +1,10 @@
using Bootstrap.DataAccess;
using Bootstrap.Security.Mvc;
using Longbow.Caching;
using Longbow.Security.Principal;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Web.Http;
using System.Web.Security;
@ -14,7 +18,8 @@ namespace Bootstrap.Admin.Controllers
[HttpGet]
public LoginInfo Get()
{
return new LoginInfo() { UserName = User.Identity.Name, Token = string.Empty };
var token = Request.Headers.GetValues("Token").First();
return new LoginInfo() { UserName = User.Identity.Name, Token = token };
}
/// <summary>
///
@ -24,9 +29,12 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns>
[AllowAnonymous]
[HttpPost]
public LoginInfo Post(string userName, string password)
public LoginInfo Post([FromBody]JObject value)
{
if (UserHelper.Authenticate(userName, password))
dynamic user = value;
string userName = user.userName;
string password = user.password;
if (LgbPrincipal.IsAdmin(userName, password) || UserHelper.Authenticate(userName, password))
{
var token = Guid.NewGuid().ToString();
return CacheManager.AddOrUpdate(token, int.Parse(Math.Round(FormsAuthentication.Timeout.TotalSeconds).ToString()), k => new LoginInfo() { UserName = userName, Token = token }, (k, info) => info, "Token 数据缓存");
@ -34,18 +42,4 @@ namespace Bootstrap.Admin.Controllers
return new LoginInfo();
}
}
/// <summary>
///
/// </summary>
public class LoginInfo
{
/// <summary>
///
/// </summary>
public string UserName { get; set; }
/// <summary>
///
/// </summary>
public string Token { get; set; }
}
}