Exemple #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            var tutor = _tutorRepository.Filter(y => y.User.Email == model.UserEmail).FirstOrDefault();

            if (tutor == null)
            {
                if (_sessionManagementService.LogIn(model.UserEmail, model.Password, model.RememberMe))
                {
                    var user = _userRepository.Filter(x => x.Email == model.UserEmail).FirstOrDefault();
                    var needsEducationLevel = false;
                    var hasEducationLevel   = false;

                    if (user != null)
                    {
                        if (user.Role.Name == "Director")
                        {
                            needsEducationLevel = true;
                            var educationLevelRepo = new DependecyFinder <IEducationLevelRepository>().GetDependency();
                            hasEducationLevel = educationLevelRepo.Filter(x => x.Director.Id == user.Id).Include(level => level.Director).Any();
                        }
                        if (user.IsActive && (!needsEducationLevel || hasEducationLevel))
                        {
                            return(user.IsUsingDefaultPassword
                                ? RedirectToAction("ChangePassword")
                                : String.IsNullOrWhiteSpace(returnUrl)
                                ? RedirectToAction("Index", "Home")
                                : RedirectToLocal(returnUrl));
                        }
                    }
                    _sessionManagementService.LogOut();
                    TempData["loginModelError"] = "Cuenta no habilitada o no funcional. Para mas informacion, contactar al administrador.";
                    return(RedirectToAction("Login", new{ returnUrl }));
                }
                ModelState.AddModelError("", "El nombre de usuario o la contraseña especificados son incorrectos.");
                return(View(model));
            }
            ModelState.AddModelError("", "El usuario no tiene privilegios para entrar a esta pagina");
            return(View(model));
            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
        }
 public ActionResult LogOut()
 {
     _sessionManagementService.LogOut();
     return(RedirectToAction("Index", "Home"));
 }
Exemple #3
0
 public ActionResult Logout()
 {
     _sessionManagement.LogOut();
     return(RedirectToAction("Index"));
 }