Update client to use forms

This commit is contained in:
2025-06-19 16:49:43 -07:00
parent 34d3d047d2
commit 059c755d14
8 changed files with 126 additions and 135 deletions
@@ -34,10 +34,21 @@
}
public async Task TrySendCode() {
MailAddress addr = new MailAddress(Email);
if ( addr.Address != Email ){
Result = "Enter a valid email address";
}else{
Result = "";
}
if (string.IsNullOrEmpty(Result)){
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "Email", Email }
};
Result = "Waiting on response from server";
HttpResponseMessage TestLogin = await Http.PostAsJsonAsync("api/account/sendresetpassword", new Account(){ Email = Email });
HttpResponseMessage TestLogin = await Http.PostAsync("api/account/sendresetpassword", new FormUrlEncodedContent(formData) );
Result = await TestLogin.Content.ReadAsStringAsync();
}
base.StateHasChanged();
}
}
@@ -54,11 +54,22 @@
Loading = "Waiting for login response from server";
ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL;
ErrorMsgs = new List<string>();
if( !string.IsNullOrEmpty(UserName) ) {
if( !string.IsNullOrEmpty(Password) ) {
if (Password.Length >= 6 ) {
HttpResponseMessage TestLogin = await Http.PostAsJsonAsync("api/account/login", new MistoxWebsite.Shared.Account(){ UserName = UserName, PasswordHash = Password, EmailVerified = StayLoggedIn });
if( string.IsNullOrEmpty(UserName) ) {
ErrorMsgs.Add("The 'username' field is required");
}
if( string.IsNullOrEmpty(Password) ) {
ErrorMsgs.Add("The 'password' field is required");
}
if (Password.Length < 6 ) {
ErrorMsgs.Add("Password must be at least 6 Characters long");
}
if (ErrorMsgs.Count == 0){
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", UserName },
{ "PasswordHash", Password },
{ "StayLoggedIn", StayLoggedIn.ToString() }
};
HttpResponseMessage TestLogin = await Http.PostAsync("api/account/login", new FormUrlEncodedContent(formData) );
string result = await TestLogin.Content.ReadAsStringAsync();
Account? user = JsonConvert.DeserializeObject<Account>(result);
if (user == null ) {
@@ -68,19 +79,10 @@
}
if ( string.IsNullOrEmpty(user.Error) ) {
ErrorMsgs.Add("Login Success");
Nav.NavigateTo("/", true);
Nav.NavigateTo(ReturnURL, true);
} else {
ErrorMsgs.Add(user.Error);
}
Loading = "";
} else {
ErrorMsgs.Add("Password must be at least 6 Characters long");
}
} else {
ErrorMsgs.Add("The 'password' field is required");
}
} else{
ErrorMsgs.Add("The 'username' field is required");
}
Loading = "";
base.StateHasChanged();
@@ -52,62 +52,40 @@
}
}
public bool CheckEmail(string email ) {
int ATcount = 0;
int DOTcount = 0;
char[] cmail = email.ToArray();
foreach(char cur in cmail ) {
if(cur == '@' ) {
ATcount += 1;
}else if(cur == '.' ) {
DOTcount += 1;
}
}
if (ATcount == 1 && DOTcount >= 1 ) {
return true;
}
return false;
}
public async Task TryRegister() {
Loading = "Waiting for a response from the server";
ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL;
ErrorMsgs = new List<string>();
if ( !string.IsNullOrEmpty(Email) ){
if( CheckEmail( Email ) ) {
if( !string.IsNullOrEmpty(UserName) ) {
if( !string.IsNullOrEmpty(Password) ) {
if (Password.Length >= 6 ) {
HttpResponseMessage TestRegister = await Http.PostAsJsonAsync("api/account/register", new Account(){
UserName = UserName,
Email = Email,
PasswordHash = Password,
EmailVerified = false,
});
MailAddress addr = new MailAddress(Email);
if ( addr.Address != Email ){
ErrorMsgs.Add("Please check your email address");
}
if (Password.Length < 6 ) {
ErrorMsgs.Add("Password must be at least 6 Characters long");
}
if( string.IsNullOrEmpty(UserName) ) {
ErrorMsgs.Add("The 'username' field is required");
}
if( string.IsNullOrEmpty(Password) ) {
ErrorMsgs.Add("The 'password' field is required");
}
if ( string.IsNullOrEmpty(Email) ){
ErrorMsgs.Add("The 'email' field is required");
}
if (ErrorMsgs.Count == 0){
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "Email", Email },
{ "UserName", UserName },
{ "PasswordHash", Password },
};
HttpResponseMessage TestRegister = await Http.PostAsync("api/account/register", new FormUrlEncodedContent(formData) );
Account? user = await TestRegister.Content.ReadFromJsonAsync<Account>();
if ( string.IsNullOrEmpty(user?.Error) ) {
ErrorMsgs.Add("Register Success");
Nav.NavigateTo("/", true);
Nav.NavigateTo(ReturnURL, true);
} else {
ErrorMsgs.Add( user.Error );
}
Loading = "";
}else{
ErrorMsgs.Add("Password must be at least 6 Characters long");
}
}else{
ErrorMsgs.Add("The 'password' field is required");
}
}else{
ErrorMsgs.Add("The 'username' field is required");
}
}else{
ErrorMsgs.Add("Please check your email address");
}
}else{
ErrorMsgs.Add("The 'email' field is required");
}
Loading = "";
base.StateHasChanged();
@@ -38,7 +38,6 @@
[Parameter]
[SupplyParameterFromQuery]
public string ResetPwd { get; set; } = "";
public string NewPassword{ get; set; } = "";
public string RepeatPassword{ get; set; } = "";
@@ -52,9 +51,19 @@
protected async Task TryChange() {
Result = "Waiting on response from server";
if (NewPassword.Length >= 6){
if (NewPassword == RepeatPassword){
HttpResponseMessage TestLogin = await Http.PostAsJsonAsync("api/account/resetpassword", new Account(){ UserName = UserName, PasswordHash = NewPassword, Error = ResetPwd });
if (NewPassword != RepeatPassword){
Result = "Passwords must match";
}
if (NewPassword.Length < 6){
Result = "Password must be at least 6 Characters long";
}
if (string.IsNullOrEmpty(Result)){
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", UserName },
{ "NewPassword", NewPassword },
{ "ResetToken", ResetPwd },
};
HttpResponseMessage TestLogin = await Http.PostAsync("api/account/resetpassword", new FormUrlEncodedContent(formData) );
string result = await TestLogin.Content.ReadAsStringAsync();
bool success = result == "true" ? true : false;
if (success){
@@ -64,11 +73,6 @@
}else{
Result = "Something is wrong";
}
}else{
Result = "Passwords must match";
}
}else{
Result = "Password must be at least 6 Characters long";
}
}
@@ -26,7 +26,11 @@
public string Result{ get; set; } = "";
protected override async Task OnInitializedAsync() {
HttpResponseMessage Query = await Http.PostAsJsonAsync("api/account/verifyemail", new Account(){ UserName = UserName, PasswordHash = Guid });
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", UserName },
{ "EmailToken", Guid },
};
HttpResponseMessage Query = await Http.PostAsync("api/account/verifyemail", new FormUrlEncodedContent(formData) );
bool Answer = await Query.Content.ReadFromJsonAsync<bool>();
if (Answer == true ) {
Result = "Verified Email Successfully";
@@ -41,7 +41,7 @@
@code {
public MistoxWebsite.Shared.Account? _account = null;
public MistoxWebsite.Shared.Database.Account? _account = null;
public int MaxFailedLogin = 0;
public bool FailedLoginToggle = false;
@@ -49,18 +49,19 @@
public async Task SubmitLoginLock() {
if (_account != null ) {
_account.SiteData.FailedPasswordLock = FailedLoginToggle;
_account.SiteData.PasswordAttempts = MaxFailedLogin;
_account.PasswordHash = "";
HttpResponseMessage SendVerifyEmail = await Http.PostAsJsonAsync("api/account/toggleAccountLock", _account);
LoginCounterResult = await SendVerifyEmail.Content.ReadAsStringAsync();
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", _account.UserName },
{ "AccountLock", FailedLoginToggle.ToString() },
};
HttpResponseMessage Query = await Http.PostAsync("api/account/toggleAccountLock", new FormUrlEncodedContent(formData) );
LoginCounterResult = await Query.Content.ReadAsStringAsync();
}
}
protected override async Task OnInitializedAsync() {
HttpResponseMessage x = await Http.PostAsync("api/account/get", new StringContent(""));
string body = await x.Content.ReadAsStringAsync();
_account = JsonConvert.DeserializeObject<MistoxWebsite.Shared.Account>(body);
_account = JsonConvert.DeserializeObject<MistoxWebsite.Shared.Database.Account>(body);
if (_account != null){
FailedLoginToggle = _account.SiteData.FailedPasswordLock;
MaxFailedLogin = _account.SiteData.PasswordAttempts;
@@ -73,8 +74,11 @@
public async Task SendVerifyEmail() {
if (_account != null){
HttpResponseMessage SendVerifyEmail = await Http.PostAsJsonAsync("api/account/sendverifyemail", new MistoxWebsite.Shared.Account(){ UserName = _account.UserName });
bool result = await SendVerifyEmail.Content.ReadFromJsonAsync<bool>();
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", _account.UserName },
};
HttpResponseMessage Query = await Http.PostAsync("api/account/sendverifyemail", new FormUrlEncodedContent(formData) );
bool result = await Query.Content.ReadFromJsonAsync<bool>();
if (result == true ) {
EmailSentResult = "Email Sent";
} else {
@@ -108,8 +112,13 @@
return;
}
if (_account != null){
HttpResponseMessage TryChangePassword = await Http.PostAsJsonAsync("api/account/changepassword", new MistoxWebsite.Shared.Account(){ UserName = _account.UserName, PasswordHash = CurPass, Error = NewPass1 });
bool resultText = await TryChangePassword.Content.ReadFromJsonAsync<bool>();
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", _account.UserName },
{ "OldPassword", CurPass },
{ "NewPassword", NewPass1 }
};
HttpResponseMessage Query = await Http.PostAsync("api/account/changepassword", new FormUrlEncodedContent(formData) );
bool resultText = await Query.Content.ReadFromJsonAsync<bool>();
if (resultText == true ) {
PasswordErrorText = "Password changed successfully";
} else {
@@ -119,12 +119,12 @@
}
async Task confirmDeleteAccount() {
HttpResponseMessage Delete = await Http.PostAsJsonAsync( "api/account/delete", new MistoxWebsite.Shared.Account(){
ID = Statics.User.ID,
UserName = Statics.User.Email,
PasswordHash = Password
});
string result = await Delete.Content.ReadAsStringAsync();
Dictionary<string, string> formData = new Dictionary<string, string>{
{ "UserName", Statics.User.UserName },
{ "Password", Password },
};
HttpResponseMessage Query = await Http.PostAsync("api/account/delete", new FormUrlEncodedContent(formData) );
string result = await Query.Content.ReadAsStringAsync();
bool status = result == "true" ? true : false;
if (status){
await Http.PostAsync("api/account/logout", new StringContent(""));
@@ -6,28 +6,11 @@
<div class="Big-Div">
<div id="DirTree">
@if (output != null ) {
<ExplorerChild Title=@output.Path Children=output.Children PartialPath="\"></ExplorerChild>
}
</div>
<span>@ErrorTxt</span>
</div>
@code{
public string ErrorTxt = "";
public DirObj? output = null;
protected override async void OnInitialized() {
try {
byte[] resultBody = await (await Http.PostAsync( "api/product/showdownloads", new StringContent("") )).Content.ReadAsByteArrayAsync();
string JsonData = Encoding.UTF8.GetString(resultBody);
output = JsonConvert.DeserializeObject<DirObj>( JsonData );
base.StateHasChanged();
} catch( Exception e ) {
ErrorTxt = "Error : " + e.ToString();
}
}
}