Пример #1
0
        public ActionResult Validate(UserLogonModel userModel)
        {

            try
            {
                var account = new AccountInfo();
                var userobj = new User()
                {
                    UserName = userModel.UserName,
                    Password = userModel.Password
                };
                var errorMessage = "";
                if (SecurityService.ValidateCredentials(userobj, out errorMessage))
                {
                    account.SetUserName(userModel.UserName);
                    account.SetUserCredentials(userModel.Password);

                    if (TempData != null && TempData.Count > 0 && TempData.ContainsKey("ReturnURL"))
                    {
                        var returnUrl = TempData["ReturnURL"].ToString();
                        TempData.Clear();
                        var decodedUrl = "";
                        if (!string.IsNullOrEmpty(returnUrl))
                            decodedUrl = Server.UrlDecode(returnUrl);


                        if (Url.IsLocalUrl(decodedUrl))
                        {
                            decodedUrl = decodedUrl.Replace("\\\"", ""); ;
                            decodedUrl = Request.Url.Scheme + "://" + Request.Url.Authority + decodedUrl;
                            return Redirect(decodedUrl);
                        }
                    }

                    return RedirectToAction("Index", "Home");
                }
                if (errorMessage.ToUpper().Equals("LDAPERROR"))
                {
                    ModelState.AddModelError("UserName", _InvalidUser);
                    return View("Login");
                }
                return View("Login");
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                ModelState.AddModelError("UserName", ce.Message);
                return View("Login");
            }
            catch (InvalidOperationException ix)
            {
                ModelState.AddModelError("UserName", _InvalidUser);
                ModelState.AddModelError("Password", String.Empty);
                return View("Login");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
 public bool ValidateCredentials(User userModel,out string errorMessage)
 {
     errorMessage = "";
     return SecurityDao.ValidateCredentials(userModel, out errorMessage);
 }