예제 #1
0
        public ActionResult Login(LoginViewModel lg, string returnURl)
        {
            Connection ld = new Connection();

            loginDAO = new LoginDAO();
            ld.conecta();

            if (!ModelState.IsValid)
            {
                return(View(lg));
            }

            else
            {
                Login lb = loginDAO.AutenticaUsuario(lg.Username, lg.Password);
                if (lb != null)
                {
                    FormsAuthentication.SetAuthCookie(lg.Username, false);
                    Funcionario ff = loginDAO.userInformation(lb.ID);
                    Session["Name"] = ff.Nome;
                    Session["Role"] = lb.Role;
                    if (Url.IsLocalUrl(returnURl))
                    {
                        return(Redirect(returnURl));
                    }

                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                else
                {
                    lg.invalidCredentials = true;
                    return(View(lg));
                }
            }
        }