PTMagic/Monitor/Pages/SetupPassword.cshtml.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2018-05-22 10:11:50 +02:00
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Core.Main;
2021-02-19 22:14:01 +01:00
using Core.Helper;
2018-05-22 10:11:50 +02:00
namespace Monitor.Pages
{
public class SetupPasswordModel : _Internal.BasePageModel
{
2018-05-22 10:11:50 +02:00
public string ValidationMessage = "";
public void OnGet()
{
2018-05-22 10:11:50 +02:00
base.PreInit();
}
2021-02-19 22:14:01 +01:00
public void OnPost(string OldPassword, string Password, string PasswordConfirm)
{
2021-02-19 22:14:01 +01:00
base.PreInit();
2021-02-20 20:26:22 +01:00
ValidationMessage = "Test";
2021-02-19 22:14:01 +01:00
string encryptedOldPassword = null;
if (OldPassword != null)
{
2021-02-19 22:14:01 +01:00
encryptedOldPassword = EncryptionHelper.Encrypt(OldPassword);
2021-02-27 07:05:12 +01:00
if (!Password.Equals(PasswordConfirm) || !encryptedOldPassword.Equals(PTMagicConfiguration.SecureSettings.MonitorPassword) && System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory().Split("Monitor")[0] + "/settings.secure.json"))
2021-02-19 22:14:01 +01:00
{
2021-02-20 20:26:22 +01:00
ValidationMessage = "Old Password wrong or new Password does not match with confirmation";
2021-02-19 22:14:01 +01:00
}
else if (ModelState.IsValid)
{
PTMagicConfiguration.WriteSecureSettings(Password);
2021-02-20 20:26:22 +01:00
ValidationMessage = "";
2021-02-19 22:14:01 +01:00
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "Login");
}
2018-05-22 10:11:50 +02:00
}
2021-02-19 22:14:01 +01:00
else
{
2021-02-27 07:05:12 +01:00
if (!Password.Equals(PasswordConfirm) && !System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory().Split("Monitor")[0] + "/settings.secure.json"))
2021-02-19 22:14:01 +01:00
{
2021-02-20 20:26:22 +01:00
ValidationMessage = "New Password does not match with confirmation";
2021-02-19 22:14:01 +01:00
}
else if (ModelState.IsValid)
{
PTMagicConfiguration.WriteSecureSettings(Password);
2021-02-20 20:26:22 +01:00
ValidationMessage = "";
2021-02-19 22:14:01 +01:00
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "Login");
}
2018-05-22 10:11:50 +02:00
}
}
}
}