public void AddSystemUser(SystemUserDataInfo userInfo) { if (string.IsNullOrEmpty(userInfo.UserName) || string.IsNullOrEmpty(userInfo.Password)) { throw new MissingDomainObjectException("用户名或者密码不能为空"); } SystemUser existUser = db.SystemUser.FirstOrDefault(n => !n.IsDelete && n.UserName == userInfo.UserName); if (existUser != null) { throw new DuplicatedDomainObjectException(string.Format("【{0}】用户已存在,请勿重复添加", existUser.UserName)); } if (existUser == null) { existUser = new SystemUser(); existUser.DisplayName = userInfo.DisplayName; existUser.UserName = userInfo.UserName; existUser.Password = userInfo.Password; existUser.UserFace = userInfo.UserFace; db.SystemUser.Add(existUser); db.SaveChanges(); AddSystemLog(new SystemLogDataInfo() { ModulePage = "SystemUser", Remark = string.Format("添加了用户,用户数据为:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(existUser)), CreationDate = DateTime.Now, CreationUserID = CurrentAdminUserId, }); } }
public SystemUserDataInfo GetSystemUserDataInfoByID(int Id) { SystemUser user = db.SystemUser.Find(Id); SystemUserDataInfo userDataInfo = SimpleObjectMapper.CreateTargetObject <SystemUser, SystemUserDataInfo>(user); return(userDataInfo); }
public virtual ActionResult AdminLogin(LoginViewModel model, string returnUrl) { try { if (string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("", "请输入用户名或密码。"); return(View(model)); } string password = EncrypManager.Encode(model.Password); SystemUserDataInfo user = SystemUserService.GetSystemUserDataInfoByLogin(model.UserName, password); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, false); CookieUtil.CreateCookie(user.ID, CookieName.IMAdminCurrentUser); return(RedirectToAction("Index", "Admin")); } else { ModelState.AddModelError("", "用户名或密码错误"); } } catch (Exception ex) { ServerLogger.Error("Failed to log in."); ModelState.AddModelError("", ex.Message); return(View(model)); } return(View(model)); }
public HttpResponseMessage UpdateInfo(SystemUserDataInfo systemUserDataInfo) { SystemUserDataInfo user = SystemUserService.GetSystemUserDataInfoByID(CurrentUserID); user.Password = string.Empty; user.DisplayName = systemUserDataInfo.DisplayName; SystemUserService.UpdateSystemUser(user); return(ResultJson.BuildJsonResponse(null, Models.MessageType.Information, "修改成功")); }
public SystemUserDataInfo GetSystemUserDataInfoByLogin(string userName, string password) { SystemUser user = db.SystemUser.FirstOrDefault(n => !n.IsDelete && n.UserName == userName && n.Password == password); SystemUserDataInfo userDataInfo = SimpleObjectMapper.CreateTargetObject <SystemUser, SystemUserDataInfo>(user); if (userDataInfo != null) { AddSystemLog(new SystemLogDataInfo() { ModulePage = "SystemUser", Remark = "登录了系统", CreationDate = DateTime.Now, CreationUserID = userDataInfo.ID, }); } return(userDataInfo); }
public void DeleteSystemUser(int Id) { SystemUser existUser = db.SystemUser.Find(Id); if (existUser == null) { throw new DuplicatedDomainObjectException("用户不存在"); } existUser.IsDelete = true; db.SaveChanges(); SystemUserDataInfo userDataInfo = SimpleObjectMapper.CreateTargetObject <SystemUser, SystemUserDataInfo>(existUser); AddSystemLog(new SystemLogDataInfo() { ModulePage = "SystemUser", Remark = string.Format("虚拟删除了用户,用户数据为:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)), CreationDate = DateTime.Now, CreationUserID = CurrentAdminUserId, }); }
public HttpResponseMessage AddOrUpdateSystemUser(SystemUserDataInfo systemUserDataInfo) { string responseMsg = string.Empty; if (systemUserDataInfo.ID > 0) { if (!string.IsNullOrEmpty(systemUserDataInfo.Password)) { systemUserDataInfo.Password = EncrypManager.Encode(systemUserDataInfo.Password); } SystemUserService.UpdateSystemUser(systemUserDataInfo); responseMsg = "修改成功"; } else { systemUserDataInfo.Password = EncrypManager.Encode(systemUserDataInfo.Password); SystemUserService.AddSystemUser(systemUserDataInfo); responseMsg = "添加成功"; } return(ResultJson.BuildJsonResponse(null, Models.MessageType.Information, responseMsg)); }
public void UpdateSystemUser(SystemUserDataInfo userInfo) { if (string.IsNullOrEmpty(userInfo.UserName)) { throw new MissingDomainObjectException("用户名不能为空"); } SystemUser existUserByUserName = db.SystemUser.FirstOrDefault(n => !n.IsDelete && n.UserName == userInfo.UserName && n.ID != userInfo.ID); if (existUserByUserName != null) { throw new DuplicatedDomainObjectException(string.Format("【{0}】用户名已存在,修改失败", existUserByUserName.UserName)); } SystemUser existUser = db.SystemUser.Find(userInfo.ID); SystemUserDataInfo userDataInfo = SimpleObjectMapper.CreateTargetObject <SystemUser, SystemUserDataInfo>(existUser); string oldData = Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo); if (existUser == null) { throw new DuplicatedDomainObjectException(string.Format("【{0}】用户不存在", existUser.UserName)); } if (existUser != null) { existUser.DisplayName = userInfo.DisplayName; existUser.UserName = userInfo.UserName; if (!string.IsNullOrEmpty(userInfo.Password)) { existUser.Password = userInfo.Password; } db.SaveChanges(); userDataInfo = SimpleObjectMapper.CreateTargetObject <SystemUser, SystemUserDataInfo>(existUser); AddSystemLog(new SystemLogDataInfo() { ModulePage = "SystemUser", Remark = string.Format("修改了用户,原数据为:{0} 修改后数据为:{1}", oldData, Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)), CreationDate = DateTime.Now, CreationUserID = CurrentAdminUserId, }); } }
public override void OnAuthorization(AuthorizationContext filterContext) { BaseAdminController controller = filterContext.Controller as BaseAdminController; if (controller != null) { base.OnAuthorization(filterContext); ServerLogger.Info(string.Format("Authorize controller {0}", controller.GetType().ToString())); ISystemUserService systemUserService = (ISystemUserService)Bootstrapper.GetService <ISystemUserService>(); SystemUserDataInfo user = systemUserService.GetSystemUserDataInfoByID(controller.CurrentUserID); if (user == null) { filterContext.Result = new RedirectResult("/Account/AdminLogin"); } else { base.OnAuthorization(filterContext); } } else { base.OnAuthorization(filterContext); } }