/// <summary> /// 用户忘记密码,发送密码 /// </summary> /// <param name="userName">用户名</param> /// <param name="returnStatusCode">状态码</param> /// <param name="returnStatusMessage">状态信息</param> /// <returns>成功发送密码</returns> public static bool SendPassword(string userName, out string returnStatusCode, out string returnStatusMessage) { bool returnValue = false; // 1.用户是否找到?默认是未找到用户状态 returnStatusCode = StatusCode.UserNotFound.ToString(); returnStatusMessage = "用户未找到,请重新输入用户名。"; // 用户数据库进行差找用户操作 IDbProvider dbProvider = new SqlProvider(RDIFrameworkDbConection); dbProvider.Open(); PiUserManager userManager = new PiUserManager(dbProvider); // 2.用户是否已被删除? var parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(PiUserTable.FieldUserName, userName)); parameters.Add(new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)); var userEntity = BaseEntity.Create <PiUserEntity>(userManager.GetDT(parameters, 0, string.Empty)); dbProvider.Close(); // 是否已找到了此用户 if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id.ToString())) { // 3.用户是否有效的? if (userEntity.Enabled == 1) { if (!string.IsNullOrEmpty(userEntity.Email)) { // 5.重新产生随机密码? // 6.发送邮件给用户? // 7.重新设置用户密码? returnValue = SendPassword(userEntity); returnStatusCode = StatusCode.OK.ToString(); returnStatusMessage = "新密码已发送到您的注册邮箱" + userEntity.Email + "。"; } else { // 4.用户是否有邮件账户? returnStatusCode = StatusCode.UserNotEmail.ToString(); returnStatusMessage = "用户没有电子邮件地址,无法从新设置密码,请您及时联系系统管理员。"; } } else { if (userEntity.Enabled == 0) { returnStatusCode = StatusCode.UserLocked.ToString(); returnStatusMessage = "用户被锁定,不允许设置密码。"; } else { returnStatusCode = StatusCode.UserNotActive.ToString(); returnStatusMessage = "用户还未被激活,不允许设置密码。"; } } } return(returnValue); }
/// <summary> /// 获取用户列表 /// </summary> /// <param name="ddlUser">用户选项</param> /// <param name="organizeId">部门主键</param> /// <param name="insertBlank">插入空行</param> protected void GetUserByPermissionScope(DropDownList ddlUser, string organizeId = null, bool insertBlank = false, string permissionItemCode = "Resource.ManagePermission") { var manager = new PiUserManager(this.RDIFrameworkDbProvider, this.UserInfo); DataTable dtUser = null; if (string.IsNullOrEmpty(organizeId)) { if (this.UserInfo.IsAdministrator) { dtUser = manager.GetDT(); } else { dtUser = RDIFrameworkService.Instance.PermissionService.GetUserDTByPermissionScope(userInfo, userInfo.Id, permissionItemCode); if (!string.IsNullOrEmpty(organizeId)) { BusinessLogic.SetFilter(dtUser, PiUserTable.FieldDepartmentId, organizeId); } // 至少要把自己显示出来,否则难控制权限了 if (dtUser == null || dtUser.Rows.Count == 0) { var userManager = new PiUserManager(userInfo); dtUser = userManager.GetDTById(this.UserInfo.Id); } } } else { dtUser = manager.GetDataTableByOrganizes(new string[] { organizeId }); } ddlUser.SelectedValue = null; ddlUser.DataValueField = PiUserTable.FieldId; ddlUser.DataTextField = PiUserTable.FieldRealName; ddlUser.DataSource = dtUser; ddlUser.DataBind(); if (this.UserInfo.IsAdministrator || insertBlank) { ddlUser.Items.Insert(0, new ListItem()); } }