31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using System.Linq;
|
|
using LinqToDB;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using trainav.web.database;
|
|
using trainav.web.database.Tables;
|
|
|
|
namespace trainav.web.Pages {
|
|
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"]))
|
|
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());
|
|
if (user != null)
|
|
return; //user already exists
|
|
|
|
var uid = db.InsertWithInt32Identity(new User {Username = Request.Form["user"].ToString(), Password = Request.Form["pass"].ToString().Sha256()});
|
|
|
|
HttpContext.Session.SetString("uid", uid.ToString());
|
|
HttpContext.Session.SetString("authorized", "true");
|
|
}
|
|
}
|
|
} |