1
This commit is contained in:
parent
1368e68b1b
commit
3ad96bcce9
@ -13,6 +13,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using static asg_form.Controllers.Budget.BgCountController;
|
||||
using static asg_form.Controllers.InviteReferee;
|
||||
using static asg_form.Controllers.login;
|
||||
using static asg_form.Controllers.menuAssignController;
|
||||
|
||||
namespace asg_form.Controllers
|
||||
@ -287,6 +288,7 @@ namespace asg_form.Controllers
|
||||
|
||||
public DbSet<InviteBg> T_Invitation { get; set; }
|
||||
public DbSet<menuDB> mainMenu { get; set; }
|
||||
public DbSet<capData> T_captcha_check { get; set; }
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
|
||||
|
@ -261,8 +261,8 @@ namespace asg_form.Controllers
|
||||
else
|
||||
{
|
||||
|
||||
a.cout = userManager.Users.Where(a => a.chinaname == keyword || a.UserName == keyword || a.Email == keyword).Count();
|
||||
a.msg = await userManager.Users.Where(a => a.chinaname == keyword || a.UserName == keyword || a.Email == keyword).Paginate(pageindex, pagesize).Select(a => new { a.Id, a.Email, a.chinaname, a.UserName, a.Integral, a.officium,a.qqnumber, a.roleListName, a.roleListCode }).ToListAsync();
|
||||
a.cout = userManager.Users.Where(a => a.chinaname.Contains(keyword) || a.UserName == keyword || a.Email == keyword).Count();
|
||||
a.msg = await userManager.Users.Where(a => a.chinaname.Contains(keyword) || a.UserName == keyword || a.Email == keyword).Paginate(pageindex, pagesize).Select(a => new { a.Id, a.Email, a.chinaname, a.UserName, a.Integral, a.officium,a.qqnumber, a.roleListName, a.roleListCode }).ToListAsync();
|
||||
}
|
||||
return Ok(a);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ using System.Security.Authentication;
|
||||
using Flurl.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.CodeDom.Compiler;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
using Manganese.Array;
|
||||
|
||||
namespace asg_form.Controllers
|
||||
{
|
||||
@ -220,25 +222,71 @@ namespace asg_form.Controllers
|
||||
|
||||
public string captchaNow = "7777";
|
||||
|
||||
public class capData
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string? captcha_alphabet { get; set; }
|
||||
public int? captcha_number { get; set; }
|
||||
public string off_time { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证码生成
|
||||
/// </summary>
|
||||
[Route("api/v2/makeCaptcha")]
|
||||
[HttpGet]
|
||||
public ActionResult<(string captchaImage, string captchaCode)> GetCaptcha()
|
||||
public async Task<ActionResult<(string captchaImage, string captchaCode)> >GetCaptcha()
|
||||
{
|
||||
var captchaService = new CaptchaService();
|
||||
var (captchaImage, captchaCode) = captchaService.GenerateCaptcha();
|
||||
try
|
||||
{
|
||||
var captchaService = new CaptchaService();
|
||||
var (captchaImage, captchaCode) = captchaService.GenerateCaptcha();
|
||||
captchaNow=captchaCode;
|
||||
var offTime = new DateTime();
|
||||
using (var db = new TestDbContext())
|
||||
{
|
||||
var query = db.T_captcha_check.AsQueryable();
|
||||
var currentDateTime = DateTime.Now;
|
||||
var fiveMinutesAgo = currentDateTime.AddMinutes(-5);
|
||||
var recordsToDelete = db.T_captcha_check
|
||||
.Where(x => DateTime.TryParse(x.off_time,out offTime) && offTime < fiveMinutesAgo)
|
||||
.ToList();
|
||||
db.T_captcha_check.RemoveRange(recordsToDelete);
|
||||
int maxId = query.Max(n => n.id);
|
||||
var msg = new capData
|
||||
{
|
||||
id = maxId + 1,
|
||||
captcha_alphabet = captchaCode,
|
||||
off_time = DateTime.Now.ToString(),
|
||||
};
|
||||
db.Add(msg);
|
||||
db.SaveChanges();
|
||||
}
|
||||
return Ok(new { captchaImage });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Ok(new { code = 500, message = "服务器错误", ex });
|
||||
}
|
||||
|
||||
captchaNow=captchaCode;
|
||||
|
||||
return Ok(new { captchaImage, captchaCode });
|
||||
}
|
||||
|
||||
// 验证用户输入的验证码
|
||||
public bool ValidateCaptcha(string userInput)
|
||||
{
|
||||
return userInput.Equals(captchaNow, StringComparison.OrdinalIgnoreCase);
|
||||
using (var db = new TestDbContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = db.T_captcha_check.AsQueryable();
|
||||
var msg = query.FirstOrDefault(n => n.captcha_alphabet == userInput);
|
||||
bool isVali = (msg != null);
|
||||
if(isVali) db.T_captcha_check.Remove(msg);
|
||||
return isVali;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -253,7 +301,7 @@ namespace asg_form.Controllers
|
||||
try
|
||||
{
|
||||
bool isCaptchaValid = ValidateCaptcha(newuser.captcha);
|
||||
if (captchaNow == "7777") return BadRequest(new { code = 400, message = "服务器正忙" });
|
||||
if (captchaNow == "7777") return BadRequest(new { code = 503, message = "服务器正忙" });
|
||||
if (!isCaptchaValid)
|
||||
{
|
||||
captchaNow = "7777";
|
||||
|
@ -21,6 +21,7 @@ namespace asg_form.Controllers
|
||||
public string component { get; set; }
|
||||
public string allow_operate { get; set; }
|
||||
public string show { get; set; }
|
||||
public int sort { get; set; }
|
||||
}
|
||||
public class menuInput
|
||||
{
|
||||
@ -33,6 +34,7 @@ namespace asg_form.Controllers
|
||||
public string component { get; set; }
|
||||
public string allowOperate { get; set; }
|
||||
public string show { get; set; }
|
||||
public int sort { get; set; }
|
||||
}
|
||||
|
||||
private readonly UserManager<User> userManager;
|
||||
@ -67,6 +69,8 @@ namespace asg_form.Controllers
|
||||
component = msg.component,
|
||||
allow_operate = msg.allowOperate,
|
||||
show = msg.show,
|
||||
sort = msg.sort,
|
||||
|
||||
};
|
||||
db.mainMenu.Add(menu);
|
||||
db.SaveChanges();
|
||||
@ -82,6 +86,7 @@ namespace asg_form.Controllers
|
||||
mA.component = msg.component;
|
||||
mA.allow_operate = msg.allowOperate;
|
||||
mA.show = msg.show;
|
||||
mA.sort = msg.sort;
|
||||
db.SaveChanges();
|
||||
}
|
||||
return Ok(new error_mb { code = 200, message = "成功存入" });
|
||||
@ -109,8 +114,10 @@ namespace asg_form.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
db.Remove(db.mainMenu.FirstOrDefaultAsync(n => n.id==uid));
|
||||
await db.SaveChangesAsync();
|
||||
var menumessage = db.mainMenu.FirstOrDefault(n => n.id == uid);
|
||||
if (menumessage != null) db.Remove(menumessage);
|
||||
else return Ok(new error_mb { code = 400, message = "数据不存在" });
|
||||
db.SaveChanges();
|
||||
return Ok(new error_mb { code = 200, message = "成功删除" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -130,27 +137,39 @@ namespace asg_form.Controllers
|
||||
public string component { get; set; }
|
||||
public string allowOperate { get; set; }
|
||||
public string show { get; set; }
|
||||
public int sort { get; set; } = 1;
|
||||
public List<menuFront> children { get; set; } = new List<menuFront>();
|
||||
}
|
||||
|
||||
private List<menuFront> BuildTree(IEnumerable<menuDB> nodes, string? parentId)
|
||||
{
|
||||
return nodes.Where(x => x.parent_id == parentId)
|
||||
.Select(x => new menuFront
|
||||
{
|
||||
id = x.id,
|
||||
path = x.path,
|
||||
iconClass = x.icon_class,
|
||||
title = x.title,
|
||||
parentId = x.parent_id,
|
||||
auth = x.auth,
|
||||
component = x.component,
|
||||
allowOperate = x.allow_operate,
|
||||
show = x.show,
|
||||
children = BuildTree(nodes, x.id)
|
||||
}).ToList();
|
||||
try
|
||||
{
|
||||
return nodes.Where(x => x.parent_id == parentId)
|
||||
.OrderBy(x => x.sort)
|
||||
.Select(x => new menuFront
|
||||
{
|
||||
id = x.id,
|
||||
path = x.path,
|
||||
iconClass = x.icon_class,
|
||||
title = x.title,
|
||||
parentId = x.parent_id,
|
||||
auth = x.auth,
|
||||
component = x.component,
|
||||
allowOperate = x.allow_operate,
|
||||
show = x.show,
|
||||
sort = x.sort,
|
||||
children = BuildTree(nodes, x.id)
|
||||
}).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error in BuildTree: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询菜单
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user