Пример #1
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                string email = model.UserName;
                string password = model.Password;
                var userDetails = new UserDetails();
                var result = loginService.GetUserDetails(email, password, ref userDetails);
                switch (result)
                {
                    case UserLoginResult.Successful:
                        FormsAuthentication.SetAuthCookie(userDetails.Username,false);

                        System.Web.HttpContext.Current.Cache["AdminInfo"] = userDetails;
                        System.Web.HttpContext.Current.Cache.Remove("ItemDetails");
                        return RedirectToAction("Dashboard", "Home");

                    case UserLoginResult.WrongPassword:
                        ModelState.AddModelError("", "UserName and Password doesnot match");
                        break;
                    case UserLoginResult.NotRegistered:
                        ModelState.AddModelError("", "User not Registered");
                        break;
                }
                return View(model);
            }
            return View();
        }
Пример #2
0
        public UserLoginResult GetUserDetails(string email, string password,ref UserDetails userDetailsOu)
        {
            var result = new UserDetails();
            Database db = new Database();
            string[,] str = new string[1, 2];
            str[0, 0] = "@Email";
            str[0, 1] = email;
            string xmlResult = db.StoreprocedureExecuteQueryReturned("usp_GetUserDetails", str);
            var serializer = new XmlSerializer(typeof(UserDetails));
            if (!string.IsNullOrEmpty(xmlResult))
            {
                using (var reader = new StringReader(xmlResult))
                {
                    result = (UserDetails)serializer.Deserialize(reader);
                }
            }

            if (result != null)
            {
                //string pswd = encryptionService.CreatePasswordHash(password, "SHA1");
                if (encriptDecript.Decrypt(result.Password) == password)
                {
                    userDetailsOu = result;
                    return UserLoginResult.Successful;
                }
                else
                {
                    return UserLoginResult.WrongPassword;
                }
            }
            return UserLoginResult.NotRegistered;
        }