0
I’m doing a project and trying to create a simple login method
I have the following class User
public class Usuario
{
public int Id { get; set; }
public string Nome { get; set; }
public string Login { get; set; }
public string Senha { get; set; }
public bool Admin { get; set; }
}
And the next login method
Metodo Get
[HttpGet]
public IActionResult Login()
{
return View("login");
}
Metodo post
[HttpPost]
public IActionResult Login(string login, string senha)
{
ViewBag.login = db.Usuario.Where(x => x.Login.Contains(login) && x.Senha.Contains(senha)).FirstOrDefault();
if (ViewBag.login != null)
{
return RedirectToAction("Index");
}
else
{
return View("login");
}
}
My question is, does he log in correctly, seeing if the login and password entered match the bank’s, but, I would also like to know if I can load the admin column information along with the login and password so that later I use this information in a view for example
Example: user 1, password 123, admin: false
If I log in normally with user 1 and 123 it pulls the admin false together
It would not be good practice to include all users in Viewbag. Choose something more interesting kind of serious information, like: Viewbag.Email = user.Email; Or something like that
– Edvaldo Farias
Great observation, Edvaldo. To pass the whole object it can use the heavily typed view. It would be better.
– Jaderson