public IActionResult Add(AdministratorAddModel model)
        {
            var oldAdmin = AdministratorDal.FindByAccounts(model.Accounts);

            if (oldAdmin != null)
            {
                return(Json("该登录账号已经占用"));
            }

            try
            {
                CryptoHelper helper = new CryptoHelper();

                var p = new AdministratorDefinition()
                {
                    AdministratorId = Guid.NewGuid().ToString("N"),
                    SysAdmin        = false,
                    Name            = model.Name,
                    PassWord        = helper.Encrypt(model.PassWord.Trim()),
                    Phone           = model.Phone,
                    Accounts        = model.Accounts.ToLower(),
                    ReWritePassWord = true,
                    RoleId          = model.RoleId,
                };
                AdministratorDal.Add(p);
                return(Json(1));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
Exemple #2
0
        public IActionResult ChangePassword(FrameChangePassword model)
        {
            if (ModelState.IsValid)
            {
                var dal = new AdministratorDal();
                try
                {
                    CryptoHelper helper = new CryptoHelper();
                    var          p      = CurrentAdmin;
                    var          old    = dal.FindByAccounts(model.Accounts.Trim().ToLower());
                    if (old != null)
                    {
                        if (old.AdministratorId != p.AdministratorId)
                        {
                            ModelState.AddModelError("", "该账号已经被占用.");
                            return(View(model));
                        }
                    }

                    if (model.OldPassword.Trim() == helper.Decrypt(p.PassWord.Trim()))
                    {
                        var logMode = new LogDefinition()
                        {
                            Content        = "修改密码",
                            AdminName      = p.Name,
                            AfterUpdate    = "",
                            BeforeUpdate   = "",
                            UpdateDateTime = DateTime.Now,
                        };
                        var logDal = new LogDal();
                        logDal.Add(logMode);
                        p.PassWord = helper.Encrypt(model.NewPassword);
                        p.Accounts = model.Accounts.Trim().ToLower();
                        dal.Update(p);
                        CurrentAdmin = null;
                        return(RedirectToAction("LogOn", "Account"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "密码不正确.");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            //model.OldPassword = "";
            //model.NewPassword = "";
            //model.ConfirmPassword = "";

            return(View(model));
        }
Exemple #3
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));
        }