This repository has been archived on 2023-04-02. You can view files and clone it, but cannot push or open issues or pull requests.
trainav/trainav.web/Pages/Register.cshtml.cs

31 lines
1 KiB
C#
Raw Normal View History

2020-06-11 20:29:16 +02:00
using System.Linq;
using LinqToDB;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages;
2022-04-29 14:59:24 +02:00
using trainav.web.database;
using trainav.web.database.Tables;
2020-06-11 20:29:16 +02:00
2022-04-29 14:59:24 +02:00
namespace trainav.web.Pages {
2020-06-11 20:29:16 +02:00
public class RegisterModel : PageModel {
public void OnPost() {
if (!Request.HasFormContentType
|| string.IsNullOrWhiteSpace(Request.Form["user"])
|| string.IsNullOrWhiteSpace(Request.Form["pass"])
|| string.IsNullOrWhiteSpace(Request.Form["code"]))
2020-06-11 20:29:16 +02:00
return;
if (Request.Form["code"] != System.IO.File.ReadAllLines("regkey.txt")[0])
return;
using var db = new Database.DbConn();
var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString());
2020-06-11 20:29:16 +02:00
if (user != null)
return; //user already exists
var uid = db.InsertWithInt32Identity(new User {Username = Request.Form["user"].ToString(), Password = Request.Form["pass"].ToString().Sha256()});
2020-06-11 20:29:16 +02:00
HttpContext.Session.SetString("uid", uid.ToString());
HttpContext.Session.SetString("authorized", "true");
}
}
}