mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-12-26 22:25:39 +08:00
优化autofac注入方式,Controller使用属性注入
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
{
|
||||
|
||||
public class PassportLoginRequest
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string AppKey { get; set; }
|
||||
|
||||
public void Trim()
|
||||
{
|
||||
if (string.IsNullOrEmpty(UserName))
|
||||
{
|
||||
throw new Exception("用户名不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
throw new Exception("密码不能为空");
|
||||
}
|
||||
UserName = UserName.Trim();
|
||||
Password = Password.Trim();
|
||||
if(!string.IsNullOrEmpty(AppKey)) AppKey = AppKey.Trim();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
{
|
||||
|
||||
public class PassportLoginRequest
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string AppKey { get; set; }
|
||||
|
||||
public void Trim()
|
||||
{
|
||||
if (string.IsNullOrEmpty(UserName))
|
||||
{
|
||||
throw new Exception("用户名不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
throw new Exception("密码不能为空");
|
||||
}
|
||||
UserName = UserName.Trim();
|
||||
Password = Password.Trim();
|
||||
if(!string.IsNullOrEmpty(AppKey)) AppKey = AppKey.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,78 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
{
|
||||
public class SSOAuthUtil
|
||||
{
|
||||
public static LoginResult Parse(PassportLoginRequest model)
|
||||
{
|
||||
var result = new LoginResult();
|
||||
try
|
||||
{
|
||||
model.Trim();
|
||||
//<2F><>ȡӦ<C8A1><D3A6><EFBFBD><EFBFBD>Ϣ
|
||||
var appInfo = new AppInfoService().Get(model.AppKey);
|
||||
if (appInfo == null)
|
||||
{
|
||||
throw new Exception("Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
//<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
||||
User userInfo = null;
|
||||
if (model.UserName == "System")
|
||||
{
|
||||
userInfo = new User
|
||||
{
|
||||
Id = Guid.Empty,
|
||||
Account = "System",
|
||||
Name ="<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա",
|
||||
Password = "123456"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var usermanager = (UserManagerApp)DependencyResolver.Current.GetService(typeof(UserManagerApp));
|
||||
userInfo = usermanager.Get(model.UserName);
|
||||
}
|
||||
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new Exception("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
if (userInfo.Password != model.Password)
|
||||
{
|
||||
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
var currentSession = new UserAuthSession
|
||||
{
|
||||
UserName = model.UserName,
|
||||
Token = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = DateTime.Now,
|
||||
IpAddress = HttpContext.Current.Request.UserHostAddress
|
||||
};
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Session
|
||||
new ObjCacheProvider<UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
|
||||
|
||||
result.Success = true;
|
||||
result.ReturnUrl = appInfo.ReturnUrl;
|
||||
result.Token = currentSession.Token;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMsg = ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
{
|
||||
public class SSOAuthUtil
|
||||
{
|
||||
public static LoginResult Parse(PassportLoginRequest model)
|
||||
{
|
||||
var result = new LoginResult();
|
||||
try
|
||||
{
|
||||
model.Trim();
|
||||
//<2F><>ȡӦ<C8A1><D3A6><EFBFBD><EFBFBD>Ϣ
|
||||
var appInfo = new AppInfoService().Get(model.AppKey);
|
||||
if (appInfo == null)
|
||||
{
|
||||
throw new Exception("Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
//<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
||||
User userInfo = null;
|
||||
if (model.UserName == "System")
|
||||
{
|
||||
userInfo = new User
|
||||
{
|
||||
Id = Guid.Empty,
|
||||
Account = "System",
|
||||
Name ="<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա",
|
||||
Password = "123456"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var usermanager = (UserManagerApp)DependencyResolver.Current.GetService(typeof(UserManagerApp));
|
||||
userInfo = usermanager.Get(model.UserName);
|
||||
}
|
||||
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new Exception("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
if (userInfo.Password != model.Password)
|
||||
{
|
||||
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
var currentSession = new UserAuthSession
|
||||
{
|
||||
UserName = model.UserName,
|
||||
Token = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = DateTime.Now,
|
||||
IpAddress = HttpContext.Current.Request.UserHostAddress
|
||||
};
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Session
|
||||
new ObjCacheProvider<UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
|
||||
|
||||
result.Success = true;
|
||||
result.ReturnUrl = appInfo.ReturnUrl;
|
||||
result.Token = currentSession.Token;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMsg = ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user