mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 10:37:55 +08:00
修改部分文件结构,完善第三方登陆功能
This commit is contained in:
62
OpenAuth.App/SSO/SSOAuthUtil.cs
Normal file
62
OpenAuth.App/SSO/SSOAuthUtil.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
{
|
||||
public class SSOAuthUtil
|
||||
{
|
||||
public static LoginResult Parse(PassportLoginRequest model)
|
||||
{
|
||||
model.Trim();
|
||||
|
||||
var result = new LoginResult();
|
||||
|
||||
try
|
||||
{
|
||||
//<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>Ϣ
|
||||
var usermanager = (UserManagerApp) DependencyResolver.Current.GetService(typeof (UserManagerApp));
|
||||
var 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().ToMd5(),
|
||||
InvalidTime = DateTime.Now.AddMinutes(10),
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = DateTime.Now,
|
||||
IpAddress = HttpContext.Current.Request.UserHostAddress
|
||||
};
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Session
|
||||
new UserAuthSessionService().Create(currentSession);
|
||||
|
||||
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