2022 jphd-3dprint
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
e0115e0e07
commit
772525a9b6
|
|
@ -7,20 +7,52 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace _2021_backend.Controllers
|
namespace _2021_backend.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/submit")]
|
|
||||||
|
|
||||||
|
[Route("api")]
|
||||||
public class SubmissionController : Controller
|
public class SubmissionController : Controller
|
||||||
{
|
{
|
||||||
public BackendContext Context;
|
|
||||||
|
public BackendContext context;
|
||||||
|
|
||||||
public SubmissionController(BackendContext context)
|
public SubmissionController(BackendContext context)
|
||||||
{
|
{
|
||||||
Context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
[HttpPost]
|
|
||||||
public async Task<IActionResult> Post([FromForm] string dto)
|
[HttpPost("checkCaptcha")]
|
||||||
|
public async Task<IActionResult> CheckCaptcha([FromQuery] string stuid, [FromQuery] string captcha)
|
||||||
|
{
|
||||||
|
var stu = context.Students.FirstOrDefault(e => e.Stuid == stuid);
|
||||||
|
if (stu == null) return Ok(ApiResponse.Error("INVALID_STUID"));
|
||||||
|
else if (captcha == stu.LastCaptcha)
|
||||||
|
{
|
||||||
|
if (DateTime.Now - stu.LastCaptchaTime > TimeSpan.FromMinutes(15)) return Ok(ApiResponse.Error("CAPTCHA_TIMEOUT"));
|
||||||
|
return Ok(ApiResponse.Success("success"));
|
||||||
|
}
|
||||||
|
else return Ok(ApiResponse.Error("INVALID_CAPTCHA"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost("getCaptcha")]
|
||||||
|
public async Task<IActionResult> GetCaptcha([FromQuery] string stuid)
|
||||||
|
{
|
||||||
|
|
||||||
|
var stu = context.Students.FirstOrDefault(e => e.Stuid == stuid);
|
||||||
|
if (stu == null) return Ok(ApiResponse.Error("INVALID_STUID"));
|
||||||
|
else if (DateTime.Now - stu.LastCaptchaTime < TimeSpan.FromMinutes(1)) return Ok(ApiResponse.Error("ALREADY_SENT"));
|
||||||
|
var result = await TencentSMS.Send(context, SMSType.Captcha, stu, "smsbot");
|
||||||
|
if (!result) return Ok(ApiResponse.Error("SEND_ERROR"));
|
||||||
|
return Ok(ApiResponse.Success("success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost("submit")]
|
||||||
|
public async Task<IActionResult> PostSubmit([FromForm] string dto)
|
||||||
{
|
{
|
||||||
var aDto = JsonSerializer.Deserialize<SubmissionDto>(dto);
|
var aDto = JsonSerializer.Deserialize<SubmissionDto>(dto);
|
||||||
string ip = Request.Headers["X-Real-IP"].FirstOrDefault();
|
string ip = Request.Headers["X-Real-IP"].FirstOrDefault();
|
||||||
|
|
@ -29,48 +61,47 @@ namespace _2021_backend.Controllers
|
||||||
if (aDto.Check() == false)
|
if (aDto.Check() == false)
|
||||||
return StatusCode(400, ApiResponse.Error("TICKET_NOT_LEGEAL"));
|
return StatusCode(400, ApiResponse.Error("TICKET_NOT_LEGEAL"));
|
||||||
Submission sub = new Submission(aDto, ip);
|
Submission sub = new Submission(aDto, ip);
|
||||||
foreach (var tm in Context.Sessions)
|
foreach (var tm in context.Sessions)
|
||||||
{
|
{
|
||||||
if(aDto.Timelist != null)if (aDto.Timelist.Any(it => it.Day.Day == tm.Day.Day && it.BeginTime.TimeOfDay == tm.BeginTime.TimeOfDay))
|
if(aDto.Timelist != null)if (aDto.Timelist.Any(it => it.Day.Day == tm.Day.Day && it.BeginTime.TimeOfDay == tm.BeginTime.TimeOfDay))
|
||||||
{
|
{
|
||||||
sub.Timelist.Add(tm.Id);
|
sub.Timelist.Add(tm.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var q = Context.Students.Where(stu => (stu.Name == aDto.Name || stu.Stuid == aDto.Stuid));
|
var q = context.Students.Where(stu => (stu.Name == aDto.Name || stu.Stuid == aDto.Stuid));
|
||||||
Student stu;
|
Student stu;
|
||||||
if (q.Count() == 0)
|
if (q.Count() == 0)
|
||||||
{
|
{
|
||||||
stu = Student.create(sub);
|
stu = Student.create(sub);
|
||||||
stu.Status = status.刚报名;
|
stu.Status = status.刚报名;
|
||||||
Context.Students.Add(stu);
|
context.Students.Add(stu);
|
||||||
|
context.SaveChanges();
|
||||||
|
sub.Host = stu.Id;
|
||||||
|
context.Submissions.Add(sub);
|
||||||
|
context.SaveChanges();
|
||||||
|
stu.Submissions.Add(sub.Id);
|
||||||
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stu = q.FirstOrDefault();
|
stu = q.FirstOrDefault();
|
||||||
|
sub.Host = stu.Id;
|
||||||
|
context.Submissions.Add(sub);
|
||||||
|
context.SaveChanges();
|
||||||
stu.Update(sub);
|
stu.Update(sub);
|
||||||
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
sub.Host = stu.Id;
|
|
||||||
Context.Submissions.Add(sub);
|
await TencentSMS.Send(context, SMSType.Signed, stu, _2021_backend.Models.User.Bot.stuID);
|
||||||
Context.SaveChanges();
|
|
||||||
await TencentSMS.Send(Context, SMSType.Signed, stu, _2021_backend.Models.User.Bot.stuID);
|
|
||||||
return Ok(ApiResponse.Success("success"));
|
return Ok(ApiResponse.Success("success"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/sessionlist")]
|
|
||||||
public class SessionlistContoller : Controller
|
|
||||||
{
|
|
||||||
private readonly BackendContext _context;
|
|
||||||
public SessionlistContoller(BackendContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
[HttpGet]
|
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("sessionlist")]
|
||||||
public IActionResult GetSessions()
|
public IActionResult GetSessions()
|
||||||
{
|
{
|
||||||
var query = _context.Sessions.OrderBy(r => r.Day).ThenBy(r => r.BeginTime).ThenBy(r => r.Place).Where(e => e.Capacity > e.Students.Count).Select(r => new SessionDto
|
var query = context.Sessions.OrderBy(r => r.Day).ThenBy(r => r.BeginTime).ThenBy(r => r.Place).Where(e => e.Capacity > e.Students.Count).Select(r => new SessionDto
|
||||||
{
|
{
|
||||||
BeginTime = r.BeginTime,
|
BeginTime = r.BeginTime,
|
||||||
Day = r.Day,
|
Day = r.Day,
|
||||||
|
|
@ -78,22 +109,76 @@ namespace _2021_backend.Controllers
|
||||||
return Ok(ApiResponse.Success(query.ToList().FindAll(it => it.Day.Add(it.BeginTime.TimeOfDay).CompareTo(DateTime.Now) > 0).Distinct(new SessionDtoComparer()).ToList()));
|
return Ok(ApiResponse.Success(query.ToList().FindAll(it => it.Day.Add(it.BeginTime.TimeOfDay).CompareTo(DateTime.Now) > 0).Distinct(new SessionDtoComparer()).ToList()));
|
||||||
//return Ok(ApiResponse.Success("报名结束了"));
|
//return Ok(ApiResponse.Success("报名结束了"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/postsession")]
|
|
||||||
public class PostsessionController : Controller
|
[HttpGet("fileinfo")]
|
||||||
{
|
public async Task<IActionResult> GetInfo([FromQuery] string? stuid)
|
||||||
private readonly BackendContext Context;
|
|
||||||
public PostsessionController(BackendContext context)
|
|
||||||
{
|
{
|
||||||
Context = context;
|
if (stuid == null || (!context.Students.Any(e => e.Stuid == stuid)))
|
||||||
}
|
{
|
||||||
[HttpPost]
|
return Ok(ApiResponse.Error("INVALID_STUID"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var student = context.Students.FirstOrDefault(e => e.Stuid == stuid.ToString());
|
||||||
|
if (student.Uploads == null)
|
||||||
|
{
|
||||||
|
student.Uploads = new List<int> { };
|
||||||
|
context.SaveChangesAsync();
|
||||||
|
return Ok(ApiResponse.Error("NO_FILES"));
|
||||||
|
|
||||||
|
}
|
||||||
|
var fileIdx = student.Uploads.Last();
|
||||||
|
var file = context.FileDesc.Find(fileIdx);
|
||||||
|
var oldNameSplit = file.Name.Split(".");
|
||||||
|
var oldName = "";
|
||||||
|
var oldNameExtension = oldNameSplit.LastOrDefault();
|
||||||
|
for (int i = 0; i < oldNameSplit.Count() - 1; i++)
|
||||||
|
{
|
||||||
|
oldName += oldNameSplit[i];
|
||||||
|
}
|
||||||
|
file.Path = "***.***.****";
|
||||||
|
if (oldName.Count() >= 2)
|
||||||
|
{
|
||||||
|
file.Name = $"{oldName[0]}***{oldName}.{oldNameExtension}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file.Name = $"**.{oldNameExtension}";
|
||||||
|
}
|
||||||
|
return Ok(ApiResponse.Success(file));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost("upload")]
|
||||||
|
public async Task<IActionResult> UploadFile([FromQuery] string? stuid,[FromQuery]string filename, [FromQuery] string filepath, [FromQuery] float fileSizeInKB)
|
||||||
|
{
|
||||||
|
var filedesc = new FileDesc { Name = filename, Path = $"jphd-3dprint-2022.oss-cn-hangzhou.aliyuncs.com/uploads/{stuid}/{filename}", Size = Convert.ToInt32(fileSizeInKB), UploadTime = DateTime.Now };
|
||||||
|
if (!context.Students.Any(e => e.Stuid == stuid)) return Ok(ApiResponse.Error("INVALID_STUID"));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var s = context.Students.First(e => e.Stuid == stuid);
|
||||||
|
filedesc.OwnerId = s.Id;
|
||||||
|
if (s.Uploads == null) s.Uploads = new List<int> { };
|
||||||
|
context.FileDesc.Add(filedesc);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
s.Uploads.Add(filedesc.Id);
|
||||||
|
s.Status = status.已提交;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
return Ok(ApiResponse.Success("success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("postsession")]
|
||||||
public async Task<IActionResult> Post([FromQuery] string stuid, [FromQuery] string selection)
|
public async Task<IActionResult> Post([FromQuery] string stuid, [FromQuery] string selection)
|
||||||
{
|
{
|
||||||
Student stu = Context.Students.FirstOrDefault(r => r.Stuid == stuid);
|
Student stu = context.Students.FirstOrDefault(r => r.Stuid == stuid);
|
||||||
if (stu == null)
|
if (stu == null)
|
||||||
{
|
{
|
||||||
return StatusCode(400, ApiResponse.Error("INVALID_STUDENT_int"));
|
return StatusCode(400, ApiResponse.Error("INVALID_STUDENT_int"));
|
||||||
|
|
@ -110,31 +195,32 @@ namespace _2021_backend.Controllers
|
||||||
};
|
};
|
||||||
//get the selected session ints;
|
//get the selected session ints;
|
||||||
int targetSession = 0;
|
int targetSession = 0;
|
||||||
var sessions = Context.Sessions.ToList();
|
var sessions = context.Sessions.ToList();
|
||||||
var s = sessions.Find((Session s) =>
|
var s = sessions.Find((Session s) =>
|
||||||
{
|
{
|
||||||
return time.Day == s.Day && time.BeginTime == s.BeginTime;
|
return time.Day == s.Day && time.BeginTime == s.BeginTime;
|
||||||
});
|
});
|
||||||
var overwritten = false;
|
var overwritten = false;
|
||||||
if (s.Students.Count >= s.Capacity) return Ok(ApiResponse.Error("OUT_OF_CAPACITY"));
|
if (s.Students.Count >= s.Capacity) return Ok(ApiResponse.Error("OUT_OF_CAPACITY"));
|
||||||
if (Context.Sessions.Find(stu.InterviewTime) != null)
|
if (context.Sessions.Find(stu.InterviewTime) != null)
|
||||||
{
|
{
|
||||||
var olds = Context.Sessions.Find(stu.InterviewTime);
|
var olds = context.Sessions.Find(stu.InterviewTime);
|
||||||
olds.Students.Remove(stu.Id);
|
olds.Students.Remove(stu.Id);
|
||||||
Context.SaveChanges();
|
context.SaveChanges();
|
||||||
overwritten = true;
|
overwritten = true;
|
||||||
}
|
}
|
||||||
targetSession = s.Id;
|
targetSession = s.Id;
|
||||||
s.Students.Add(stu.Id);
|
s.Students.Add(stu.Id);
|
||||||
stu.Timelist = new List<int> { targetSession};
|
stu.Timelist = new List<int> { targetSession };
|
||||||
stu.Status = status.已选时间;
|
stu.Status = status.已选时间;
|
||||||
stu.InterviewTime = s.Id;
|
stu.InterviewTime = s.Id;
|
||||||
await TencentSMS.Send(Context, SMSType.TimeSet, stu, "smsbot");
|
await TencentSMS.Send(context, SMSType.TimeSet, stu, "smsbot");
|
||||||
Context.SaveChanges();
|
context.SaveChanges();
|
||||||
if (overwritten) return Ok(ApiResponse.Success("overwritten"));
|
if (overwritten) return Ok(ApiResponse.Success("overwritten"));
|
||||||
return Ok(ApiResponse.Success("success"));
|
return Ok(ApiResponse.Success("success"));
|
||||||
//return Ok(ApiResponse.Success("报名结束了"));
|
//return Ok(ApiResponse.Success("报名结束了"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,8 @@ namespace _2021_backend.Data
|
||||||
public DbSet<Student> Students { get; set; }
|
public DbSet<Student> Students { get; set; }
|
||||||
public DbSet<SMS> SMS { get; set; }
|
public DbSet<SMS> SMS { get; set; }
|
||||||
|
|
||||||
|
public DbSet<FileDesc> FileDesc { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder mb)
|
protected override void OnModelCreating(ModelBuilder mb)
|
||||||
{
|
{
|
||||||
mb.Entity<Submission>()
|
mb.Entity<Submission>()
|
||||||
|
|
@ -28,6 +30,7 @@ namespace _2021_backend.Data
|
||||||
.HasKey(u => u.Id);
|
.HasKey(u => u.Id);
|
||||||
mb.Entity<SMS>()
|
mb.Entity<SMS>()
|
||||||
.HasKey(u => u.Id);
|
.HasKey(u => u.Id);
|
||||||
|
mb.Entity<FileDesc>().HasKey(u => u.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ using _2021_backend.Data;
|
||||||
namespace _2021_backend.Migrations
|
namespace _2021_backend.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(BackendContext))]
|
[DbContext(typeof(BackendContext))]
|
||||||
[Migration("20220222090619_initial")]
|
[Migration("20220223070103_initial")]
|
||||||
partial class initial
|
partial class initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
|
@ -51,6 +51,34 @@ namespace _2021_backend.Migrations
|
||||||
b.ToTable("Comments");
|
b.ToTable("Comments");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("_2021_backend.Models.FileDesc", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("OwnerId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("Size")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UploadTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("FileDesc");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.Session", b =>
|
modelBuilder.Entity("_2021_backend.Models.Session", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
|
@ -140,6 +168,12 @@ namespace _2021_backend.Migrations
|
||||||
b.Property<int>("InterviewTime")
|
b.Property<int>("InterviewTime")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("LastCaptcha")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastCaptchaTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("LastSubmission")
|
b.Property<DateTime>("LastSubmission")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
|
@ -176,6 +210,9 @@ namespace _2021_backend.Migrations
|
||||||
b.Property<List<int>>("Timelist")
|
b.Property<List<int>>("Timelist")
|
||||||
.HasColumnType("integer[]");
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
|
b.Property<List<int>>("Uploads")
|
||||||
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
b.Property<int>("Yard")
|
b.Property<int>("Yard")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
|
@ -27,6 +27,23 @@ namespace _2021_backend.Migrations
|
||||||
table.PrimaryKey("PK_Comments", x => x.Id);
|
table.PrimaryKey("PK_Comments", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "FileDesc",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
OwnerId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Size = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Path = table.Column<string>(type: "text", nullable: true),
|
||||||
|
UploadTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_FileDesc", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Sessions",
|
name: "Sessions",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
|
|
@ -81,13 +98,16 @@ namespace _2021_backend.Migrations
|
||||||
Exp = table.Column<int>(type: "integer", nullable: false),
|
Exp = table.Column<int>(type: "integer", nullable: false),
|
||||||
InterviewTime = table.Column<int>(type: "integer", nullable: false),
|
InterviewTime = table.Column<int>(type: "integer", nullable: false),
|
||||||
Submissions = table.Column<List<int>>(type: "integer[]", nullable: true),
|
Submissions = table.Column<List<int>>(type: "integer[]", nullable: true),
|
||||||
|
Uploads = table.Column<List<int>>(type: "integer[]", nullable: true),
|
||||||
Messages = table.Column<List<int>>(type: "integer[]", nullable: true),
|
Messages = table.Column<List<int>>(type: "integer[]", nullable: true),
|
||||||
Timelist = table.Column<List<int>>(type: "integer[]", nullable: true),
|
Timelist = table.Column<List<int>>(type: "integer[]", nullable: true),
|
||||||
Comments = table.Column<List<int>>(type: "integer[]", nullable: true),
|
Comments = table.Column<List<int>>(type: "integer[]", nullable: true),
|
||||||
Score = table.Column<int>(type: "integer", nullable: false),
|
Score = table.Column<int>(type: "integer", nullable: false),
|
||||||
Status = table.Column<int>(type: "integer", nullable: false),
|
Status = table.Column<int>(type: "integer", nullable: false),
|
||||||
LastSubmission = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
LastSubmission = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
RegisterTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
RegisterTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
LastCaptcha = table.Column<string>(type: "text", nullable: true),
|
||||||
|
LastCaptchaTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
|
|
@ -141,6 +161,9 @@ namespace _2021_backend.Migrations
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Comments");
|
name: "Comments");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "FileDesc");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Sessions");
|
name: "Sessions");
|
||||||
|
|
||||||
|
|
@ -46,7 +46,35 @@ namespace _2021_backend.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Comments", (string)null);
|
b.ToTable("Comments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("_2021_backend.Models.FileDesc", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("OwnerId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("Size")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UploadTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("FileDesc");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.Session", b =>
|
modelBuilder.Entity("_2021_backend.Models.Session", b =>
|
||||||
|
|
@ -81,7 +109,7 @@ namespace _2021_backend.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Sessions", (string)null);
|
b.ToTable("Sessions");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.SMS", b =>
|
modelBuilder.Entity("_2021_backend.Models.SMS", b =>
|
||||||
|
|
@ -112,7 +140,7 @@ namespace _2021_backend.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("SMS", (string)null);
|
b.ToTable("SMS");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.Student", b =>
|
modelBuilder.Entity("_2021_backend.Models.Student", b =>
|
||||||
|
|
@ -138,6 +166,12 @@ namespace _2021_backend.Migrations
|
||||||
b.Property<int>("InterviewTime")
|
b.Property<int>("InterviewTime")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("LastCaptcha")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastCaptchaTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("LastSubmission")
|
b.Property<DateTime>("LastSubmission")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
|
@ -174,12 +208,15 @@ namespace _2021_backend.Migrations
|
||||||
b.Property<List<int>>("Timelist")
|
b.Property<List<int>>("Timelist")
|
||||||
.HasColumnType("integer[]");
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
|
b.Property<List<int>>("Uploads")
|
||||||
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
b.Property<int>("Yard")
|
b.Property<int>("Yard")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Students", (string)null);
|
b.ToTable("Students");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.Submission", b =>
|
modelBuilder.Entity("_2021_backend.Models.Submission", b =>
|
||||||
|
|
@ -231,7 +268,7 @@ namespace _2021_backend.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Submissions", (string)null);
|
b.ToTable("Submissions");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("_2021_backend.Models.User", b =>
|
modelBuilder.Entity("_2021_backend.Models.User", b =>
|
||||||
|
|
@ -256,7 +293,7 @@ namespace _2021_backend.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Users", (string)null);
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ namespace _2021_backend.Models
|
||||||
TimeSelect,
|
TimeSelect,
|
||||||
TimeSet,
|
TimeSet,
|
||||||
Signed,
|
Signed,
|
||||||
Reply
|
Reply,
|
||||||
|
Captcha,
|
||||||
}
|
}
|
||||||
public class SMS
|
public class SMS
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace _2021_backend.Models
|
||||||
需调整时间,
|
需调整时间,
|
||||||
已确认时间,
|
已确认时间,
|
||||||
不通过,
|
不通过,
|
||||||
|
已提交,
|
||||||
已评分,
|
已评分,
|
||||||
暂缺
|
暂缺
|
||||||
}
|
}
|
||||||
|
|
@ -48,8 +49,21 @@ namespace _2021_backend.Models
|
||||||
暂缺 = 0,
|
暂缺 = 0,
|
||||||
萌新 = 1,
|
萌新 = 1,
|
||||||
略有了解 = 2,
|
略有了解 = 2,
|
||||||
了解较多 = 3,
|
轻车熟路 = 3,
|
||||||
轻车熟路 = 4
|
}
|
||||||
|
|
||||||
|
public class FileDesc
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int OwnerId { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Size { get; set; }
|
||||||
|
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
public DateTime UploadTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Student
|
public class Student
|
||||||
|
|
@ -91,7 +105,6 @@ namespace _2021_backend.Models
|
||||||
student.Yard = sub.Yard;
|
student.Yard = sub.Yard;
|
||||||
student.Exp = sub.Exp;
|
student.Exp = sub.Exp;
|
||||||
student.Timelist = sub.Timelist;
|
student.Timelist = sub.Timelist;
|
||||||
student.Submissions.Add(sub.Id);
|
|
||||||
student.RegisterTime = sub.SubmitTime;
|
student.RegisterTime = sub.SubmitTime;
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
|
|
@ -122,8 +135,12 @@ namespace _2021_backend.Models
|
||||||
|
|
||||||
[Display(Name = "最终场次")]
|
[Display(Name = "最终场次")]
|
||||||
public int InterviewTime { get; set; }
|
public int InterviewTime { get; set; }
|
||||||
[Display(Name = "提交记录")]
|
[Display(Name = "报名记录")]
|
||||||
public List<int> Submissions { get; set; }
|
public List<int> Submissions { get; set; }
|
||||||
|
|
||||||
|
[Display(Name = "提交的文件")]
|
||||||
|
public List<int> Uploads { get; set; }
|
||||||
|
|
||||||
[Display(Name = "短信记录")]
|
[Display(Name = "短信记录")]
|
||||||
public List<int> Messages { get; set; }
|
public List<int> Messages { get; set; }
|
||||||
[Display(Name = "可选场次")]
|
[Display(Name = "可选场次")]
|
||||||
|
|
@ -143,5 +160,9 @@ namespace _2021_backend.Models
|
||||||
[Display(Name = "报名时间")]
|
[Display(Name = "报名时间")]
|
||||||
[DataType(DataType.DateTime)]
|
[DataType(DataType.DateTime)]
|
||||||
public DateTime RegisterTime { get; set; }
|
public DateTime RegisterTime { get; set; }
|
||||||
|
|
||||||
|
public string LastCaptcha { get; set; }
|
||||||
|
|
||||||
|
public DateTime LastCaptchaTime { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ namespace _2021_backend.Models
|
||||||
if (Major.Length > 20)
|
if (Major.Length > 20)
|
||||||
return false;
|
return false;
|
||||||
if (Yard >= 6 && Yard <= 0) return false;
|
if (Yard >= 6 && Yard <= 0) return false;
|
||||||
if (Exp >= 5 && Exp <= 0) return false;
|
if (Exp >= 3 && Exp <= 0) return false;
|
||||||
if (!r.IsMatch(Email))
|
if (!r.IsMatch(Email))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<strong>@Html.DisplayFor(model => Model.Errmsg)</strong>
|
<strong>@Html.DisplayFor(model => Model.Errmsg)</strong>
|
||||||
</h5>
|
</h5>
|
||||||
<h3><strong>发送短信</strong></h3>
|
<h3><strong>发送短信</strong></h3>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<input type="hidden" asp-for="pageid" />
|
<input type="hidden" asp-for="pageid" />
|
||||||
<input type="submit" value="拉取5天内的回复短信" class="btn btn-primary" asp-page-handler="Pull" />
|
<input type="submit" value="拉取5天内的回复短信" class="btn btn-primary" asp-page-handler="Pull" />
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace _2021_backend.Pages.Message
|
||||||
Context = context;
|
Context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Construct(int PageId)
|
public IActionResult Construct(int PageId, string emsg)
|
||||||
{
|
{
|
||||||
List<int> stus;
|
List<int> stus;
|
||||||
IQueryable<int> q;
|
IQueryable<int> q;
|
||||||
|
|
@ -62,101 +62,149 @@ namespace _2021_backend.Pages.Message
|
||||||
int count = (PageId + 1) * pageSize > cnt ? (cnt - PageId * pageSize) : pageSize;
|
int count = (PageId + 1) * pageSize > cnt ? (cnt - PageId * pageSize) : pageSize;
|
||||||
Messages = Messages.GetRange(PageId * pageSize, count);
|
Messages = Messages.GetRange(PageId * pageSize, count);
|
||||||
|
|
||||||
|
Errmsg = emsg;
|
||||||
|
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(int PageId)
|
public async Task<IActionResult> OnGetAsync(int PageId)
|
||||||
{
|
{
|
||||||
return Construct(PageId);
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync(int PageId)
|
public async Task<IActionResult> OnPostAsync(int PageId)
|
||||||
{
|
{
|
||||||
return Construct(PageId);
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void OnPostPullAsync(int PageId)
|
public async void OnPostPullAsync(int PageId)
|
||||||
{
|
{
|
||||||
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
var stu = Context.Students.ToList();
|
|
||||||
foreach (var e in stu)
|
|
||||||
{
|
{
|
||||||
await Utils.TencentSMS.Pull(Context, e, true);
|
return c.Type == ClaimTypes.Role && (
|
||||||
}
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
|
{
|
||||||
|
await Utils.TencentSMS.Pull(Context, e, true);
|
||||||
|
}
|
||||||
|
|
||||||
Construct(PageId);
|
Construct(PageId, "");
|
||||||
|
}
|
||||||
|
else Construct(PageId, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostSignAsync(int PageId)
|
public async Task<IActionResult> OnPostSignAsync(int PageId)
|
||||||
{
|
{
|
||||||
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
var stu = Context.Students.ToList();
|
|
||||||
foreach (var e in stu)
|
|
||||||
{
|
{
|
||||||
if (e.Status == status.刚报名)
|
return c.Type == ClaimTypes.Role && (
|
||||||
await Utils.TencentSMS.Send(Context, SMSType.Signed, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
c.Value == "admin" || c.Value == "manager");
|
||||||
}
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
|
{
|
||||||
|
if (e.Status == status.刚报名)
|
||||||
|
await Utils.TencentSMS.Send(Context, SMSType.Signed, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
||||||
|
}
|
||||||
|
|
||||||
return Construct(PageId);
|
return Construct(PageId, "");
|
||||||
|
}
|
||||||
|
else return Construct(PageId, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostResultRejectAsync(int PageId)
|
public async Task<IActionResult> OnPostResultRejectAsync(int PageId)
|
||||||
{
|
{
|
||||||
var stu = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach (var e in stu)
|
|
||||||
{
|
{
|
||||||
if (e.Status == status.不通过)
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
{
|
{
|
||||||
if (!Context.SMS.Any(it => it.Host == e.Id && it.Type == SMSType.Reject))
|
if (e.Status == status.不通过)
|
||||||
await Utils.TencentSMS.Send(Context, SMSType.Reject, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
{
|
||||||
|
if (!Context.SMS.Any(it => it.Host == e.Id && it.Type == SMSType.Reject))
|
||||||
|
await Utils.TencentSMS.Send(Context, SMSType.Reject, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
return Construct(PageId);
|
else return Construct(PageId, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostTimeSelectAsync(int PageId)
|
public async Task<IActionResult> OnPostTimeSelectAsync(int PageId)
|
||||||
{
|
{
|
||||||
var stu = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach (var e in stu)
|
|
||||||
{
|
{
|
||||||
if (e.Status != status.不通过 && e.Status != status.已选时间)
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
{
|
{
|
||||||
await Utils.TencentSMS.Send(Context, SMSType.TimeSelect, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
if (e.Status != status.不通过 && e.Status != status.已选时间)
|
||||||
|
{
|
||||||
|
await Utils.TencentSMS.Send(Context, SMSType.TimeSelect, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
else return Construct(PageId, "您无权进行此操作");
|
||||||
return Construct(PageId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostResultAccpetAsync(int PageId)
|
public async Task<IActionResult> OnPostResultAcceptAsync(int PageId)
|
||||||
{
|
{
|
||||||
var stu = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach (var e in stu)
|
|
||||||
{
|
{
|
||||||
if (e.Status == status.通过)
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
{
|
{
|
||||||
if (!Context.SMS.Any(it => it.Host == e.Id && it.Type == SMSType.Accept))
|
if (e.Status == status.通过)
|
||||||
await Utils.TencentSMS.Send(Context, SMSType.Accept, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
{
|
||||||
}
|
if (!Context.SMS.Any(it => it.Host == e.Id && it.Type == SMSType.Accept))
|
||||||
|
await Utils.TencentSMS.Send(Context, SMSType.Accept, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
return Construct(PageId);
|
else return Construct(PageId, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostTimeSetAsync(int PageId)
|
public async Task<IActionResult> OnPostTimeSetAsync(int PageId)
|
||||||
{
|
{
|
||||||
var stu = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach(var e in stu)
|
|
||||||
{
|
{
|
||||||
var t = Context.Sessions.Find(e.InterviewTime);
|
return c.Type == ClaimTypes.Role && (
|
||||||
if(t != null && t.Students.Find(s => s==e.Id)!= 0 && e.Status == status.已选时间)
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var stu = Context.Students.ToList();
|
||||||
|
foreach (var e in stu)
|
||||||
{
|
{
|
||||||
await Utils.TencentSMS.Send(Context, SMSType.TimeSet, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
var t = Context.Sessions.Find(e.InterviewTime);
|
||||||
e.Status = status.已确认时间;
|
if (t != null && t.Students.Find(s => s == e.Id) != 0 && e.Status == status.已选时间)
|
||||||
|
{
|
||||||
|
await Utils.TencentSMS.Send(Context, SMSType.TimeSet, e, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
||||||
|
e.Status = status.已确认时间;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct(PageId, "");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
else return Construct(PageId, "您无权进行此操作");
|
||||||
return Construct(PageId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace _2021_backend.Pages.Sessions
|
namespace _2021_backend.Pages.Sessions
|
||||||
{
|
{
|
||||||
|
|
@ -124,159 +125,227 @@ namespace _2021_backend.Pages.Sessions
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostArrangeAsync()
|
public async Task<IActionResult> OnPostArrangeAsync()
|
||||||
{
|
{
|
||||||
if (Utils.Arranger.Arrange(Context)) return Construct("");
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
else return Construct("排班失败,无法满足条件");
|
{
|
||||||
|
return c.Type == ClaimTypes.Role&& (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
})){
|
||||||
|
if (Utils.Arranger.Arrange(Context)) return Construct("");
|
||||||
|
else return Construct("排班失败,无法满足条件");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct("您无权进行此操作");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostClearAllAsync()
|
public async Task<IActionResult> OnPostClearAllAsync()
|
||||||
{
|
{
|
||||||
foreach(var s in Context.Students)
|
|
||||||
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
{
|
{
|
||||||
s.InterviewTime = 0;
|
return c.Type == ClaimTypes.Role && (
|
||||||
s.Status = status.需调整时间;
|
c.Value == "admin" || c.Value == "manager");
|
||||||
s.Timelist.Clear();
|
}))
|
||||||
}
|
|
||||||
Context.SaveChanges();
|
|
||||||
foreach(var s in Context.Sessions)
|
|
||||||
{
|
{
|
||||||
Context.Sessions.Remove(s);
|
foreach (var s in Context.Students)
|
||||||
|
{
|
||||||
|
s.InterviewTime = 0;
|
||||||
|
s.Status = status.需调整时间;
|
||||||
|
s.Timelist.Clear();
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
foreach (var s in Context.Sessions)
|
||||||
|
{
|
||||||
|
Context.Sessions.Remove(s);
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct("您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostResetAllAsync()
|
public async Task<IActionResult> OnPostResetAllAsync()
|
||||||
{
|
{
|
||||||
var stus = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach (var s in stus)
|
|
||||||
{
|
{
|
||||||
if(s.Status == status.已选时间)
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var stus = Context.Students.ToList();
|
||||||
|
foreach (var s in stus)
|
||||||
{
|
{
|
||||||
s.InterviewTime = 0;
|
if (s.Status == status.已选时间)
|
||||||
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Id == it));
|
|
||||||
s.Timelist.Sort((int a, int b) =>
|
|
||||||
{
|
{
|
||||||
var x = Context.Sessions.Find(a);
|
s.InterviewTime = 0;
|
||||||
var y = Context.Sessions.Find(b);
|
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Id == it));
|
||||||
var k1 = x.Day.CompareTo(y.Day);
|
s.Timelist.Sort((int a, int b) =>
|
||||||
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
{
|
||||||
return k1 != 0 ? k1 : k2;
|
var x = Context.Sessions.Find(a);
|
||||||
});
|
var y = Context.Sessions.Find(b);
|
||||||
|
var k1 = x.Day.CompareTo(y.Day);
|
||||||
|
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
||||||
|
return k1 != 0 ? k1 : k2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
foreach (var s in Context.Sessions)
|
||||||
|
{
|
||||||
|
s.Students.Clear();
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct("");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
else
|
||||||
foreach (var s in Context.Sessions)
|
|
||||||
{
|
{
|
||||||
s.Students.Clear();
|
return Construct("您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostSaveAsync()
|
public async Task<IActionResult> OnPostSaveAsync()
|
||||||
{
|
{
|
||||||
var lst = Context.Sessions.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
var str = JsonSerializer.Serialize(lst);
|
{
|
||||||
Console.WriteLine("Saving arrangement: " + str);
|
return c.Type == ClaimTypes.Role && (
|
||||||
if(!Directory.Exists("./saves")) Directory.CreateDirectory("./saves/");
|
c.Value == "admin" || c.Value == "manager");
|
||||||
System.IO.File.WriteAllText($"./saves/{DateTime.Now.ToString("MM-dd-hh-mm-ss")}.txt", str);
|
}))
|
||||||
return Construct("");
|
{
|
||||||
|
var lst = Context.Sessions.ToList();
|
||||||
|
var str = JsonSerializer.Serialize(lst);
|
||||||
|
Console.WriteLine("Saving arrangement: " + str);
|
||||||
|
if (!Directory.Exists("./saves")) Directory.CreateDirectory("./saves/");
|
||||||
|
System.IO.File.WriteAllText($"./saves/{DateTime.Now.ToString("MM-dd-hh-mm-ss")}.txt", str);
|
||||||
|
return Construct("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct("您无权进行此操作");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public async Task<IActionResult> OnPostTidyAsync()
|
public async Task<IActionResult> OnPostTidyAsync()
|
||||||
{
|
{
|
||||||
var stus = Context.Students.ToList();
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
var sess = Context.Sessions.ToList();
|
|
||||||
foreach(var i in stus)
|
|
||||||
{
|
{
|
||||||
var tm = i.Timelist;
|
return c.Type == ClaimTypes.Role && (
|
||||||
var ntm = new List<Session>();
|
c.Value == "admin" || c.Value == "manager");
|
||||||
foreach(var j in tm)
|
}))
|
||||||
|
{
|
||||||
|
var stus = Context.Students.ToList();
|
||||||
|
var sess = Context.Sessions.ToList();
|
||||||
|
foreach (var i in stus)
|
||||||
{
|
{
|
||||||
var k = sess.Find(it => it.Id == j);
|
var tm = i.Timelist;
|
||||||
ntm.Add(k);
|
var ntm = new List<Session>();
|
||||||
}
|
foreach (var j in tm)
|
||||||
ntm.Sort((Session a,Session b) =>
|
|
||||||
{
|
|
||||||
var x = a.Day.CompareTo(b.Day);
|
|
||||||
var y = a.BeginTime.CompareTo(b.BeginTime);
|
|
||||||
return x != 0 ? x : y;
|
|
||||||
});
|
|
||||||
List<int> nl = new List<int>();
|
|
||||||
foreach(var j in ntm)
|
|
||||||
{
|
|
||||||
if(i.Status != status.不通过 && i.Status != status.通过 && i.Status != status.已确认时间)
|
|
||||||
{
|
{
|
||||||
if (j.Day.Date.Add(j.BeginTime.TimeOfDay).CompareTo(DateTime.Now) < 0 || (j.Students.Count >= j.Capacity && !j.Students.Any(k => k ==i.Id) )) continue;
|
var k = sess.Find(it => it.Id == j);
|
||||||
nl.Add(j.Id);
|
ntm.Add(k);
|
||||||
}
|
}
|
||||||
else
|
ntm.Sort((Session a, Session b) =>
|
||||||
{
|
{
|
||||||
nl.Add(j.Id);
|
var x = a.Day.CompareTo(b.Day);
|
||||||
|
var y = a.BeginTime.CompareTo(b.BeginTime);
|
||||||
|
return x != 0 ? x : y;
|
||||||
|
});
|
||||||
|
List<int> nl = new List<int>();
|
||||||
|
foreach (var j in ntm)
|
||||||
|
{
|
||||||
|
if (i.Status != status.不通过 && i.Status != status.通过 && i.Status != status.已确认时间)
|
||||||
|
{
|
||||||
|
if (j.Day.Date.Add(j.BeginTime.TimeOfDay).CompareTo(DateTime.Now) < 0 || (j.Students.Count >= j.Capacity && !j.Students.Any(k => k == i.Id))) continue;
|
||||||
|
nl.Add(j.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nl.Add(j.Id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
i.Timelist = nl;
|
||||||
}
|
}
|
||||||
i.Timelist = nl;
|
Context.SaveChanges();
|
||||||
|
return Construct("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct("您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostLoadAsync()
|
public async Task<IActionResult> OnPostLoadAsync()
|
||||||
{
|
{
|
||||||
var str = "";
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
|
{
|
||||||
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var str = "";
|
||||||
|
|
||||||
List<Session> loads = new List<Session>();
|
List<Session> loads = new List<Session>();
|
||||||
if (!string.IsNullOrEmpty(savename)) str = System.IO.File.ReadAllText(savename);
|
if (!string.IsNullOrEmpty(savename)) str = System.IO.File.ReadAllText(savename);
|
||||||
loads = JsonSerializer.Deserialize<List<Session>>(str);
|
loads = JsonSerializer.Deserialize<List<Session>>(str);
|
||||||
|
|
||||||
var stus = Context.Students.ToList();
|
var stus = Context.Students.ToList();
|
||||||
foreach (var s in stus)
|
foreach (var s in stus)
|
||||||
{
|
|
||||||
if (s.Status == status.已选时间)
|
|
||||||
{
|
{
|
||||||
s.InterviewTime = 0;
|
if (s.Status == status.已选时间)
|
||||||
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Id == it));
|
|
||||||
s.Timelist.Sort((int a, int b) =>
|
|
||||||
{
|
{
|
||||||
var x = Context.Sessions.Find(a);
|
s.InterviewTime = 0;
|
||||||
var y = Context.Sessions.Find(b);
|
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Id == it));
|
||||||
var k1 = x.Day.CompareTo(y.Day);
|
s.Timelist.Sort((int a, int b) =>
|
||||||
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
|
||||||
return k1 != 0 ? k1 : k2;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Context.SaveChanges();
|
|
||||||
foreach (var s in Context.Sessions)
|
|
||||||
{
|
|
||||||
s.Students.Clear();
|
|
||||||
}
|
|
||||||
Context.SaveChanges();
|
|
||||||
foreach(var item in loads)
|
|
||||||
{
|
|
||||||
Session s = Context.Sessions.Find(item.Id);
|
|
||||||
if(s != null)
|
|
||||||
{
|
|
||||||
s.BeginTime = item.BeginTime;
|
|
||||||
s.Day = item.Day;
|
|
||||||
s.Capacity = item.Capacity;
|
|
||||||
s.SendSMS = item.SendSMS;
|
|
||||||
s.Chiefs = item.Chiefs;
|
|
||||||
s.Students = new List<int>();
|
|
||||||
foreach(var s2 in item.Students)
|
|
||||||
{
|
|
||||||
if (Context.Students.Any(k => k.Id == s2))
|
|
||||||
{
|
{
|
||||||
Context.Students.Find(s2).InterviewTime = item.Id;
|
var x = Context.Sessions.Find(a);
|
||||||
s.Students.Add(s2);
|
var y = Context.Sessions.Find(b);
|
||||||
|
var k1 = x.Day.CompareTo(y.Day);
|
||||||
|
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
||||||
|
return k1 != 0 ? k1 : k2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
foreach (var s in Context.Sessions)
|
||||||
|
{
|
||||||
|
s.Students.Clear();
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
foreach (var item in loads)
|
||||||
|
{
|
||||||
|
Session s = Context.Sessions.Find(item.Id);
|
||||||
|
if (s != null)
|
||||||
|
{
|
||||||
|
s.BeginTime = item.BeginTime;
|
||||||
|
s.Day = item.Day;
|
||||||
|
s.Capacity = item.Capacity;
|
||||||
|
s.SendSMS = item.SendSMS;
|
||||||
|
s.Chiefs = item.Chiefs;
|
||||||
|
s.Students = new List<int>();
|
||||||
|
foreach (var s2 in item.Students)
|
||||||
|
{
|
||||||
|
if (Context.Students.Any(k => k.Id == s2))
|
||||||
|
{
|
||||||
|
Context.Students.Find(s2).InterviewTime = item.Id;
|
||||||
|
s.Students.Add(s2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct("您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,35 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
给他打分
|
给他打分
|
||||||
<input asp-for="score" class="form-control"/>
|
<input asp-for="score" class="form-control" />
|
||||||
<input type="submit" value="打" class="btn btn-warning" style="margin:5px" asp-page-handler="Rank" />
|
<input type="submit" value="打分" class="btn btn-warning" style="margin:5px" asp-page-handler="Rank" />
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-2">
|
||||||
|
作品链接:
|
||||||
|
@{
|
||||||
|
if(Model.Student.Uploads == null)
|
||||||
|
{
|
||||||
|
<div>尚未提交作品</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var fd = Model.Context.FileDesc.Find(Model.Student.Uploads.Last());
|
||||||
|
if (fd == null)
|
||||||
|
{
|
||||||
|
<div>尚未提交作品</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a href="https://@Html.DisplayFor(model => fd.Path)">点我</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|
@ -161,7 +187,7 @@
|
||||||
</h4>
|
</h4>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr >
|
<tr>
|
||||||
<th>地点</th>
|
<th>地点</th>
|
||||||
<th>日期</th>
|
<th>日期</th>
|
||||||
<th>时间</th>
|
<th>时间</th>
|
||||||
|
|
@ -293,7 +319,7 @@
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.SubmissionSample.Sex)
|
@Html.DisplayNameFor(model => model.SubmissionSample.Sex)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.SubmissionSample.Yard)
|
@Html.DisplayNameFor(model => model.SubmissionSample.Yard)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using _2021_backend.Utils;
|
using _2021_backend.Utils;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace _2021_backend.Pages.Students
|
namespace _2021_backend.Pages.Students
|
||||||
{
|
{
|
||||||
|
|
@ -96,26 +97,48 @@ namespace _2021_backend.Pages.Students
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostFinalizeAsync(int? pageId, string errInfo)
|
public async Task<IActionResult> OnPostFinalizeAsync(int? pageId, string errInfo)
|
||||||
{
|
{
|
||||||
if (pageId == null) pageId = 0;
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
|
|
||||||
foreach(var s in Context.Students)
|
|
||||||
{
|
{
|
||||||
if (s.RegisterTime.CompareTo(new DateTime(2021, 11, 11)) > 0) s.Status = status.不通过;
|
return c.Type == ClaimTypes.Role && (
|
||||||
else if (s.Timelist.Count == 0 && s.Status != status.不通过) s.Status = status.需调整时间;
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
if (pageId == null) pageId = 0;
|
||||||
|
|
||||||
|
foreach (var s in Context.Students)
|
||||||
|
{
|
||||||
|
if (s.RegisterTime.CompareTo(new DateTime(2021, 11, 11)) > 0) s.Status = status.不通过;
|
||||||
|
else if (s.Timelist.Count == 0 && s.Status != status.不通过) s.Status = status.需调整时间;
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct((int)pageId, errInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct(pageId??0, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct((int)pageId, errInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostReselectAllAsync(int? pageId,string errInfo)
|
public async Task<IActionResult> OnPostReselectAllAsync(int? pageId,string errInfo)
|
||||||
{
|
{
|
||||||
if (pageId == null) pageId = 0;
|
if (HttpContext.User.HasClaim((c) =>
|
||||||
foreach (var s in Context.Students)
|
|
||||||
{
|
{
|
||||||
if (s.Status != status.不通过) s.Status = status.需调整时间;
|
return c.Type == ClaimTypes.Role && (
|
||||||
|
c.Value == "admin" || c.Value == "manager");
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
if (pageId == null) pageId = 0;
|
||||||
|
foreach (var s in Context.Students)
|
||||||
|
{
|
||||||
|
if (s.Status != status.不通过) s.Status = status.需调整时间;
|
||||||
|
}
|
||||||
|
Context.SaveChanges();
|
||||||
|
return Construct((int)pageId, errInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Construct(pageId ?? 0, "您无权进行此操作");
|
||||||
}
|
}
|
||||||
Context.SaveChanges();
|
|
||||||
return Construct((int)pageId,errInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
Program.cs
10
Program.cs
|
|
@ -14,6 +14,7 @@ namespace _2021_backend
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
|
|
@ -28,7 +29,7 @@ namespace _2021_backend
|
||||||
context.Database.Migrate();
|
context.Database.Migrate();
|
||||||
Console.WriteLine("Migration succeeded.");
|
Console.WriteLine("Migration succeeded.");
|
||||||
var config = host.Services.GetRequiredService<IConfiguration>();
|
var config = host.Services.GetRequiredService<IConfiguration>();
|
||||||
TencentSMS.Init(config["TENCENT_ID"], config["TENCENT_KEY"], config["SMS_APPID"], config["SMS_ID_ACCEPT"], config["SMS_ID_REJECT"], config["SMS_ID_TIMESET"], config["SMS_ID_SUBMITTED"], config["SMS_ID_TIMESELECT"]);
|
TencentSMS.Init(config["TENCENT_ID"], config["TENCENT_KEY"], config["SMS_APPID"], config["SMS_ID_ACCEPT"], config["SMS_ID_REJECT"], config["SMS_ID_TIMESET"], config["SMS_ID_SUBMITTED"], config["SMS_ID_TIMESELECT"], config["SMS_ID_CAPTCHA"]);
|
||||||
var botname = config["SMSBOT_NAME"];
|
var botname = config["SMSBOT_NAME"];
|
||||||
var q = context.Users.Where(it => it.Name == botname);
|
var q = context.Users.Where(it => it.Name == botname);
|
||||||
if (q.Count() == 0)
|
if (q.Count() == 0)
|
||||||
|
|
@ -47,14 +48,13 @@ namespace _2021_backend
|
||||||
User.Bot = q.FirstOrDefault();
|
User.Bot = q.FirstOrDefault();
|
||||||
//do nothing cause I 've already got a bot
|
//do nothing cause I 've already got a bot
|
||||||
}
|
}
|
||||||
var id = int.Parse("4c20c535-3661-40c7-b4db-ce479675bbd7");
|
var name = config["ADMIN_USERNAME"];
|
||||||
while (context.Users.Any(e => e.Id == id))
|
while (context.Users.Any(e => e.stuID == name))
|
||||||
{
|
{
|
||||||
context.Users.Remove(context.Users.Find(id));
|
context.Users.Remove(context.Users.FirstOrDefault(e => e.stuID == name));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var usr = new User();
|
var usr = new User();
|
||||||
usr.Id = id;
|
|
||||||
usr.Name = config["ADMIN_USERNAME"];
|
usr.Name = config["ADMIN_USERNAME"];
|
||||||
usr.isManager = true;
|
usr.isManager = true;
|
||||||
usr.Secret = EvaCryptoHelper.Password2Secret(config["ADMIN_PASSWORD"]);
|
usr.Secret = EvaCryptoHelper.Password2Secret(config["ADMIN_PASSWORD"]);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
|
||||||
namespace _2021_backend
|
namespace _2021_backend
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace _2021_backend.Utils
|
||||||
|
{
|
||||||
|
public static class CipherHelper
|
||||||
|
{
|
||||||
|
static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
|
||||||
|
{
|
||||||
|
// Check arguments.
|
||||||
|
if (plainText == null || plainText.Length <= 0)
|
||||||
|
throw new ArgumentNullException("plainText");
|
||||||
|
if (Key == null || Key.Length <= 0)
|
||||||
|
throw new ArgumentNullException("Key");
|
||||||
|
if (IV == null || IV.Length <= 0)
|
||||||
|
throw new ArgumentNullException("IV");
|
||||||
|
byte[] encrypted;
|
||||||
|
|
||||||
|
// Create an Aes object
|
||||||
|
// with the specified key and IV.
|
||||||
|
using (Aes aesAlg = Aes.Create())
|
||||||
|
{
|
||||||
|
aesAlg.Key = Key;
|
||||||
|
aesAlg.IV = IV;
|
||||||
|
|
||||||
|
// Create an encryptor to perform the stream transform.
|
||||||
|
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
// Create the streams used for encryption.
|
||||||
|
using (MemoryStream msEncrypt = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
|
||||||
|
{
|
||||||
|
//Write all data to the stream.
|
||||||
|
swEncrypt.Write(plainText);
|
||||||
|
}
|
||||||
|
encrypted = msEncrypt.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the encrypted bytes from the memory stream.
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
|
||||||
|
{
|
||||||
|
// Check arguments.
|
||||||
|
if (cipherText == null || cipherText.Length <= 0)
|
||||||
|
throw new ArgumentNullException("cipherText");
|
||||||
|
if (Key == null || Key.Length <= 0)
|
||||||
|
throw new ArgumentNullException("Key");
|
||||||
|
if (IV == null || IV.Length <= 0)
|
||||||
|
throw new ArgumentNullException("IV");
|
||||||
|
|
||||||
|
// Declare the string used to hold
|
||||||
|
// the decrypted text.
|
||||||
|
string plaintext = null;
|
||||||
|
|
||||||
|
// Create an Aes object
|
||||||
|
// with the specified key and IV.
|
||||||
|
using (Aes aesAlg = Aes.Create())
|
||||||
|
{
|
||||||
|
aesAlg.Key = Key;
|
||||||
|
aesAlg.IV = IV;
|
||||||
|
|
||||||
|
// Create a decryptor to perform the stream transform.
|
||||||
|
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
// Create the streams used for decryption.
|
||||||
|
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
|
||||||
|
{
|
||||||
|
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
|
||||||
|
{
|
||||||
|
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
|
||||||
|
{
|
||||||
|
|
||||||
|
// Read the decrypted bytes from the decrypting stream
|
||||||
|
// and place them in a string.
|
||||||
|
plaintext = srDecrypt.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plaintext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ using TencentCloud.Common;
|
||||||
using TencentCloud.Common.Profile;
|
using TencentCloud.Common.Profile;
|
||||||
using TencentCloud.Sms.V20210111;
|
using TencentCloud.Sms.V20210111;
|
||||||
using TencentCloud.Sms.V20210111.Models;
|
using TencentCloud.Sms.V20210111.Models;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace _2021_backend.Utils
|
namespace _2021_backend.Utils
|
||||||
{
|
{
|
||||||
|
|
@ -21,12 +22,13 @@ namespace _2021_backend.Utils
|
||||||
public static string SMSID_reject { get; set; }
|
public static string SMSID_reject { get; set; }
|
||||||
public static string SMSID_timeSet { get; set; }
|
public static string SMSID_timeSet { get; set; }
|
||||||
public static string SMSID_signed { get; set; }
|
public static string SMSID_signed { get; set; }
|
||||||
|
public static string SMSID_captcha { get; set; }
|
||||||
|
|
||||||
private static bool Initialized = false;
|
private static bool Initialized = false;
|
||||||
|
|
||||||
private static string SMSID_timeSelect { get; set; }
|
private static string SMSID_timeSelect { get; set; }
|
||||||
|
|
||||||
public static void Init(string tencentid, string tencentKey, string appid, string ID_accept, string ID_reject, string ID_timeSet, string ID_submitted, string ID_timeSelect)
|
public static void Init(string tencentid, string tencentKey, string appid, string ID_accept, string ID_reject, string ID_timeSet, string ID_submitted, string ID_timeSelect,string ID_captcha)
|
||||||
{
|
{
|
||||||
Tencent_id = tencentid;
|
Tencent_id = tencentid;
|
||||||
Tencent_key = tencentKey;
|
Tencent_key = tencentKey;
|
||||||
|
|
@ -36,6 +38,7 @@ namespace _2021_backend.Utils
|
||||||
SMSID_timeSet = ID_timeSet;
|
SMSID_timeSet = ID_timeSet;
|
||||||
SMSID_signed = ID_submitted;
|
SMSID_signed = ID_submitted;
|
||||||
SMSID_timeSelect = ID_timeSelect;
|
SMSID_timeSelect = ID_timeSelect;
|
||||||
|
SMSID_captcha = ID_captcha;
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
}
|
}
|
||||||
public static async Task<bool> Pull(BackendContext Context, Student stu, bool fullPull)
|
public static async Task<bool> Pull(BackendContext Context, Student stu, bool fullPull)
|
||||||
|
|
@ -145,6 +148,18 @@ namespace _2021_backend.Utils
|
||||||
req.TemplateParamSet = new string[] { stu.Name };
|
req.TemplateParamSet = new string[] { stu.Name };
|
||||||
req.TemplateId = SMSID_signed;
|
req.TemplateId = SMSID_signed;
|
||||||
break;
|
break;
|
||||||
|
case SMSType.Captcha:
|
||||||
|
sms.Type = SMSType.Captcha;
|
||||||
|
var captchaBytes = new byte[]{0,0,0,0,0,0};
|
||||||
|
RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider();
|
||||||
|
csp.GetBytes(captchaBytes);
|
||||||
|
for (int i = 0; i < 6; i++) captchaBytes[i] %= 10;
|
||||||
|
string captcha = $"{captchaBytes[0]}{captchaBytes[1]}{captchaBytes[2]}{captchaBytes[3]}{captchaBytes[4]}{captchaBytes[5]}";
|
||||||
|
stu.LastCaptcha = captcha;
|
||||||
|
stu.LastCaptchaTime = DateTime.Now;
|
||||||
|
req.TemplateParamSet = new string[] { captcha };
|
||||||
|
req.TemplateId = SMSID_captcha;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
sms.Tel = stu.Tel;
|
sms.Tel = stu.Tel;
|
||||||
sms.Host = stu.Id;
|
sms.Host = stu.Id;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
"SMS_ID_SUBMITTED": "1163892",
|
"SMS_ID_SUBMITTED": "1163892",
|
||||||
"SMS_ID_TIMESET": "1232109",
|
"SMS_ID_TIMESET": "1232109",
|
||||||
"SMS_ID_TIMESELECT": "1232577",
|
"SMS_ID_TIMESELECT": "1232577",
|
||||||
|
"SMS_ID_CAPTCHA": "1312236",
|
||||||
"TENCENT_ID": "AKIDYv5JGwKSJtCE0VjhOpyqSotgDTSaYIsF",
|
"TENCENT_ID": "AKIDYv5JGwKSJtCE0VjhOpyqSotgDTSaYIsF",
|
||||||
"TENCENT_KEY": "mPzSimdGenpdCWcT5TcWBboreAQQ9bmh",
|
"TENCENT_KEY": "mPzSimdGenpdCWcT5TcWBboreAQQ9bmh",
|
||||||
"SMSBOT_NAME": "msgbot",
|
"SMSBOT_NAME": "msgbot",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue