Esempio n. 1
0
        //Използва се когато binding model-а е weakly-typed за да се намапне от view -то към параметрите на метода
        //public ActionResult DoLogin([Bind(Prefix="user")]UserDetails userDetails)
        public ActionResult DoLogin(UserDetails userDetails)
        {
            if (ModelState.IsValid)
            {
                UserDetailsBusinessLayer bol = new UserDetailsBusinessLayer();
                //New Code Start
                UserStatus status  = bol.GetUserValidity(userDetails);
                bool       IsAdmin = false;
                if (status == UserStatus.AuthenticatedAdmin)
                {
                    IsAdmin = true;
                }
                else if (status == UserStatus.AuthentucatedUser)
                {
                    IsAdmin = false;
                }
                else
                {
                    ModelState.AddModelError("CredentialError", "Invalid Username or Password");
                    return(View("Login"));
                }
                //FormsAuthentication.SetAuthCookie(userDetails.UserName, true);

                string sessionID = Guid.NewGuid().ToString();

                Session.Add(sessionID, IsAdmin);
                CreatingFormsAuthentication(userDetails, sessionID);

                RijndaelAlgorithm crypter = new RijndaelAlgorithm(userDetails);
                crypter.EncryptData();

                return(RedirectToAction("Index", "Employee"));
                //New Code End
            }
            else
            {
                return(View("Login"));
            }
        }
Esempio n. 2
0
        //Remote validation
        public JsonResult IsUserAvailable(string UserName)
        {
            UserDetailsBusinessLayer bol = new UserDetailsBusinessLayer();

            if (!bol.UserExists(UserName))//!WebSecurity.UserExists(username))
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            string suggestedUID = String.Format(CultureInfo.InvariantCulture,
                                                "{0} is not available.", UserName);

            for (int i = 1; i < 100; i++)
            {
                string altCandidate = UserName + i.ToString();
                if (!bol.UserExists(altCandidate))//!WebSecurity.UserExists(altCandidate))
                {
                    suggestedUID = String.Format(CultureInfo.InvariantCulture,
                                                 "{0} is not available. Try {1}.", UserName, altCandidate);
                    break;
                }
            }
            return(Json(suggestedUID, JsonRequestBehavior.AllowGet));
        }