mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-18 17:48:01 +08:00
主页加载菜单按钮
重新修改了登陆逻辑
This commit is contained in:
12
OpenAuth.App/DTO/MenuForUserRequest.cs
Normal file
12
OpenAuth.App/DTO/MenuForUserRequest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenAuth.App.DTO
|
||||
{
|
||||
public class MenuForUserRequest
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
}
|
15
OpenAuth.App/DTO/MenuForUserResponse.cs
Normal file
15
OpenAuth.App/DTO/MenuForUserResponse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.App.DTO
|
||||
{
|
||||
public class MenuForUserResponse
|
||||
{
|
||||
private IList<Menu> _menus = new List<Menu>();
|
||||
|
||||
public IList<Menu> Menus
|
||||
{
|
||||
get { return _menus; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using OpenAuth.App.DTO;
|
||||
@@ -10,37 +11,27 @@ namespace OpenAuth.App
|
||||
{
|
||||
private LoginService _loginService;
|
||||
|
||||
public LoginApp(IUserRepository repository)
|
||||
public LoginApp(LoginService service)
|
||||
{
|
||||
_loginService = new LoginService(repository);
|
||||
_loginService = service;
|
||||
}
|
||||
|
||||
public LoginResponse Login(LoginRequest request)
|
||||
{
|
||||
var resp = new LoginResponse {UserName = request.UserName};
|
||||
|
||||
var user = _loginService.Login(request.UserName, request.Password);
|
||||
if (user == null)
|
||||
try
|
||||
{
|
||||
resp.Message = "<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
}
|
||||
else if (!user.Password.Equals(request.Password))
|
||||
{
|
||||
resp.Message = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
}
|
||||
else if (!user.Enabled)
|
||||
{
|
||||
resp.Message = "<22><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
}
|
||||
else
|
||||
{
|
||||
resp.UserId = user.UserId;
|
||||
var user = _loginService.Login(request.UserName, request.Password);
|
||||
resp.UserId = user.Id;
|
||||
resp.Success = true;
|
||||
foreach (var role in user.Roles)
|
||||
{
|
||||
resp.UserRoleNames.Add(role.FullName);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resp.Success = false;
|
||||
resp.Message = ex.Message;
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
26
OpenAuth.App/LoginCacheApp.cs
Normal file
26
OpenAuth.App/LoginCacheApp.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Web;
|
||||
|
||||
using OpenAuth.App.DTO;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class LoginCacheApp
|
||||
{
|
||||
public static LoginResponse GetLogin()
|
||||
{
|
||||
var session = HttpContext.Current.Session;
|
||||
return session["Login"] as LoginResponse;
|
||||
}
|
||||
|
||||
public static void SetLogin(LoginResponse loginresp)
|
||||
{
|
||||
var session = HttpContext.Current.Session;
|
||||
var login = session["Login"] as LoginResponse;
|
||||
if (login != null && login.UserId == loginresp.UserId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
session["Login"] = loginresp;
|
||||
}
|
||||
}
|
||||
}
|
39
OpenAuth.App/MenuApp.cs
Normal file
39
OpenAuth.App/MenuApp.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 05-19-2015
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 05-20-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="MenuApp.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>菜单服务</summary>
|
||||
// ***********************************************************************
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.App.DTO;
|
||||
using OpenAuth.Domain.Model;
|
||||
using OpenAuth.Domain.Service;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class MenuApp
|
||||
{
|
||||
private MenuService _menuService;
|
||||
|
||||
public MenuApp(MenuService service)
|
||||
{
|
||||
_menuService = service;
|
||||
}
|
||||
public MenuForUserResponse LoadFor(MenuForUserRequest request)
|
||||
{
|
||||
var response = new MenuForUserResponse();
|
||||
foreach (var menu in _menuService.GetMenuFor(request.UserId))
|
||||
{
|
||||
response.Menus.Add(menu);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,6 +32,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -41,7 +42,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DTO\LoginRequest.cs" />
|
||||
<Compile Include="DTO\LoginResponse.cs" />
|
||||
<Compile Include="DTO\MenuForUserRequest.cs" />
|
||||
<Compile Include="DTO\MenuForUserResponse.cs" />
|
||||
<Compile Include="LoginApp.cs" />
|
||||
<Compile Include="LoginCacheApp.cs" />
|
||||
<Compile Include="MenuApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="DTO\Response.cs" />
|
||||
</ItemGroup>
|
||||
|
Reference in New Issue
Block a user