mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
check some bugs
This commit is contained in:
parent
9a328c9c90
commit
994ab81ebb
@ -77,7 +77,7 @@ namespace OpenAuth.App.SSO
|
||||
/// <param name="username">̞</param>
|
||||
/// <param name="pwd">ÃÜÂë</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string Login(string appKey, string username, string pwd)
|
||||
public static LoginResult Login(string appKey, string username, string pwd)
|
||||
{
|
||||
var requestUri = "/SSO/Login/Check";
|
||||
|
||||
@ -91,18 +91,12 @@ namespace OpenAuth.App.SSO
|
||||
}, requestUri);
|
||||
|
||||
var result = JsonHelper.Instance.Deserialize<LoginResult>(value);
|
||||
if (result.Success)
|
||||
{
|
||||
return result.Token;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,11 @@ namespace OpenAuth.App
|
||||
_relevanceRepository = relevanceRepository;
|
||||
}
|
||||
|
||||
public User Get(string account)
|
||||
{
|
||||
return _repository.FindSingle(u => u.Account == account);
|
||||
}
|
||||
|
||||
public int GetUserCntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
@ -8,12 +7,8 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class LoginController : Controller
|
||||
{
|
||||
private LoginApp _app;
|
||||
private const string AppKey = "670b14728ad9902aecba32e22fa4f6bd";
|
||||
|
||||
public LoginController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<LoginApp>();
|
||||
}
|
||||
// GET: Login
|
||||
public ActionResult Index()
|
||||
{
|
||||
@ -25,9 +20,9 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", username, password);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
return Redirect("/home/index?Token=" + token);
|
||||
var result = AuthUtil.Login(AppKey, username, password);
|
||||
if (result.Success)
|
||||
return Redirect("/home/index?Token=" + result.Token);
|
||||
else
|
||||
{
|
||||
var response = new BjuiResponse
|
||||
@ -57,9 +52,9 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", "System","123456");
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
return Redirect("/home/index?Token=" + token);
|
||||
var result = AuthUtil.Login(AppKey, "System","123456");
|
||||
if (result.Success)
|
||||
return Redirect("/home/index?Token=" + result.Token);
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Login");
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.WebApi.Areas.SSO.Models;
|
||||
using OpenAuth.WebApi.Areas.SSO.Models.Services;
|
||||
@ -15,8 +16,7 @@ namespace OpenAuth.WebApi.Areas.SSO.Controllers
|
||||
public class LoginController : Controller
|
||||
{
|
||||
private readonly AppInfoService _appInfoService = new AppInfoService();
|
||||
private readonly AppUserService _appUserService = new AppUserService();
|
||||
|
||||
private UserManagerApp _useraApp = AutofacExt.GetFromFac<UserManagerApp>();
|
||||
private const string AppInfo = "AppInfo";
|
||||
|
||||
//默认登录界面
|
||||
@ -77,45 +77,50 @@ namespace OpenAuth.WebApi.Areas.SSO.Controllers
|
||||
|
||||
var result = new LoginResult();
|
||||
|
||||
//获取应用信息
|
||||
var appInfo = _appInfoService.Get(model.AppKey);
|
||||
if (appInfo == null)
|
||||
try
|
||||
{
|
||||
//获取应用信息
|
||||
var appInfo = _appInfoService.Get(model.AppKey);
|
||||
if (appInfo == null)
|
||||
{
|
||||
throw new Exception("应用不存在");
|
||||
}
|
||||
TempData[AppInfo] = appInfo;
|
||||
|
||||
//获取用户信息
|
||||
var userInfo = _useraApp.Get(model.UserName);
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new Exception("用户不存在");
|
||||
}
|
||||
if (userInfo.Password != model.Password)
|
||||
{
|
||||
throw new Exception("密码错误");
|
||||
}
|
||||
|
||||
var currentSession = new UserAuthSession
|
||||
{
|
||||
UserName = model.UserName,
|
||||
Token = Guid.NewGuid().ToString().ToMd5(),
|
||||
InvalidTime = DateTime.Now.AddMinutes(10),
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = DateTime.Now,
|
||||
IpAddress = Request.UserHostAddress
|
||||
};
|
||||
|
||||
//创建Session
|
||||
new UserAuthSessionService().Create(currentSession);
|
||||
|
||||
result.Success = true;
|
||||
result.ReturnUrl = appInfo.ReturnUrl;
|
||||
result.Token = currentSession.Token;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMsg = "应用不存在";
|
||||
}
|
||||
TempData[AppInfo] = appInfo;
|
||||
|
||||
//获取用户信息
|
||||
var userInfo = _appUserService.Get(model.UserName);
|
||||
if (userInfo == null)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMsg = "用户不存在";
|
||||
result.ErrorMsg = ex.Message;
|
||||
}
|
||||
|
||||
//if (userInfo.UserPwd != model.Password.ToMd5())
|
||||
//{
|
||||
// //密码不正确
|
||||
// return View(model);
|
||||
//}
|
||||
|
||||
var currentSession = new UserAuthSession
|
||||
{
|
||||
UserName = model.UserName,
|
||||
Token = Guid.NewGuid().ToString().ToMd5(),
|
||||
InvalidTime = DateTime.Now.AddMinutes(10),
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = DateTime.Now,
|
||||
IpAddress = Request.UserHostAddress
|
||||
};
|
||||
|
||||
//创建Session
|
||||
new UserAuthSessionService().Create(currentSession);
|
||||
|
||||
result.Success = true;
|
||||
result.ReturnUrl = appInfo.ReturnUrl;
|
||||
result.Token = currentSession.Token;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace OpenAuth.WebApi.Areas.SSO.Models
|
||||
{
|
||||
public class AppUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录账号
|
||||
/// </summary>
|
||||
[Key]
|
||||
[MaxLength(50)]
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录密码
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(32)]
|
||||
public string UserPwd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 昵称
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string Nick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
[Required]
|
||||
public bool IsEnable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace OpenAuth.WebApi.Areas.SSO.Models.Services
|
||||
{
|
||||
public class AppUserService : ServiceContext
|
||||
{
|
||||
public AppUser Get(string username = "")
|
||||
{
|
||||
//模拟用户
|
||||
return new AppUser
|
||||
{
|
||||
Nick = "超级管理员",
|
||||
UserName = username,
|
||||
UserPwd = "xxxxxxxxx"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -152,11 +152,9 @@
|
||||
<Compile Include="Areas\SSO\Controllers\LoginController.cs" />
|
||||
<Compile Include="Areas\SSO\Controllers\CheckController.cs" />
|
||||
<Compile Include="Areas\SSO\Models\AppInfo.cs" />
|
||||
<Compile Include="Areas\SSO\Models\AppUser.cs" />
|
||||
<Compile Include="Areas\SSO\Models\PassportLoginRequest.cs" />
|
||||
<Compile Include="Areas\SSO\Models\ServiceContext.cs" />
|
||||
<Compile Include="Areas\SSO\Models\Services\AppInfoService.cs" />
|
||||
<Compile Include="Areas\SSO\Models\Services\AppUserService.cs" />
|
||||
<Compile Include="Areas\SSO\Models\Services\UserAuthSessionService.cs" />
|
||||
<Compile Include="Areas\SSO\Models\StringExtensions.cs" />
|
||||
<Compile Include="Areas\SSO\SSOAreaRegistration.cs" />
|
||||
|
@ -16,6 +16,9 @@ namespace OpenAuth.WebTest.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跳转到后台管理页面
|
||||
/// </summary>
|
||||
public ActionResult Admin()
|
||||
{
|
||||
return Redirect(ConfigurationManager.AppSettings["OpenAuthURL"] + "?token=" + Request.Cookies["Token"].Value);
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.WebTest.Controllers
|
||||
@ -18,12 +14,12 @@ namespace OpenAuth.WebTest.Controllers
|
||||
[HttpPost]
|
||||
public ActionResult Index(string username, string password)
|
||||
{
|
||||
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", username, password);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
return Redirect("/home/index?Token=" + token);
|
||||
var result = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", username, password);
|
||||
if (result.Success)
|
||||
return Redirect("/home/index?Token=" + result.Token);
|
||||
else
|
||||
{
|
||||
return View();
|
||||
return View(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,28 +1,39 @@
|
||||
@{
|
||||
@model OpenAuth.App.SSO.LoginResult
|
||||
|
||||
@{
|
||||
ViewBag.Title = "title";
|
||||
}
|
||||
|
||||
<h2>OpenAuth.net测试站点登陆</h2>
|
||||
<div class="col-lg-12">
|
||||
@if (Model != null && !Model.Success)
|
||||
{
|
||||
<span class="alert alert-danger">@Model.ErrorMsg</span>
|
||||
}
|
||||
</div>
|
||||
<div class="col-lg-12">
|
||||
<form class="form-horizontal" method="POST">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="username">用户名</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="username" name="username" value="admin">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">密码</label>
|
||||
<div class="controls">
|
||||
<input type="password" id="password" name="password" value="admin">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox"> Remember me
|
||||
</label>
|
||||
<button type="submit" class="btn btn-primary">登陆</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<form class="form-horizontal" method="POST">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="username">用户名</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="username" name="username" value="admin">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">密码</label>
|
||||
<div class="controls">
|
||||
<input type="password" id="password" name="password" value="admin">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox"> Remember me
|
||||
</label>
|
||||
<button type="submit" class="btn btn-primary">登陆</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user