Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public async Task<ActionResult> Login(LoginModel details)
  2. {
  3. UserModel user = await userManager.FindUserByEmailAsync(details.Email);
  4. bool findingUser = await userManager.CheckUserPasswordAsync(user, details.Password);
  5.  
  6. if (!findingUser)
  7. {
  8. ModelState.AddModelError("", "Не верно указано имя или пароль");
  9. }
  10. else
  11. {
  12. ClaimsIdentity identityClaims = await userManager.CreateUserIdentityAsync(user);
  13.  
  14. if (identityClaims == null)
  15. {
  16. return View(details);
  17. }
  18.  
  19. signInManager.UserSignOut(DefaultAuthenticationTypes.ApplicationCookie);
  20. signInManager.UserSignIn(identityClaims);
  21.  
  22. return Redirect(GetRedirectUrl(details.ReturnUrl));
  23. }
  24. return View(details);
  25. }
  26.  
  27. public async Task<ClaimsIdentity> CreateUserIdentityAsync(UserModel user)
  28. {
  29. ClaimsIdentity identResult = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
  30. return identResult;
  31. }
  32.  
  33. public class UserModel : IdentityUser
  34. {
  35. public UserModel()
  36. {
  37.  
  38. }
  39.  
  40. public int Ages { get; set; }
  41.  
  42. public string Street { get; set; }
  43.  
  44. public int HomeNumber { get; set; }
  45.  
  46. public int? ApartmentNumber { get; set; }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement