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() { 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"; 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(); Result = await TestLogin.Content.ReadAsStringAsync();
}
base.StateHasChanged();
} }
} }
@@ -54,11 +54,22 @@
Loading = "Waiting for login response from server"; Loading = "Waiting for login response from server";
ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL; ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL;
ErrorMsgs = new List<string>(); ErrorMsgs = new List<string>();
if( string.IsNullOrEmpty(UserName) ) {
if( !string.IsNullOrEmpty(UserName) ) { ErrorMsgs.Add("The 'username' field is required");
if( !string.IsNullOrEmpty(Password) ) { }
if (Password.Length >= 6 ) { if( string.IsNullOrEmpty(Password) ) {
HttpResponseMessage TestLogin = await Http.PostAsJsonAsync("api/account/login", new MistoxWebsite.Shared.Account(){ UserName = UserName, PasswordHash = Password, EmailVerified = StayLoggedIn }); 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(); string result = await TestLogin.Content.ReadAsStringAsync();
Account? user = JsonConvert.DeserializeObject<Account>(result); Account? user = JsonConvert.DeserializeObject<Account>(result);
if (user == null ) { if (user == null ) {
@@ -68,19 +79,10 @@
} }
if ( string.IsNullOrEmpty(user.Error) ) { if ( string.IsNullOrEmpty(user.Error) ) {
ErrorMsgs.Add("Login Success"); ErrorMsgs.Add("Login Success");
Nav.NavigateTo("/", true); Nav.NavigateTo(ReturnURL, true);
} else { } else {
ErrorMsgs.Add(user.Error); 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 = ""; Loading = "";
base.StateHasChanged(); 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() { public async Task TryRegister() {
Loading = "Waiting for a response from the server"; Loading = "Waiting for a response from the server";
ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL; ReturnURL = string.IsNullOrEmpty(ReturnURL) ? "/" : ReturnURL;
ErrorMsgs = new List<string>(); ErrorMsgs = new List<string>();
MailAddress addr = new MailAddress(Email);
if ( !string.IsNullOrEmpty(Email) ){ if ( addr.Address != Email ){
if( CheckEmail( Email ) ) { ErrorMsgs.Add("Please check your email address");
if( !string.IsNullOrEmpty(UserName) ) { }
if( !string.IsNullOrEmpty(Password) ) { if (Password.Length < 6 ) {
if (Password.Length >= 6 ) { ErrorMsgs.Add("Password must be at least 6 Characters long");
HttpResponseMessage TestRegister = await Http.PostAsJsonAsync("api/account/register", new Account(){ }
UserName = UserName, if( string.IsNullOrEmpty(UserName) ) {
Email = Email, ErrorMsgs.Add("The 'username' field is required");
PasswordHash = Password, }
EmailVerified = false, 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>(); Account? user = await TestRegister.Content.ReadFromJsonAsync<Account>();
if ( string.IsNullOrEmpty(user?.Error) ) { if ( string.IsNullOrEmpty(user?.Error) ) {
ErrorMsgs.Add("Register Success"); ErrorMsgs.Add("Register Success");
Nav.NavigateTo("/", true); Nav.NavigateTo(ReturnURL, true);
} else { } else {
ErrorMsgs.Add( user.Error ); 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 = ""; Loading = "";
base.StateHasChanged(); base.StateHasChanged();
@@ -38,7 +38,6 @@
[Parameter] [Parameter]
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
public string ResetPwd { get; set; } = ""; public string ResetPwd { get; set; } = "";
public string NewPassword{ get; set; } = ""; public string NewPassword{ get; set; } = "";
public string RepeatPassword{ get; set; } = ""; public string RepeatPassword{ get; set; } = "";
@@ -52,9 +51,19 @@
protected async Task TryChange() { protected async Task TryChange() {
Result = "Waiting on response from server"; Result = "Waiting on response from server";
if (NewPassword.Length >= 6){ if (NewPassword != RepeatPassword){
if (NewPassword == RepeatPassword){ Result = "Passwords must match";
HttpResponseMessage TestLogin = await Http.PostAsJsonAsync("api/account/resetpassword", new Account(){ UserName = UserName, PasswordHash = NewPassword, Error = ResetPwd }); }
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(); string result = await TestLogin.Content.ReadAsStringAsync();
bool success = result == "true" ? true : false; bool success = result == "true" ? true : false;
if (success){ if (success){
@@ -64,11 +73,6 @@
}else{ }else{
Result = "Something is wrong"; 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; } = ""; public string Result{ get; set; } = "";
protected override async Task OnInitializedAsync() { 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>(); bool Answer = await Query.Content.ReadFromJsonAsync<bool>();
if (Answer == true ) { if (Answer == true ) {
Result = "Verified Email Successfully"; Result = "Verified Email Successfully";
@@ -41,7 +41,7 @@
@code { @code {
public MistoxWebsite.Shared.Account? _account = null; public MistoxWebsite.Shared.Database.Account? _account = null;
public int MaxFailedLogin = 0; public int MaxFailedLogin = 0;
public bool FailedLoginToggle = false; public bool FailedLoginToggle = false;
@@ -49,18 +49,19 @@
public async Task SubmitLoginLock() { public async Task SubmitLoginLock() {
if (_account != null ) { if (_account != null ) {
_account.SiteData.FailedPasswordLock = FailedLoginToggle; Dictionary<string, string> formData = new Dictionary<string, string>{
_account.SiteData.PasswordAttempts = MaxFailedLogin; { "UserName", _account.UserName },
_account.PasswordHash = ""; { "AccountLock", FailedLoginToggle.ToString() },
HttpResponseMessage SendVerifyEmail = await Http.PostAsJsonAsync("api/account/toggleAccountLock", _account); };
LoginCounterResult = await SendVerifyEmail.Content.ReadAsStringAsync(); HttpResponseMessage Query = await Http.PostAsync("api/account/toggleAccountLock", new FormUrlEncodedContent(formData) );
LoginCounterResult = await Query.Content.ReadAsStringAsync();
} }
} }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
HttpResponseMessage x = await Http.PostAsync("api/account/get", new StringContent("")); HttpResponseMessage x = await Http.PostAsync("api/account/get", new StringContent(""));
string body = await x.Content.ReadAsStringAsync(); string body = await x.Content.ReadAsStringAsync();
_account = JsonConvert.DeserializeObject<MistoxWebsite.Shared.Account>(body); _account = JsonConvert.DeserializeObject<MistoxWebsite.Shared.Database.Account>(body);
if (_account != null){ if (_account != null){
FailedLoginToggle = _account.SiteData.FailedPasswordLock; FailedLoginToggle = _account.SiteData.FailedPasswordLock;
MaxFailedLogin = _account.SiteData.PasswordAttempts; MaxFailedLogin = _account.SiteData.PasswordAttempts;
@@ -73,8 +74,11 @@
public async Task SendVerifyEmail() { public async Task SendVerifyEmail() {
if (_account != null){ if (_account != null){
HttpResponseMessage SendVerifyEmail = await Http.PostAsJsonAsync("api/account/sendverifyemail", new MistoxWebsite.Shared.Account(){ UserName = _account.UserName }); Dictionary<string, string> formData = new Dictionary<string, string>{
bool result = await SendVerifyEmail.Content.ReadFromJsonAsync<bool>(); { "UserName", _account.UserName },
};
HttpResponseMessage Query = await Http.PostAsync("api/account/sendverifyemail", new FormUrlEncodedContent(formData) );
bool result = await Query.Content.ReadFromJsonAsync<bool>();
if (result == true ) { if (result == true ) {
EmailSentResult = "Email Sent"; EmailSentResult = "Email Sent";
} else { } else {
@@ -108,8 +112,13 @@
return; return;
} }
if (_account != null){ if (_account != null){
HttpResponseMessage TryChangePassword = await Http.PostAsJsonAsync("api/account/changepassword", new MistoxWebsite.Shared.Account(){ UserName = _account.UserName, PasswordHash = CurPass, Error = NewPass1 }); Dictionary<string, string> formData = new Dictionary<string, string>{
bool resultText = await TryChangePassword.Content.ReadFromJsonAsync<bool>(); { "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 ) { if (resultText == true ) {
PasswordErrorText = "Password changed successfully"; PasswordErrorText = "Password changed successfully";
} else { } else {
@@ -119,12 +119,12 @@
} }
async Task confirmDeleteAccount() { async Task confirmDeleteAccount() {
HttpResponseMessage Delete = await Http.PostAsJsonAsync( "api/account/delete", new MistoxWebsite.Shared.Account(){ Dictionary<string, string> formData = new Dictionary<string, string>{
ID = Statics.User.ID, { "UserName", Statics.User.UserName },
UserName = Statics.User.Email, { "Password", Password },
PasswordHash = Password };
}); HttpResponseMessage Query = await Http.PostAsync("api/account/delete", new FormUrlEncodedContent(formData) );
string result = await Delete.Content.ReadAsStringAsync(); string result = await Query.Content.ReadAsStringAsync();
bool status = result == "true" ? true : false; bool status = result == "true" ? true : false;
if (status){ if (status){
await Http.PostAsync("api/account/logout", new StringContent("")); await Http.PostAsync("api/account/logout", new StringContent(""));
@@ -6,28 +6,11 @@
<div class="Big-Div"> <div class="Big-Div">
<div id="DirTree"> <div id="DirTree">
@if (output != null ) {
<ExplorerChild Title=@output.Path Children=output.Children PartialPath="\"></ExplorerChild>
}
</div> </div>
<span>@ErrorTxt</span>
</div> </div>
@code{ @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();
}
}
} }