90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
namespace YLErp.Web.Controllers
|
|
{
|
|
[MyAuthorizeIgnore]
|
|
public class HomeController : BaseController
|
|
{
|
|
public ActionResult Index()
|
|
{
|
|
if (PS.Config.ErpElement.CheckPassword && Server.CacheProvider.Get("简单密码" + UserId) != null)
|
|
{
|
|
ViewData["复杂密码"] = "true";
|
|
return View("ChangePassword");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
public ActionResult Index2()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ActionResult _ChangePassword()
|
|
{
|
|
if (PS.Config.ErpElement.CheckPassword)
|
|
{
|
|
ViewData["复杂密码"] = "true";
|
|
}
|
|
return PartialView();
|
|
}
|
|
|
|
public JsonResult AjaxChangePassword(string oldPassword, string newPassword, string newPassword2)
|
|
{
|
|
if (string.IsNullOrEmpty(oldPassword))
|
|
{
|
|
return JsonError("旧密码 必须填写");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(newPassword))
|
|
{
|
|
return JsonError("新密码 必须填写");
|
|
}
|
|
|
|
var CheckPassword = PS.Config.ErpElement.CheckPassword;
|
|
|
|
if (CheckPassword && newPassword.Length < 12)
|
|
{
|
|
return JsonError("新密码 必须至少12位长度");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(newPassword2))
|
|
{
|
|
return JsonError("确认新密码 必须填写");
|
|
}
|
|
|
|
if (newPassword2 != newPassword)
|
|
{
|
|
return JsonError("确认新密码 和 新密码 必须一致");
|
|
}
|
|
|
|
if (CheckPassword && !PasswordValidator.Validate(newPassword))
|
|
{
|
|
return JsonError("新密码 必须包含大小写字母,数字,特殊字符,长度不小于12位");
|
|
}
|
|
|
|
try
|
|
{
|
|
var userId = CurUser.UserId;
|
|
|
|
using (var db = new ErpBaseContext())
|
|
{
|
|
var user = db.SystemUsers.Find(userId);
|
|
if (user.CheckPassword(oldPassword) == true)
|
|
{
|
|
user.Password = DataHelper.EncryptPassword(user.LoginName.ToLower(), newPassword);
|
|
db.SaveChanges();
|
|
Server.CacheProvider.Remove("简单密码" + UserId);
|
|
Server.CacheProvider.Set("loginUserError^" + user.LoginName.ToLower(), 0, TimeSpan.FromMinutes(120));
|
|
return JsonSuccess();
|
|
}
|
|
return JsonError("旧密码错误");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFactory.GetLogger("修改密码").Error(ex);
|
|
return JsonError("修改密码失败,发生错误:" + ex.GetBaseException().Message);
|
|
}
|
|
}
|
|
}
|
|
}
|