Exemplo n.º 1
0
 public ActionResult Login([Bind(Include = "UserName, Password")] LoginViewModel loginViewModel)
 {
     if (ModelState.IsValid)
     {
         UserLoginDTO userLoginDTO = _LoginMapper.Map <LoginViewModel, UserLoginDTO>(loginViewModel);
         try
         {
             UserBasicDTO loggedInUserDTO = userBusinessContext.LoginUser(userLoginDTO);
             Session["UserID"] = loggedInUserDTO.ID;
             if (Request.UrlReferrer.ToString() == "a")
             {
                 return(null);
             }
             return(RedirectToAction("Index", "Home"));
         }
         catch (InvalidLoginException ex)
         {
             ModelState.AddModelError("", "Invalid Login Credentials.");
             return(View(loginViewModel));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", "Something went wrong, Please try again.");
             return(View("Error"));
         }
     }
     return(View(loginViewModel));
 }
Exemplo n.º 2
0
 public ActionResult Login([Bind(Include = "Email, Password")] LoginViewModel loginViewModel)
 {
     if (ModelState.IsValid)
     {
         UserLoginDTO loggedInUserCredentialsDTO = LoginMapper.Map <LoginViewModel, UserLoginDTO>(loginViewModel);
         try
         {
             UserInfoDTO loggedInUserInfoDTO = UserBusinessContextObject.LoginUser(loggedInUserCredentialsDTO);
             Session["UserID"] = loggedInUserInfoDTO.ID;
             return(RedirectToAction("Index", "Home"));
         }
         catch (InvalidLoginException ex)
         {
             ModelState.AddModelError("", "Invalid Login Credentials");
             return(View(loginViewModel));
         }
         catch (IncorrectPasswordException ex)
         {
             ModelState.AddModelError("", "Incorrect password");
             return(View(loginViewModel));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", "Something Went wrong. Please Try again later");
             return(View("Error"));
         }
     }
     return(View(loginViewModel));
 }
Exemplo n.º 3
0
        public ActionResult Index([Bind(Include = " Email, Password")] LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                UserLoginDTO userLoginDTO = LoginMapper.Map <LoginModel, UserLoginDTO>(loginModel);
                try
                {
                    UserBasicDTO loggedInUserDTO = userBusinessContext.LoginUser(userLoginDTO);
                    Session["UserID"] = loggedInUserDTO.ID;
                    Session["name"]   = loggedInUserDTO.Name;
                    ViewBag.MSG       = loggedInUserDTO.ID;
                    Response.Buffer   = true;

                    Response.CacheControl = "no-cache";
                    return(RedirectToAction("Index", "Home"));
                }
                catch (InvalidLoginException ex)
                {
                    ModelState.AddModelError("", "Invalid Login Credentials.");
                    return(View(loginModel));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Something went wrong, Please try again.");
                    return(View("Error"));
                }
            }
            return(View(loginModel));
        }