Ejemplo n.º 1
0
 // GET: Studeng
 //[Filters.SessionUserParameter]
 public ActionResult Index()
 {
     Models.LoginUser loginUser = (Session["venue"] as Models.LoginUser);//为Action设置参数
     if (loginUser == null)
     {
     }
     else
     {
     }
     ViewBag.venueId = 1;
     return(View());
 }
Ejemplo n.º 2
0
        public void LoginInvalidData()
        {
            Controllers.LoginController login = new Controllers.LoginController();
            Models.LoginUser            usr   = new Models.LoginUser();
            usr.Username = "******";
            usr.Password = "******";
            usr.Domain   = "example.com";

            var result = login.Login(usr) as ViewResult;

            Assert.AreEqual("AUTH FAILED", result.ViewData["Error"]);
        }
Ejemplo n.º 3
0
        public void LoginData()
        {
            Controllers.LoginController login = new Controllers.LoginController();
            Models.LoginUser            usr   = new Models.LoginUser();
            usr.Username = "******";
            usr.Password = "******";
            usr.Domain   = "example.com";

            var result = login.Login(usr) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
Ejemplo n.º 4
0
        //
        // GET: /App/

        public ActionResult Index()
        {
            string userData = "";

            if (Request.IsAuthenticated)
            {
                Models.LoginUser user = new Models.LoginUser();
                user.Username        = User.Identity.Name;
                userData             = user.FetchUserDetails();
                ViewData["USERDATA"] = userData;
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult Login(Models.LoginUser user)
        {
            if (ModelState.IsValid)
            {
                if (user.IsAdmin(user.Email, user.Password))
                {
                    //Admin Login
                    FormsAuthentication.SetAuthCookie(user.Email, user.RememberMe);
                    return(RedirectToAction("AdminLoggedIn", "User"));
                }
                else if (user.IsValid(user.Email, user.Password))
                {
                    //login successful
                    FormsAuthentication.SetAuthCookie(user.Email, user.RememberMe);
                    return(RedirectToAction("LoggedIn", "User"));
                }
                else
                {
                    //incorrect login information

                    var  entities = new Job_Candidate_Application_Entities();
                    bool model    = entities.Tbl_Users.Any(u => u.Email_Id == user.Email);

                    if (model)
                    {
                        ModelState.AddModelError("", "Account is not active");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Login data is incorrect!");
                    }
                }
            }

            /*
             * ****error tracing*****
             */
            //else
            //{
            //    var errors = ModelState.Select(x => x.Value.Errors)
            //               .Where(y => y.Count > 0)
            //               .ToList();
            //}
            return(View(user));
        }
Ejemplo n.º 6
0
 public ActionResult Login(Models.LoginUser user)
 {
     if (ModelState.IsValid)
     {
         if (user.Authenticate(user.Username, user.Password, user.Domain))
         {
             FormsAuthentication.SetAuthCookie(user.Username, user.RememberMe);
             TempData["USER"] = user;
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Error", "");
             ViewData["Error"] = "AUTH FAILED";
         }
     }
     return(View(user));
 }
Ejemplo n.º 7
0
 //[ValidateAntiForgeryToken]
 //[Authorize]
 public ActionResult Login(Models.LoginUser o)
 {
     if (!ModelState.IsValid)
     {
         return(View(o));
     }
     DAO.DbHandler.CheckAndSetDb();
     Models.User validateUser = BAL.AccessBO.LoginAuthentication(o.LoginName, o.Password);
     if (validateUser == null)
     {
         ModelState.AddModelError(string.Empty, "Cannot find user or wrong password.");
         return(View(o));
     }
     /// https://www.aspsnippets.com/Articles/ASPNet-MVC-Keep-User-Logged-in-and-automatically-Login-User-using-Forms-Authentication-and-Cookies.aspx
     System.Web.Security.FormsAuthentication.SetAuthCookie(validateUser.LoginName, false);
     Session["UserId"]    = validateUser.UserId.ToString();
     Session["LoginName"] = validateUser.LoginName;
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 8
0
 public ActionResult Index()
 {
     Models.LoginUser user = new Models.LoginUser();
     if (Request.IsAuthenticated)
     {
         if (TempData["USER"] != null)
         {
             user = (Models.LoginUser)TempData["USER"];
         }
         else
         {
             user.Username = User.Identity.Name;
         }
     }
     else
     {
         return(RedirectToAction("Login"));
     }
     return(View(user));
 }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            const string key = "venueId";

            //if (filterContext.ActionParameters.ContainsKey(key))
            {
                Models.LoginUser loginUser = (filterContext.HttpContext.Session["venue"] as Models.LoginUser);//为Action设置参数
                if (loginUser == null)
                {
                    //todo
                    //filterContext.HttpContext.Response.Redirect("/");
                    filterContext.ActionParameters[key] = 1;// loginUser.VenueInfo.VenueID;
                }
                else
                {
                    filterContext.ActionParameters[key] = loginUser.VenueInfo.VenueID;
                }
            }

            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 10
0
        public ActionResult Login(FormCollection formCollection)
        {
            string username = formCollection["username"];
            string password = formCollection["password"];

            TempData["usernameInput"] = username;
            TempData["passwordInput"] = password;

            ILoginUserBLL bLL       = new LoginUserBLL();
            LoginUser     loginUser = bLL.GetLoginUserByUsername(username);



            if (loginUser == null)
            {
                TempData["error"] = "Username Error";
                return(RedirectToAction("Index"));
            }
            else
            {
                Models.LoginUser viewLoginUser = new Models.LoginUser()
                {
                    Id        = loginUser.Id,
                    Username  = loginUser.Username,
                    Password  = loginUser.Password,
                    RoleLevel = loginUser.RoleLevel
                };

                if (loginUser.Password == password)
                {
                    Session["loginUser"] = viewLoginUser;
                    return(RedirectToAction("Index", "Main"));
                }
                else
                {
                    TempData["error"] = "Password Error";
                    return(RedirectToAction("Index"));
                }
            }
        }
Ejemplo n.º 11
0
        public ActionResult Login(Models.LoginUser user, FormCollection form)
        {
            try
            {
                user.Role = Convert.ToInt32(form.AllKeys.ElementAt(2));
                Console.WriteLine("Hello");

                if (user.Role == 1)
                {
                    using (var entity = new Data.TestEntities())
                    {
                        user.Student = entity.studenci.Where(x => x.nr_album == user.LOGIN).FirstOrDefault();
                    }

                    if (user.Student != null)
                    {
                        return(RedirectToAction("_initStudent", new RouteValueDictionary(
                                                    new { controller = "Students", action = "_initStudent", Id = user.Student.id_student })));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else if (user.Role == 2)
                {
                    using (var entity = new Data.TestEntities())
                    {
                        user.Teacher = entity.prowadzacy.Where(x => x.haslo == user.LOGIN).FirstOrDefault();
                    }

                    if (user.Teacher != null)
                    {
                        return(RedirectToAction("_initTeacher", new RouteValueDictionary(
                                                    new { controller = "Teacher", action = "_initTeacher", Id = user.Teacher.id_prow })));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    using (var entity = new Data.TestEntities())
                    {
                        user.Supervisor = entity.administrators.Where(x => x.login == user.LOGIN && x.pass == user.PASS).FirstOrDefault();
                    }

                    if (user.Supervisor != null)
                    {
                        return(RedirectToAction("_initSupervisor", new RouteValueDictionary(
                                                    new { controller = "Supervisor", action = "_initSupervisor", Id = user.Supervisor.id_admin })));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception) { return(RedirectToAction("Index")); }
        }