/// <summary> /// 登录方法 /// </summary> /// <param name="loginName"></param> /// <param name="userPwd"></param> /// <returns></returns> public COUserIdentity Login(string loginName, string userPwd, CPEnum.DeviceTypeEnum device, ref string errorMsg) { COUser user = this.GetUserByLoginName(loginName, false, false); if (user == null) { errorMsg = "不存在登录名为[" + loginName + "]的用户,请重新输入!"; return(null); } if (user.UserPwd.Equals(this.UserPwdEncrypt(userPwd), StringComparison.CurrentCultureIgnoreCase) == false) { errorMsg = "登录名或密码不对,请重新输入!"; return(null); } Guid gId = Guid.NewGuid(); bool b = this.AddUserIdentity(user.Id, gId, device); if (b) { //记录登录日志 CPLogHelper.Instance().AddLog(user.Id, user.UserName, device, user.UserName + "登录成功!", "用户登录"); COUserIdentity userIden = this.GetUserIdentity(gId); this.AddUserSession(userIden, user); return(userIden); } else { errorMsg = "写入登录标识时出错!"; return(null); } }
public CPWebApiBaseReturnEntity UpdateUserPwd(string OldPwd, string NewPwd) { base.SetHeader(); CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity(); try { string userId = CPExpressionHelper.Instance.RunCompile("${CPUser.UserId()}"); COOrgans organs = COOrgans.Instance(); COUser user = organs.GetUserById(int.Parse(userId), false, false); OldPwd = organs.UserPwdEncrypt(OldPwd); if (user.UserPwd.Equals(OldPwd, StringComparison.CurrentCultureIgnoreCase) == false) { re.Result = false; re.ErrorMsg = "原密码输入不对,请重新输入!"; return(re); } user.UserPwd = organs.UserPwdEncrypt(NewPwd); re.Result = organs.UpdateUser(user); return(re); } catch (Exception ex) { re.Result = false; re.ErrorMsg = ex.Message.ToString(); return(re); } }
public void AfterSave(ICPFormAfterSaveEventArgs e) { string UserPwd = e.GetFieldValue("CP_User", "UserPwd", 0); COOrgans organs = COOrgans.Instance(); UserPwd = organs.UserPwdEncrypt(UserPwd); COUser user = organs.GetUserById(int.Parse(e.PKValue), false, false); user.UserPwd = UserPwd; organs.UpdateUser(user); }
public bool UpdateUser(COUser user) { this._COUserRep.Update(user); return(true); }
private void AddUserSession(COUserIdentity userIden, COUser user) { CPAppContext.GetHttpContext().Session.SetString("UserId", userIden.UserId.ToString()); CPAppContext.GetHttpContext().Session.SetString("UserKey", userIden.UserKey.ToString()); CPAppContext.GetHttpContext().Session.SetString("UserName", user.UserName); CPAppContext.GetHttpContext().Session.SetString("UserLoginName", user.LoginName.ToString()); if (string.IsNullOrEmpty(user.UserPhotoPath)) { CPAppContext.GetHttpContext().Session.SetString("UserPhotoPath", ""); } else { CPAppContext.GetHttpContext().Session.SetString("UserPhotoPath", user.UserPhotoPath.ToString()); } //获取用户所在的角色 List <CORole> userRole = this.GetUserStaticRoles(user.Id); string RoleIds = ""; string RoleNames = ""; userRole.ForEach(t => { if (string.IsNullOrEmpty(RoleIds)) { RoleIds = t.Id.ToString(); RoleNames = t.RoleName; } else { RoleIds += "," + t.Id.ToString(); RoleNames += "," + t.RoleName; } }); CPAppContext.GetHttpContext().Session.SetString("RoleIds", RoleIds.ToString()); CPAppContext.GetHttpContext().Session.SetString("RoleNames", RoleNames.ToString()); //获取部门 List <CODep> depCol = this.GetDepByUser(user.Id); string DepIds = ""; string DepNames = ""; depCol.ForEach(t => { if (string.IsNullOrEmpty(DepIds)) { DepIds = t.Id.ToString(); DepNames = t.DepName; } else { DepIds += "," + t.Id.ToString(); DepNames += "," + t.DepName; } }); CPAppContext.GetHttpContext().Session.SetString("DepIds", DepIds.ToString()); CPAppContext.GetHttpContext().Session.SetString("DepNames", DepNames.ToString()); //获取当前用户拥有管理员权限的子系统 List <CPSystem> sysCol = CPSystemHelper.Instance().GetSystems(); string sysIds = ""; sysCol.ForEach(t => { if (string.IsNullOrEmpty(t.AdminUserIds)) { return; } if (t.AdminUserIds.Split(',').Contains(user.Id.ToString())) { if (string.IsNullOrEmpty(sysIds)) { sysIds = t.Id.ToString(); } else { sysIds += "," + t.Id.ToString(); } } }); CPAppContext.GetHttpContext().Session.SetString("UserAdminSysIds", sysIds.ToString()); }