2016-04-21 10:54:05 +08:00
|
|
|
|
using System;
|
2016-01-07 11:47:43 +08:00
|
|
|
|
using System.Linq;
|
2016-04-21 10:54:05 +08:00
|
|
|
|
using System.Web;
|
|
|
|
|
using Infrastructure;
|
|
|
|
|
using OpenAuth.App.ViewModel;
|
|
|
|
|
using System.Web.Security;
|
|
|
|
|
using OpenAuth.Domain.Service;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.App
|
|
|
|
|
{
|
|
|
|
|
public class LoginApp
|
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
private AuthoriseService _service;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
|
2016-04-21 10:54:05 +08:00
|
|
|
|
public LoginApp(AuthoriseService service)
|
2015-09-22 23:10:00 +08:00
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
_service = service;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 10:54:05 +08:00
|
|
|
|
public void Login(string userName, string password)
|
2015-09-22 23:10:00 +08:00
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
_service.Check(userName, password);
|
|
|
|
|
FormsAuthentication.SetAuthCookie(userName, true);
|
2016-01-07 11:47:43 +08:00
|
|
|
|
|
2015-12-01 17:30:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-01-02 23:16:22 +08:00
|
|
|
|
/// 开发者登陆
|
2015-12-01 17:30:24 +08:00
|
|
|
|
/// </summary>
|
2016-04-21 10:54:05 +08:00
|
|
|
|
public void LoginByDev()
|
|
|
|
|
{
|
|
|
|
|
_service.SetSysUser();
|
|
|
|
|
FormsAuthentication.SetAuthCookie("System", true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LoginUserVM GetLoginUser()
|
2015-12-01 17:30:24 +08:00
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
if (!HttpContext.Current.User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
2016-04-25 11:53:21 +08:00
|
|
|
|
throw new HttpException(401,"未登录");
|
2016-04-21 10:54:05 +08:00
|
|
|
|
}
|
|
|
|
|
string username = HttpContext.Current.User.Identity.Name;
|
|
|
|
|
_service.GetUserAccessed(username);
|
|
|
|
|
var user = new LoginUserVM
|
2015-12-01 17:30:24 +08:00
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
User = _service.User,
|
|
|
|
|
AccessedOrgs = _service.Orgs,
|
|
|
|
|
Modules = _service.Modules.MapToList<ModuleView>(),
|
|
|
|
|
Resources = _service.Resources,
|
2015-12-01 17:30:24 +08:00
|
|
|
|
};
|
2016-04-21 10:54:05 +08:00
|
|
|
|
|
|
|
|
|
foreach (var moduleView in user.Modules)
|
2015-12-04 00:14:55 +08:00
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
moduleView.Elements = _service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList();
|
2015-12-04 00:14:55 +08:00
|
|
|
|
}
|
2015-12-22 11:55:54 +08:00
|
|
|
|
|
2016-04-21 10:54:05 +08:00
|
|
|
|
return user;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-25 12:31:01 +08:00
|
|
|
|
}
|