[英]How can I authenticate user and how can I get first name and second name of user according to the login person?
Below is my login function, I want to change the following:下面是我的登录function,我想改一下:
please how can I do that any suggestion or examples?请问我该怎么做任何建议或例子?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(Customers customer)
{
if (ModelState.IsValid)
{
var user = await _context.Customers.SingleOrDefaultAsync(m => m.Email == customer.Email && m.Password == customer.Password);
if (user != null)
{
return RedirectToAction("Account", "Account");
}
else
{
ViewBag.error = "Login Failed";
return RedirectToAction("Login");
}
}
else
{
return RedirectToAction("Index", "Home");
}
}
Select Role,Password,FirstName,LastName from Users where Username=@Username and Password=@Password
if (Validate_User(Customers customer))
{
if (customer.Role == "1")
{
return View("AdminView");
}
else
{
return View("UserView");
}
ViewBag.FirstName=customer.FirstName;
ViewBag.LastName=customer.LastName;
}
else
{
//handle failed login
ViewBag.error = "Login Failed";
return RedirectToAction("Login");
}
Please refer Role Based Access请参考基于角色的访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.