Ejemplo n.º 1
0
        public ActionResult Logon(String userName, String password)
        {
            Entities.Concrete.User user = _context.Users.FirstOrDefault(u => u.Password == password && u.Username == userName);

            if (user != null)
            {
                Session["CurrentUser"] = user;
                return(RedirectToAction(actionName: "ListUser", controllerName: "User"));
            }

            else
            {
                ViewBag.Message = "Giriş Hatalı!";
                return(View());
            }
        }
Ejemplo n.º 2
0
 public IActionResult Login(LoginViewModel loginViewModel)
 {
     Entities.Concrete.User user = null;
     try
     {
         loginViewModel.Username ??= "";
         loginViewModel.Password ??= "";
         var tempUser = new Entities.Concrete.User
         {
             Username = loginViewModel.Username,
             Password = loginViewModel.Password
         };
         user = _userManager.Login(tempUser);
         if (user != null)
         {
             var identity = new ClaimsIdentity(
                 new[]
             {
                 new Claim("userid", user.Id.ToString()),
                 new Claim("username", user.Username),
             },
                 "cookie"
                 );
             ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
             HttpContext.SignInAsync("SecurityScheme", claimsPrincipal);
             _logger.LogInformation("Logged in. Username:"******" DateTime:" + DateTime.Now);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("Error", "Username or password is invalid.");
             return(View());
         }
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError("Error", ex.Message);
         return(View());
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(Error());
     }
 }
 private string[] GetUserRolesFromDatabase(Entities.Concrete.User user)
 {
     return(_userService.GetUserRoles(user).Select(u => u.RoleName).ToArray());
 }