YAFLogo

McHine
  • McHine
  • 52.6% (Neutral)
  • YAF Forumling Topic Starter YAF Version: 4.0.8 beta
a month ago
Hi,

Trying to allow users to login from a sidepanel in my layout, but can't seem to get the code for the method right.

probably missing something obvious, but cant see it in the source (using the nuget in my project so trawling the github (which is slow)) and can't see anything that looks recent with a few like this from the last c10-12 years.

[color=var(--bs-body-color)][font=system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]without rambling too much.[/font][/color]

here's what i have

  private async Task LoginClick()

  {

      try

      {

          var baseUri = NavigationManager.BaseUri.EndsWith("/")

              ? NavigationManager.BaseUri

              : $"{NavigationManager.BaseUri}/";

          // Use the LoginBox controller endpoint instead of Account/Login

          var loginUrl = $"{baseUri}LoginBox/SignIn";

          // Create form data matching YAF's expected format

          var formData = new MultipartFormDataContent

          {

              { new StringContent(username), "UserName" },

              { new StringContent(password), "Password" },

              { new StringContent(rememberMe.ToString()), "RememberMe" }

          };

          Console.WriteLine($"Attempting login at: {loginUrl}");

          var response = await HttpClient.PostAsync(loginUrl, formData);

          if (response.IsSuccessStatusCode)

          {

              NavigationManager.NavigateTo(NavigationManager.Uri, true);

          }

          else

          {

              var error = await response.Content.ReadAsStringAsync();

              Console.WriteLine($"Login failed with status {response.StatusCode}: {error}");

              StateHasChanged();

          }

      }

      catch (Exception ex)

      {

          Console.WriteLine($"Login error: {ex.Message}");

      }

  }

probably trying to mush together a whole lot of different solutions, if i can get pointed to the right code that would also help.

Thanks a million looking forwards to showing you all what i've got so far.

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
McHine
  • McHine
  • 52.6% (Neutral)
  • YAF Forumling Topic Starter YAF Version: 4.0.8 beta
a month ago

Thanks Watcha.

Appreciate the fast replty.

Managed to get close, like password pass and fail, but issues with blazor and http connections

"headers are read-only, response has already started." eventually found out that's pretty baked in an unavoidable issue.

After another day on it, I'm linking to the cshtml page and calling it done for now.