OpenAuth.Net/OpenAuth.App/LoginApp.cs

61 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Linq;
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
{
private AuthoriseService _service;
2015-09-22 23:10:00 +08:00
public LoginApp(AuthoriseService service)
2015-09-22 23:10:00 +08:00
{
_service = service;
2015-09-22 23:10:00 +08:00
}
public void Login(string userName, string password)
2015-09-22 23:10:00 +08:00
{
_service.Check(userName, password);
FormsAuthentication.SetAuthCookie(userName, true);
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>
public void LoginByDev()
{
_service.SetSysUser();
FormsAuthentication.SetAuthCookie("System", true);
}
public LoginUserVM GetLoginUser()
2015-12-01 17:30:24 +08:00
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
throw new Exception("未登录");
}
string username = HttpContext.Current.User.Identity.Name;
_service.GetUserAccessed(username);
var user = new LoginUserVM
2015-12-01 17:30:24 +08:00
{
User = _service.User,
AccessedOrgs = _service.Orgs,
Modules = _service.Modules.MapToList<ModuleView>(),
Resources = _service.Resources,
2015-12-01 17:30:24 +08:00
};
foreach (var moduleView in user.Modules)
2015-12-04 00:14:55 +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
return user;
2015-09-22 23:10:00 +08:00
}
}
2015-04-25 12:31:01 +08:00
}