Hello everyone,
I've been testing the CRM Demo App from Radzen but I'm stuck for a couple hours in the login.
I've already debug and it's entering in the If statement (where the environment is development and the user/password is admin).
My understanding is when he tries to redirect (~/).. it goes and moves back to the login page (assuming he is trying to reach the home). The OnInitializedAsync on Home page doesn't reach.. so I still don't understand what should be the problem.
Controllers/Account Controller:
[HttpPost]
public async Task<IActionResult> Login(string userName, string password)
{
if (env.EnvironmentName == "Development" && userName == "admin" && password == "admin")
{
var claims = new List<Claim>()
{
new Claim(ClaimTypes.Name, "admin"),
new Claim(ClaimTypes.Email, "admin")
};
roleManager.Roles.ToList().ForEach(r => claims.Add(new Claim(ClaimTypes.Role, r.Name)));
await signInManager.SignInWithClaimsAsync(new ApplicationUser { UserName = userName, Email = userName }, isPersistent: false, claims);
return Redirect("~/");
}
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
{
var result = await signInManager.PasswordSignInAsync(userName, password, false, false);
if (result.Succeeded)
{
return Redirect("~/");
}
}
return Redirect("~/Login?error=Invalid user or password");
}
Login (razor):
<form method="post" action="account/login">
<RadzenContent Container="main">
<ChildContent>
<RadzenHeading Size="H1" Text="@L["pageTitle.Text"]">
</RadzenHeading>
<RadzenTemplateForm Action="/Account/Login" Method="post" TItem="dynamic">
<ChildContent>
<RadzenLabel Component="Username" style="display: block; margin-top: 16px" Text="@L["labelUsername.Text"]">
</RadzenLabel>
<RadzenTextBox style="width: 100%" Name="Username">
</RadzenTextBox>
<RadzenLabel Component="Password" style="display: block; margin-top: 16px" Text="@L["labelPassword.Text"]">
</RadzenLabel>
<RadzenPassword style="width: 100%" Name="Password">
</RadzenPassword>
<RadzenButton ButtonType="ButtonType.Submit" Icon="exit_to_app" style="margin-top: 32px; width: 100%" Text="@L["btnLogin.Text"]">
</RadzenButton>
</ChildContent>
</RadzenTemplateForm>
</ChildContent>
</RadzenContent>
</form>