Skip to content

Commit

Permalink
Remove identity column
Browse files Browse the repository at this point in the history
  • Loading branch information
lampo1024 committed Dec 22, 2018
1 parent 71116ce commit 44f8ab3
Show file tree
Hide file tree
Showing 46 changed files with 209 additions and 1,153 deletions.
12 changes: 7 additions & 5 deletions DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
* 版权所有,请勿删除
******************************************/

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using DncZeus.Api.Auth;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;

namespace DncZeus.Auth
namespace DncZeus.Api.Auth
{
/// <summary>
///
/// </summary>
public static class JwtBearerAuthenticationExtension
{
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion DncZeus.Api/Configurations/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using DncZeus.Api.Entities;
using DncZeus.Api.ViewModels.Rbac.DncIcon;
using DncZeus.Api.ViewModels.Rbac.DncMenu;
using DncZeus.Api.ViewModels.Rbac.DncPermission;
using DncZeus.Api.ViewModels.Rbac.DncRole;
using DncZeus.Api.ViewModels.Rbac.DncUser;
using DncZeus.ViewModel.Rbac.DncPermission;

namespace DncZeus.Api.Configurations
{
Expand Down Expand Up @@ -51,6 +51,7 @@ public MappingProfile()
.ForMember(d=>d.MenuName,s=>s.MapFrom(x=>x.Menu.Name));
CreateMap<PermissionCreateViewModel, DncPermission>();
CreateMap<PermissionEditViewModel, DncPermission>();
CreateMap<DncPermission,PermissionEditViewModel>();
#endregion
}
}
Expand Down
1 change: 0 additions & 1 deletion DncZeus.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public IActionResult Profile()
{
access = new string[] { },
avator = user.Avatar,
user_id = user.Id,
user_guid = user.Guid,
user_name = user.DisplayName,
user_type = user.UserType,
Expand Down
11 changes: 6 additions & 5 deletions DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using DncZeus.Api.Entities;
using DncZeus.Api.Entities.Enums;
using DncZeus.Api.Extensions;
using DncZeus.Api.Extensions.AuthContext;
using DncZeus.Api.Models.Response;
using DncZeus.Api.RequestPayload.Rbac.Icon;
using DncZeus.Api.ViewModels.Rbac.DncIcon;
Expand Down Expand Up @@ -124,8 +125,8 @@ public IActionResult Create(IconCreateViewModel model)
}
var entity = _mapper.Map<IconCreateViewModel, DncIcon>(model);
entity.CreatedOn = DateTime.Now;
entity.CreatedByUserId = 1;
entity.CreatedByUserName = "超级管理员";
entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
_dbContext.DncIcon.Add(entity);
_dbContext.SaveChanges();

Expand Down Expand Up @@ -180,8 +181,8 @@ public IActionResult Edit(IconCreateViewModel model)
entity.Custom = model.Custom;
entity.Size = model.Size;
entity.IsDeleted = model.IsDeleted;
entity.ModifiedByUserId = 0;
entity.ModifiedByUserName = "";
entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
entity.ModifiedOn = DateTime.Now;
entity.Status = model.Status;
entity.Description = model.Description;
Expand Down Expand Up @@ -301,7 +302,7 @@ public IActionResult Import(IconImportViewModel model)
var models = model.Icons.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(x => new DncIcon
{
Code = x.Trim(),
CreatedByUserId = 1,
CreatedByUserGuid = AuthContextService.CurrentUser.Guid,
CreatedOn = DateTime.Now,
CreatedByUserName = "超级管理员"
});
Expand Down
24 changes: 12 additions & 12 deletions DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* 版权所有,请勿删除
******************************************/

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using AutoMapper;
using DncZeus.Api.Entities;
using DncZeus.Api.Entities.Enums;
Expand All @@ -20,6 +16,10 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;

namespace DncZeus.Api.Controllers.Api.V1.Rbac
{
Expand Down Expand Up @@ -94,8 +94,8 @@ public IActionResult Create(MenuCreateViewModel model)
var entity = _mapper.Map<MenuCreateViewModel, DncMenu>(model);
entity.CreatedOn = DateTime.Now;
entity.Guid = Guid.NewGuid();
entity.CreatedByUserId = 1;
entity.CreatedByUserName = "超级管理员";
entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
_dbContext.DncMenu.Add(entity);
_dbContext.SaveChanges();
var response = ResponseModelFactory.CreateInstance;
Expand Down Expand Up @@ -127,7 +127,7 @@ public IActionResult Edit(Guid guid)
// }
//}
var tree = LoadMenuTree(model.ParentGuid.ToString());
response.SetData(new { model,tree });
response.SetData(new { model, tree });
return Ok(response);
}
}
Expand All @@ -149,13 +149,13 @@ public IActionResult Edit(MenuEditViewModel model)
entity.Level = 1;
entity.ParentGuid = model.ParentGuid;
entity.Sort = model.Sort;
entity.Url = model.Url;
entity.ModifiedByUserId = AuthContextService.CurrentUser.Id;
entity.Url = model.Url;
entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
entity.ModifiedOn = DateTime.Now;
entity.ModifiedOn = DateTime.Now;
entity.Description = model.Description;
entity.ParentName = model.ParentName;

if (!ConfigurationManager.AppSettings.IsTrialVersion)
{
entity.Alias = model.Alias;
Expand Down Expand Up @@ -296,7 +296,7 @@ private ResponseModel UpdateStatus(UserStatus status, string ids)
}
}

private List<MenuTree> LoadMenuTree(string selectedGuid=null)
private List<MenuTree> LoadMenuTree(string selectedGuid = null)
{
var temp = _dbContext.DncMenu.Where(x => x.IsDeleted == CommonEnum.IsDeleted.No && x.Status == CommonEnum.Status.Normal).ToList().Select(x => new MenuTree
{
Expand Down
20 changes: 13 additions & 7 deletions DncZeus.Api/Controllers/Api/V1/Rbac/PermissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
using DncZeus.Api.Entities;
using DncZeus.Api.Entities.QueryModels.DncPermission;
using DncZeus.Api.Extensions;
using DncZeus.Api.Extensions.AuthContext;
using DncZeus.Api.Models.Response;
using DncZeus.Api.RequestPayload.Rbac.Permission;
using DncZeus.Api.Utils;
using DncZeus.Api.ViewModels.Rbac.DncMenu;
using DncZeus.ViewModel.Rbac.DncPermission;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using DncZeus.Api.ViewModels.Rbac.DncPermission;
using static DncZeus.Api.Entities.Enums.CommonEnum;

namespace DncZeus.Api.Controllers.Api.V1.Rbac
Expand Down Expand Up @@ -113,8 +114,8 @@ public IActionResult Create(PermissionCreateViewModel model)
var entity = _mapper.Map<PermissionCreateViewModel, DncPermission>(model);
entity.CreatedOn = DateTime.Now;
entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true);
entity.CreatedByUserId = 1;
entity.CreatedByUserName = "超级管理员";
entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
_dbContext.DncPermission.Add(entity);
_dbContext.SaveChanges();

Expand Down Expand Up @@ -161,18 +162,23 @@ public IActionResult Edit(PermissionEditViewModel model)
}
using (_dbContext)
{
if (_dbContext.DncPermission.Count(x => x.ActionCode == model.ActionCode && x.Id != model.Id) > 0)
if (_dbContext.DncPermission.Count(x => x.ActionCode == model.ActionCode && x.Code != model.Code) > 0)
{
response.SetFailed("权限操作码已存在");
return Ok(response);
}
var entity = _dbContext.DncPermission.FirstOrDefault(x => x.Id == model.Id);
var entity = _dbContext.DncPermission.FirstOrDefault(x => x.Code == model.Code);
if (entity == null)
{
response.SetFailed("权限不存在");
return Ok(response);
}
entity.Name = model.Name;
entity.ActionCode = model.ActionCode;
entity.MenuGuid = model.MenuGuid;
entity.IsDeleted = model.IsDeleted;
entity.ModifiedByUserId = 0;
entity.ModifiedByUserName = "";
entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
entity.ModifiedOn = DateTime.Now;
entity.Status = model.Status;
entity.Description = model.Description;
Expand Down
8 changes: 5 additions & 3 deletions DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public IActionResult Create(RoleCreateViewModel model)
var entity = _mapper.Map<RoleCreateViewModel, DncRole>(model);
entity.CreatedOn = DateTime.Now;
entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true);
entity.CreatedByUserId = 1;
entity.CreatedByUserName = "超级管理员";
entity.IsSuperAdministrator = false;
entity.IsBuiltin = false;
entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
_dbContext.DncRole.Add(entity);
_dbContext.SaveChanges();

Expand Down Expand Up @@ -163,7 +165,7 @@ public IActionResult Edit(RoleCreateViewModel model)

entity.Name = model.Name;
entity.IsDeleted = model.IsDeleted;
entity.ModifiedByUserId = AuthContextService.CurrentUser.Id;
entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
entity.ModifiedOn = DateTime.Now;
entity.Status = model.Status;
Expand Down
7 changes: 6 additions & 1 deletion DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ public IActionResult Edit(UserCreateViewModel model)
using (_dbContext)
{
var entity = _dbContext.DncUser.FirstOrDefault(x => x.Guid == model.Guid);
if (entity == null)
{
response.SetFailed("用户不存在");
return Ok(response);
}
entity.DisplayName = model.DisplayName;
entity.IsDeleted = model.IsDeleted;
entity.IsLocked = model.IsLocked;
entity.ModifiedByUserId = AuthContextService.CurrentUser.Id;
entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
entity.ModifiedOn = DateTime.Now;
entity.Password = model.Password;
Expand Down
3 changes: 1 addition & 2 deletions DncZeus.Api/Controllers/OauthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 版权所有,请勿删除
******************************************/

using DncZeus.Auth;
using DncZeus.Api.Entities;
using DncZeus.Api.Extensions;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -74,7 +73,7 @@ public IActionResult Auth(string username, string password)
var claimsIdentity = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, username),
new Claim("id",user.Id.ToString()),
new Claim("guid",user.Guid.ToString()),
new Claim("avatar",""),
new Claim("displayName",user.DisplayName),
new Claim("loginName",user.LoginName),
Expand Down
15 changes: 11 additions & 4 deletions DncZeus.Api/DncZeus.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
<OutputPath></OutputPath>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations\" />
<Folder Include="wwwroot\css\" />
<Folder Include="wwwroot\js\" />
<Folder Include="wwwroot\images\" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions DncZeus.Api/Entities/AuditEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public abstract class AuditEntity
[Column(Order = 100)]
public DateTime CreatedOn { get; set; }
[Column(Order = 101)]
public int CreatedByUserId { get; set; }
public Guid? CreatedByUserGuid { get; set; }
[Column(Order = 102)]
public string CreatedByUserName { get; set; }
[Column(Order = 103)]
public DateTime? ModifiedOn { get; set; }
[Column(Order = 104)]
public int ModifiedByUserId { get; set; }
public Guid? ModifiedByUserGuid { get; set; }
[Column(Order = 105)]
public string ModifiedByUserName { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions DncZeus.Api/Entities/DncIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class DncIcon
/// <summary>
///
/// </summary>
public int CreatedByUserId { get; set; }
public Guid CreatedByUserGuid { get; set; }
/// <summary>
///
/// </summary>
Expand All @@ -75,7 +75,7 @@ public class DncIcon
/// <summary>
///
/// </summary>
public int ModifiedByUserId { get; set; }
public Guid? ModifiedByUserGuid { get; set; }
/// <summary>
///
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions DncZeus.Api/Entities/DncMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class DncMenu
/// <summary>
/// 创建者ID
/// </summary>
public int CreatedByUserId { get; set; }
public Guid CreatedByUserGuid { get; set; }
/// <summary>
/// 创建者姓名
/// </summary>
Expand All @@ -98,7 +98,7 @@ public class DncMenu
/// <summary>
/// 最近修改者ID
/// </summary>
public int ModifiedByUserId { get; set; }
public Guid? ModifiedByUserGuid { get; set; }
/// <summary>
/// 最近修改者姓名
/// </summary>
Expand Down
14 changes: 8 additions & 6 deletions DncZeus.Api/Entities/DncPermission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public DncPermission()
/// </summary>
public PermissionType Type { get; set; }
/// <summary>
/// 创建时间
/// 创建者ID
/// </summary>
public DateTime CreatedOn { get; set; }
public Guid CreatedByUserGuid { get; set; }
/// <summary>
/// 创建者ID
/// 创建时间
/// </summary>
public int CreatedByUserId { get; set; }
public DateTime CreatedOn { get; set; }
/// <summary>
/// 创建者姓名
/// </summary>
Expand All @@ -88,9 +88,9 @@ public DncPermission()
/// <summary>
/// 最近修改者ID
/// </summary>
public int ModifiedByUserId { get; set; }
public Guid? ModifiedByUserGuid { get; set; }
/// <summary>
/// 最近修改者
/// 最近修改者姓名
/// </summary>
public string ModifiedByUserName { get; set; }

Expand All @@ -102,5 +102,7 @@ public DncPermission()
/// 权限所属的角色集合
/// </summary>
public ICollection<DncRolePermissionMapping> Roles { get; set; }


}
}
Loading

0 comments on commit 44f8ab3

Please sign in to comment.