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 UpdatePassWord(UpdatePasswordDataInfo updatePassword) { updatePassword.ID = CurrentUserID; updatePassword.NewPassword = EncrypManager.Encode(updatePassword.NewPassword); updatePassword.OldPassword = EncrypManager.Encode(updatePassword.OldPassword); SystemUserService.UpdatePassword(updatePassword); return(ResultJson.BuildJsonResponse(null, Models.MessageType.Information, "修改成功")); }
public void CreateAdminUser() { string _userName = "******"; string _password = "******"; string password = EncrypManager.Encode(_password); SystemUser user = db.SystemUser.FirstOrDefault(n => n.UserName == _userName); if (user == null) { user = new SystemUser(); user.DisplayName = _userName; user.UserName = _userName; user.Password = password; db.SystemUser.Add(user); db.SaveChanges(); } }
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)); }