C
C#2w ago
IamMax420

Log in system error

I was trying to make a log in system for my web app, but my code doesn't seem to work using AplikacjaWeb.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace AplikacjaWeb.Pages.Registration { public class RegistrationModel : PageModel { private readonly UserManager<UserModel> _userManager; private readonly SignInManager<UserModel> _signInManager; public RegistrationModel(UserManager<UserModel> userManager, SignInManager<UserModel> signInManager) { _userManager = userManager; _signInManager = signInManager; } [BindProperty] public Rejestracja /*Registration in english*/ Input { get; set; } public void OnGet() { } public async Task<IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = new UserModel { UserName = Input.Username, Email = Input.Email, PasswordHash = Input.Password }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent: false); return RedirectToPage("/Index"); } else { Console.WriteLine("Error"); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return RedirectToPage("/Index"); } } }
9 Replies
IamMax420
IamMax4202w ago
am I missing something?
Jimmacle
Jimmacle2w ago
$details
MODiX
MODiX2w ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Jimmacle
Jimmacle2w ago
"doesn't work" isn't specific
IamMax420
IamMax4202w ago
when the user enters their data into the registration form, it's not being sent to the database more specifically, when I hit the "submit" button, console prints out "error", which is what I did here if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent: false); return RedirectToPage("/Index"); } else { Console.WriteLine("Error"); } so it's basically !result.Succeeded
Jimmacle
Jimmacle2w ago
what does it mean if the result of CreateAsync isn't successful? do the docs say anything?
IamMax420
IamMax4202w ago
I mean it basically says that something went wrong trying to register also what docs do you mean?
Jimmacle
Jimmacle2w ago
the documentation for identity that you're presumably following to implement this
IamMax420
IamMax4202w ago
Ummmmmmm idk what you're talking about