Ejemplo n.º 1
0
        public ActionResult Index([Bind(Include = "username,password")] mLogin mLog)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    System.Collections.Generic.IEnumerable <System.Exception> errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));
                    ModelState.AddModelError("authenticationError", "User name or Password is wrong. Try it again");
                    return(View(mLog));
                }


                bool userLoging = ClsLogin.IsValidUser(mLog.username, mLog.password);
                if (userLoging == true)
                {
                    Web.HttpContext.Current.Session["Login"] = true;
                    FormsAuthentication.SetAuthCookie(ClsLogin.StrUserName, false);
                    Web.HttpContext.Current.Session["UserName"]  = ClsLogin.StrUserName;
                    Web.HttpContext.Current.Session["UserType"]  = ClsLogin.StrUserType;
                    Web.HttpContext.Current.Session["UserEmail"] = ClsLogin.StrUserEmail;
                    Web.HttpContext.Current.Session["UserPhone"] = ClsLogin.StrUserPhone;


                    return(RedirectToAction("Home", "Home"));
                }
                else
                {
                    ModelState.AddModelError("authenticationError", "User name or Password is wrong. Try it again");
                    return(View());
                }
            }
            catch (System.Exception)
            {
                throw;
            }
        }