PTMagic/Monitor/Pages/SetupPassword.cshtml.cs

56 lines
1.7 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();
string encryptedOldPassword = null;
if (OldPassword != null)
{
2021-02-19 22:14:01 +01:00
encryptedOldPassword = EncryptionHelper.Encrypt(OldPassword);
if (!Password.Equals(PasswordConfirm) || !encryptedOldPassword.Equals(PTMagicConfiguration.SecureSettings.MonitorPassword) && System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory().Split("Monitor")[0] + "settings.secure.json"))
{
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "SetupPassword");
}
else if (ModelState.IsValid)
{
PTMagicConfiguration.WriteSecureSettings(Password);
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-19 22:14:01 +01:00
if (!Password.Equals(PasswordConfirm) && !System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory().Split("Monitor")[0] + "settings.secure.json"))
{
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "SetupPassword");
}
else if (ModelState.IsValid)
{
PTMagicConfiguration.WriteSecureSettings(Password);
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "Login");
}
2018-05-22 10:11:50 +02:00
}
}
}
}