1
This commit is contained in:
parent
e5707148d1
commit
f03c17173b
@ -13,6 +13,7 @@ using System.Security.Cryptography;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using static asg_form.Controllers.Budget.BgCountController;
|
using static asg_form.Controllers.Budget.BgCountController;
|
||||||
using static asg_form.Controllers.InviteReferee;
|
using static asg_form.Controllers.InviteReferee;
|
||||||
|
using static asg_form.Controllers.menuAssignController;
|
||||||
|
|
||||||
namespace asg_form.Controllers
|
namespace asg_form.Controllers
|
||||||
{
|
{
|
||||||
@ -285,6 +286,7 @@ namespace asg_form.Controllers
|
|||||||
public DbSet<BgDB> budgetDetails { get; set; }
|
public DbSet<BgDB> budgetDetails { get; set; }
|
||||||
|
|
||||||
public DbSet<InviteBg> T_Invitation { get; set; }
|
public DbSet<InviteBg> T_Invitation { get; set; }
|
||||||
|
public DbSet<menuDB> mainMenu { get; set; }
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
|
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
|
||||||
|
@ -29,6 +29,7 @@ using Flandre.Core.Common;
|
|||||||
using Flandre.Core.Messaging;
|
using Flandre.Core.Messaging;
|
||||||
using Mirai.Net.Data.Messages.Concretes;
|
using Mirai.Net.Data.Messages.Concretes;
|
||||||
using Flandre.Core.Messaging.Segments;
|
using Flandre.Core.Messaging.Segments;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace asg_form.Controllers
|
namespace asg_form.Controllers
|
||||||
{
|
{
|
||||||
@ -308,8 +309,41 @@ namespace asg_form.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置用户权限口
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/v1/admin/setRight")]
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<object>> opRight(userRights msg)
|
||||||
|
{
|
||||||
|
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin"))
|
||||||
|
{
|
||||||
|
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||||
|
}
|
||||||
|
using (var db = new TestDbContext())
|
||||||
|
{
|
||||||
|
var user = await userManager.FindByIdAsync(msg.userId);
|
||||||
|
if (user == null) { return BadRequest(new error_mb { code = 404, message = "用户未找到" }); }
|
||||||
|
try
|
||||||
|
{
|
||||||
|
user.roleListCode = msg.roleListCode;
|
||||||
|
user.roleListName = msg.roleListName;
|
||||||
|
await userManager.UpdateAsync(user);
|
||||||
|
return Ok(new { code = 200, message = "成功存入" ,msg});
|
||||||
|
}catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class userRights
|
||||||
|
{
|
||||||
|
public string userId { get; set; }
|
||||||
|
public string? roleListCode { get; set; }
|
||||||
|
public string? roleListName { get; set; }
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置管理员,需要superadmin
|
/// 设置管理员,需要superadmin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,7 +1,122 @@
|
|||||||
namespace asg_form.Controllers
|
using Microsoft.AspNetCore.Authorization;
|
||||||
{
|
using Microsoft.AspNetCore.Identity;
|
||||||
public class menuAssignController
|
using Microsoft.AspNetCore.Mvc;
|
||||||
{
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using static asg_form.Controllers.InviteReferee;
|
||||||
|
|
||||||
|
namespace asg_form.Controllers
|
||||||
|
{
|
||||||
|
public class menuAssignController : ControllerBase
|
||||||
|
{
|
||||||
|
public class menuDB
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public string icon_class { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string parent_id { get; set; }
|
||||||
|
public string auth { get; set; }
|
||||||
|
public string component { get; set; }
|
||||||
|
public string allow_operate { get; set; }
|
||||||
|
public string show { get; set; }
|
||||||
|
}
|
||||||
|
public class menuInput
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public string iconClass { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string parentId { get; set; }
|
||||||
|
public string auth { get; set; }
|
||||||
|
public string component { get; set; }
|
||||||
|
public string allowOperate { get; set; }
|
||||||
|
public string show { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly UserManager<User> userManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增菜单
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/v1/admin/menuAdd")]
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<object>> menuAdd([FromBody] menuInput msg)
|
||||||
|
{
|
||||||
|
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin"))
|
||||||
|
{
|
||||||
|
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||||
|
}
|
||||||
|
using (var db = new TestDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mA = db.mainMenu.Find(msg.id);
|
||||||
|
if (mA == null)
|
||||||
|
{
|
||||||
|
var menu = new menuDB
|
||||||
|
{
|
||||||
|
id = msg.id,
|
||||||
|
path = msg.path,
|
||||||
|
icon_class = msg.iconClass,
|
||||||
|
title = msg.title,
|
||||||
|
parent_id = msg.parentId,
|
||||||
|
auth = msg.auth,
|
||||||
|
component = msg.component,
|
||||||
|
allow_operate = msg.allowOperate,
|
||||||
|
show = msg.show,
|
||||||
|
};
|
||||||
|
db.mainMenu.Add(menu);
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mA.id = msg.id;
|
||||||
|
mA.path = msg.path;
|
||||||
|
mA.icon_class = msg.iconClass;
|
||||||
|
mA.title = msg.title;
|
||||||
|
mA.parent_id = msg.parentId;
|
||||||
|
mA.auth = msg.auth;
|
||||||
|
mA.component = msg.component;
|
||||||
|
mA.allow_operate = msg.allowOperate;
|
||||||
|
mA.show = msg.show;
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
return Ok(new error_mb { code = 200, message = "成功存入" });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除菜单
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/v1/admin/menuDel")]
|
||||||
|
[HttpDelete]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<object>> menuDel([FromQuery] string uid)
|
||||||
|
{
|
||||||
|
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin"))
|
||||||
|
{
|
||||||
|
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||||
|
}
|
||||||
|
using (var db = new TestDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
db.Remove(db.mainMenu.FirstOrDefaultAsync(n => n.id==uid));
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return Ok(new error_mb { code = 200, message = "成功删除" });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user