public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var member = await db.Members.FindAsync(StudentNumber); if (member == null) { ViewData["Message"] = @" <p>아이디가 없습니다. <p>회원이라면 관리자에게 문의하세요."; return(Page()); } if (member.Password == null) { return(RedirectToPage("./Register", new { ReturnUrl, StudentNumber, })); } // 비밀번호가 맞는지 검사 if (!BCrypt.Net.BCrypt.EnhancedVerify(Password, member.Password)) { if (!LegacyPasswordVerify(Password, member.Password)) { ViewData["Message"] = @" <p>비밀번호가 틀렸습니다. <p>비밀번호를 잊었다면 관리자에게 문의하세요."; return(Page()); } } if (BCrypt.Net.BCrypt.PasswordNeedsRehash(member.Password, 12)) { member.Password = BCrypt.Net.BCrypt.EnhancedHashPassword(Password, 12); await db.SaveChangesAsync(); } db.MemberLogs.Add(new Models.MemberLog { Member = member, Text = "LOGIN", }); await db.SaveChangesAsync(); await HttpContext.Session.LoadAsync(); HttpContext.Session.SetInt32("username", (int)member.StudentNumber); await HttpContext.Session.CommitAsync(); return(Redirect(ReturnUrl ?? $"{Request.PathBase}/")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (Password != PasswordConfirm) { ViewData["Message"] = @" <p>비밀번호가 다릅니다."; return(Page()); } var member = await db.Members.FindAsync(StudentNumber); if ( member == null || member.Password != null || member.Name != Name || member.PhoneNumber != uint.Parse(Regex.Replace(PhoneNumber, "[^0-9]", "")) ) { ViewData["Message"] = $@" <p>본인 확인을 실패하였거나 비밀번호가 이미 설정되어 있습니다."; return(Page()); } db.MemberLogs.Add(new Models.MemberLog { Member = member, Text = "INITIALIZE", }); await db.SaveChangesAsync(); member.Password = BCrypt.Net.BCrypt.EnhancedHashPassword(Password, 12); await db.SaveChangesAsync(); return(RedirectToPage("./Login", new { Registered = true, ReturnUrl, })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var activity = new Activity { AuthorId = (uint)HttpContext.Session.GetInt32("username"), }; if (!await TryUpdateModelAsync(activity, "Activity", i => i.Content, i => i.EndAt, i => i.Place, i => i.StartAt, i => i.Summary)) { return(BadRequest()); } foreach (var attachment in Attachments) { var filename = $"{Guid.NewGuid()}{Path.GetExtension(attachment.FileName)}"; var path = Path.Combine(env.ContentRootPath, "storage", "attaches", filename); using (var fs = new FileStream(path, FileMode.CreateNew)) { await attachment.CopyToAsync(fs); } activity.Attachments.Add(new ActivityAttachment { Filename = filename, MediaType = attachment.ContentType, OriginalFilename = attachment.FileName, Size = attachment.Length, }); } foreach (var attendeeStudentNumber in Request.Form["attend[]"].Select(uint.Parse)) { activity.ActivityAttendees.Add(new ActivityAttendee { AttandeeId = attendeeStudentNumber, }); } db.Activities.Add(activity); await db.SaveChangesAsync(); return(RedirectToPage("./Index", new { ActivityId = activity.Id, })); }
public async Task <IActionResult> OnPostAsync([FromForm] string source) { Task = await db.Tasks.FindAsync(TaskId); if (Task == null) { return(NotFound()); } var authorId = (uint)HttpContext.Session.GetInt32("username"); var filename = $"{Task.Id}_{authorId}_{Language.ToString()}"; var path = Path.Combine(env.ContentRootPath, "storage", "sources", filename); var i = 1; while (System.IO.File.Exists($"{path}_{i}{LanguageExtension}")) { i++; } filename += $"_{i}{LanguageExtension}"; path += $"_{i}{LanguageExtension}"; var submission = new Models.Submission { Task = Task, AuthorId = authorId, Sequence = (uint)i, Working = true, Error = "", Language = Language, Filename = filename, }; using (var fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) using (var sw = new StreamWriter(fs, new UTF8Encoding(false))) { await sw.WriteAsync(source); } submission.Size = (uint)new FileInfo(path).Length; db.Submissions.Add(submission); await db.SaveChangesAsync(); queue.QueueBackgroundWorkItem(submission); return(RedirectToPage("/Submissions/Index", new { taskId = TaskId, })); }
public async Task <ActionResult> OnPostAsync(uint submissionId) { var submission = await db.Submissions.FindAsync(submissionId); if (submission == null) { return(NotFound()); } submission.Status = Models.Submission.StatusCode.SuccessOrInitialization; submission.Score = 0; submission.Working = true; await db.SaveChangesAsync(); queue.QueueBackgroundWorkItem(submission); return(RedirectToPage("/Submissions/Read", new { submissionId, })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var task = new Models.Task(); if (!await TryUpdateModelAsync( task, "Task", i => i.StartAt, i => i.EndAt, i => i.Title, i => i.Content, i => i.ExampleInput, i => i.ExampleOutput)) { return(Page()); } for (var i = 0; i < Request.Form["test_score[]"].Count; i++) { task.Tests.Add(new Models.TaskTest { Score = uint.Parse(Request.Form["test_score[]"][i]), Input = Request.Form["test_input[]"][i], Output = Request.Form["test_output[]"][i], }); } db.Tasks.Add(task); await db.SaveChangesAsync(); return(RedirectToPage("./Read", new { TaskId = task.Id, })); }