Example #1
0
        public IActionResult LogOn(AccountLogOnModel model)
        {
            if (ModelState.IsValid)
            {
                var administratorDal = new AdministratorDal();
                try
                {
                    var p = administratorDal.FindByAccounts(model.Accounts.ToLower());
                    if (p != null)
                    {
                        //Url.IsLocalUrl(returnUrl)
                        CryptoHelper helper = new CryptoHelper();
                        if (p.PassWord.Trim() == helper.Encrypt(model.Password))
                        {
                            Cache.SetString("CurrentAdmin", p.AdministratorId);
                            HttpContext.Session.SetString("CurrentAdmin", p.AdministratorId);
                            var logMode = new LogDefinition()
                            {
                                Content        = "登录",
                                AdminName      = p.Name,
                                AfterUpdate    = "",
                                BeforeUpdate   = "",
                                UpdateDateTime = DateTime.Now,
                            };
                            var logDal = new LogDal();
                            logDal.Add(logMode);
                            return(RedirectToAction("Index", "Frame"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "密码不正确.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "找不到该账号.");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public void LogOn_Post_ReturnsViewIfValidateUserFails()
        {
            // Arrange
            var model = new AccountLogOnModel
            {
                Email      = "*****@*****.**",
                Password   = "******",
                RememberMe = false
            };

            // Act
            ActionResult result = _accountController.LogOn(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = (ViewResult)result;

            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("The user name or password provided is incorrect.", _accountController.ModelState[""].Errors[0].ErrorMessage);
        }
        public void LogOn_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Arrange
            var model = new AccountLogOnModel
            {
                Email      = "*****@*****.**",
                Password   = "******",
                RememberMe = false
            };

            _accountController.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = _accountController.LogOn(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = (ViewResult)result;

            Assert.AreEqual(model, viewResult.ViewData.Model);
        }
        public void LogOn_Post_ReturnsRedirectOnSuccess_WithReturnUrl()
        {
            // Arrange
            var model = new AccountLogOnModel
            {
                Email      = "*****@*****.**",
                Password   = "******",
                RememberMe = false,
                ReturnUrl  = "/someUrl"
            };

            // Act
            ActionResult result = _accountController.LogOn(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            var redirectResult = (RedirectResult)result;

            Assert.AreEqual("/someUrl", redirectResult.Url);
            Assert.IsTrue(_authenticationService.SignIn_WasCalled);
        }
Example #5
0
        public ActionResult LogOn(AccountLogOnModel model, string returnUrl)
        {
            if (this.ModelState.IsValid)
            {
                if (this.ValidateUser(model.UserName, model.Password))
                {
                    this.FormsService.SignIn(model.UserName, model.RememberMe);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(this.Redirect(returnUrl));
                    }

                    return(this.RedirectToAction("Index", "Home"));
                }

                this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
            }

            return(View(model));
        }
Example #6
0
        public ActionResult LogOn(AccountLogOnModel model)
        {
            if (ModelState.IsValid)
            {
                model.Email = model.Email.ToLower().Trim();

                if (_membershipService.ValidateUser(model.Email, model.Password))
                {
                    _formsService.SignIn(model.Email, model.RememberMe);
                    if (!string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }

                    return(RedirectTo <HomeController>(c => c.Index()));
                }

                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #7
0
        public ActionResult LogOn()
        {
            var model = new AccountLogOnModel();

            return(this.View(model));
        }