/// <summary> /// 根据邮箱获取用户实体 /// </summary> /// <param name="email"></param> /// <returns></returns> public BaseUserEntity GetEntityByEmail(string email) { BaseUserEntity userEntity = null; // 用户没有找到状态 StatusCode = Status.UserNotFound.ToString(); StatusMessage = GetStateMessage(StatusCode); // 检查是否有效的合法的参数 if (!string.IsNullOrEmpty(email) && ValidateUtil.IsEmail(email)) { var userContactManager = new BaseUserContactManager(); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email) }; var id = userContactManager.GetId(parameters); if (!string.IsNullOrEmpty(id)) { parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserEntity.FieldId, id), new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0), new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1) }; var dt = GetDataTable(parameters); if (dt != null && dt.Rows.Count == 1) { userEntity = BaseEntity.Create <BaseUserEntity>(dt); } } } return(userEntity); }
/// <summary> /// 向管理员发送登录提醒邮件 /// </summary> /// <param name="userInfo"></param> /// <param name="systemCode">系统编码</param> public static void SendLoginMailToAdministrator(BaseUserInfo userInfo, string systemCode = "Base") { //如果是系统管理员登录则发送EMAIL if (userInfo != null && IsAdministrator(userInfo.Id)) { // 登录成功发送 var userContactEntity = new BaseUserContactManager().GetEntityByUserId(userInfo.Id); if (userContactEntity != null) { var emailAddress = userContactEntity.Email; if (string.IsNullOrEmpty(emailAddress)) { emailAddress = BaseSystemInfo.ErrorReportTo; } if (!string.IsNullOrEmpty(emailAddress)) { // 没有邮箱则给管理员发邮件 // 使用线程发送邮件 var subject = "超级管理员 " + userInfo.CompanyName + " - " + userInfo.UserName + " 登录" + BaseSystemInfo.SoftFullName + " 系统提醒"; var body = userInfo.UserName + Environment.NewLine + ":<br/>" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "登录了" + BaseSystemInfo.SoftFullName + ";<br/>" + Environment.NewLine + "编号:" + userInfo.Code + ";<br/> " + Environment.NewLine + "登录系统:" + systemCode + ";<br/> " + Environment.NewLine + "登录IP:" + userInfo.IpAddress + ";<br/> " + Environment.NewLine + "MAC地址:" + userInfo.MacAddress + ";<br/>" + Environment.NewLine + "如果不是您自己登录,请马上联系系统管理员并即刻修改密码。"; MailUtil.SendByThread(emailAddress, subject, body); } } } }
/// <summary> /// 更新用户联系方式 /// </summary> /// <param name="entity">用户联系方式实体</param> /// <returns>影响行数</returns> public int Update(BaseUserContactEntity entity) { int result = 0; // 获取原始实体信息 var entityOld = this.GetObject(entity.Id); // 2015-12-26 吉日嘎拉 当新增时,需要判断这个是否为空 if (entityOld != null) { // 保存修改记录 this.UpdateEntityLog(entity, entityOld); } // 更新数据 result = this.UpdateObject(entity); // 同步数据 // AfterUpdate(entity); // 重新设置缓存 if (result > 0) { BaseUserContactManager.SetCache(entity); } // 返回值 return(result); }
public BaseUserEntity GetObjectByEmail(string email) { BaseUserEntity userEntity = null; // 用户没有找到状态 this.StatusCode = Status.UserNotFound.ToString(); this.StatusMessage = this.GetStateMessage(this.StatusCode); // 检查是否有效的合法的参数 if (!String.IsNullOrEmpty(email) && ValidateUtil.IsEmail(email)) { BaseUserContactManager userContactManager = new BaseUserContactManager(); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email)); string id = userContactManager.GetId(parameters); if (!string.IsNullOrEmpty(id)) { parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldId, id)); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1)); var dt = this.GetDataTable(parameters); if (dt.Rows.Count == 1) { userEntity = BaseEntity.Create <BaseUserEntity>(dt); } } } return(userEntity); }
/// <summary> /// 向管理员发送登录提醒邮件 /// </summary> /// <param name="result"></param> /// <param name="returnUserInfo"></param> /// <param name="StatusCode"></param> public static void SendLoginMailToAdministrator(BaseUserInfo userInfo, string systemCode = "Base") { //如果是系统管理员登录则发送EMAIL if (userInfo != null && userInfo.IsAdministrator) { // 登录成功发送 BaseUserContactEntity userContactEntity = new BaseUserContactManager().GetObject(userInfo.Id); if (userContactEntity != null) { string emailAddress = userContactEntity.Email; if (string.IsNullOrEmpty(emailAddress)) { emailAddress = BaseSystemInfo.ErrorReportTo; } if (!string.IsNullOrEmpty(emailAddress)) { // 没有邮箱则给管理员发邮件 // 使用线程发送邮件 string subject = "超级管理员 " + userInfo.CompanyName + " - " + userInfo.UserName + " 登录" + BaseSystemInfo.SoftFullName + " 系统提醒"; string body = userInfo.UserName + System.Environment.NewLine + ":<br/>" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "登录了" + BaseSystemInfo.SoftFullName + ";<br/>" + System.Environment.NewLine + "编号:" + userInfo.Code + ";<br/> " + System.Environment.NewLine + "登录系统:" + systemCode + ";<br/> " + System.Environment.NewLine + "登录IP:" + userInfo.IPAddress + ";<br/> " + System.Environment.NewLine + "MAC地址:" + userInfo.MACAddress + ";<br/>" + System.Environment.NewLine + "如果不是您自己登录,请马上联系中天系统管理员电话021-3116 5566-9582,QQ:707055073,请即刻修改密码。"; MailUtil.SendByThread(emailAddress, subject, body); } } } }
/// <summary> /// 离职处理 /// </summary> /// <param name="id">主键</param> /// <returns>影响行数</returns> public int Leave(BaseUserEntity userEntity, BaseUserLogOnEntity userLogOnEntity, string comment) { int result = 0; if (userEntity != null) { // 更新用户实体 this.UpdateObject(userEntity); } // 更新登录信息 if (userLogOnEntity != null) { BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(this.UserInfo); userLogOnManager.UpdateObject(userLogOnEntity); } // 填写评论 if (!string.IsNullOrWhiteSpace(comment)) { SQLBuilder sqlBuilder = new SQLBuilder(BaseSystemInfo.ServerDbType); sqlBuilder.BeginInsert(BaseCommentEntity.TableName); sqlBuilder.SetValue(BaseCommentEntity.FieldId, System.Guid.NewGuid().ToString("N")); sqlBuilder.SetValue(BaseCommentEntity.FieldCategoryCode, BaseUserEntity.TableName); sqlBuilder.SetValue(BaseCommentEntity.FieldObjectId, userEntity.Id); sqlBuilder.SetValue(BaseCommentEntity.FieldContents, comment); sqlBuilder.SetValue(BaseCommentEntity.FieldWorked, 1); sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentId, userEntity.DepartmentId); sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentName, userEntity.DepartmentName); sqlBuilder.SetValue(BaseCommentEntity.FieldCreateUserId, this.UserInfo.Id); sqlBuilder.SetValue(BaseCommentEntity.FieldCreateBy, this.UserInfo.RealName); sqlBuilder.SetDBNow(BaseCommentEntity.FieldCreateOn); sqlBuilder.SetValue(BaseCommentEntity.FieldIPAddress, this.UserInfo.IPAddress); sqlBuilder.SetValue(BaseCommentEntity.FieldEnabled, 1); sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 0); sqlBuilder.EndInsert(); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && !string.IsNullOrEmpty(userEntity.NickName)) { AfterLeaveStopIM(userEntity); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id)) { BaseUserContactEntity userContactEntity = BaseUserContactManager.GetObjectByCache(userEntity.Id); { if (userContactEntity != null && !string.IsNullOrEmpty(userContactEntity.CompanyMail)) { ChangeUserMailStatus(userContactEntity.CompanyMail, true); } } } return(result); }
/// <summary> /// 用户忘记密码,发送密码 /// </summary> /// <param name="email">邮箱地址</param> /// <param name="status">状态</param> /// <param name="statusMessage">状态信息</param> /// <param name="newPassword">新密码</param> /// <returns>成功发送密码</returns> public static bool ResetPassword(string email, out Status status, out string statusMessage, out string newPassword) { var result = false; // 1.用户是否找到?默认是未找到用户状态 status = Status.UserNotFound; statusMessage = "未找到对应的用户"; newPassword = RandomUtil.GetRandom(100000, 999999).ToString(); var userContactManager = new BaseUserContactManager(); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email) }; var userContactEntity = BaseEntity.Create <BaseUserContactEntity>(userContactManager.GetDataTable(parameters)); if (userContactEntity != null && userContactEntity.UserId > 0) { var userManager = new BaseUserManager(); // 2.用户是否已被删除? parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserEntity.FieldId, userContactEntity.UserId), new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0) }; var userEntity = BaseEntity.Create <BaseUserEntity>(userManager.GetDataTable(parameters)); // 是否已找到了此用户 if (userEntity != null && userEntity.Id > 0) { // 3.用户是否有效的? if (userEntity.Enabled == 1) { if (userManager.SetPassword(userEntity.Id, newPassword) > 0) { result = true; status = Status.Ok; statusMessage = "新密码已发送到您的注册邮箱" + email + ",请注意查收。"; } else { status = Status.ErrorUpdate; statusMessage = "更新数据库失败,请重试!"; } } else { if (userEntity.Enabled == 0) { status = Status.UserLocked; statusMessage = "用户被锁定,不允许重置密码。"; } } } } return(result); }
/// <summary> /// 编辑之后,需要重新刷新缓存,否则其他读取数据的地方会乱了,或者不及时了 /// </summary> /// <param name="entity">用户实体</param> /// <returns>影响行数</returns> public int AfterUpdate(BaseUserEntity entity) { var result = 0; // 用户的缓存需要更新 SetCache(entity); // 用户的联系方式需要更新 BaseUserContactManager.SetCache(entity.Id); // 2016-02-02 吉日嘎拉,修改数据后重新设置缓存。 CachePreheatingSpelling(entity); // AfterUpdateSynchronous(entity); return(result); }
/// <summary> /// 获取实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>实体</returns> public BaseUserContactEntity GetUserContactObjectByCache(BaseUserInfo userInfo, string id) { BaseUserContactEntity entity = null; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { entity = BaseUserContactManager.GetObjectByCache(id); }); return(entity); }
/// <summary> /// 添加用户 /// </summary> /// <param name="dbHelper">数据库连接</param> /// <param name="userInfo">用户信息</param> /// <param name="entity">用户实体</param> /// <param name="userLogonEntity">用户登录实体</param> /// <param name="userContactEntity">用户联系方式</param> /// <param name="status">状态</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string CreateUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity entity, BaseUserLogonEntity userLogonEntity, BaseUserContactEntity userContactEntity, out Status status, out string statusMessage) { var result = string.Empty; // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif var userManager = new BaseUserManager(dbHelper, userInfo); result = userManager.AddUser(entity, userLogonEntity); status = userManager.Status; statusMessage = userManager.GetStateMessage(); // 20140219 JiRiGaLa 添加成功的用户才增加联系方式 if (!string.IsNullOrEmpty(result) && status == Status.OkAdd && userContactEntity != null) { // 添加联系方式 userContactEntity.UserId = int.Parse(result); var userContactManager = new BaseUserContactManager(dbHelper, userInfo); userContactEntity.CompanyId = entity.CompanyId; userContactManager.Add(userContactEntity); } // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了 if (entity.Enabled == 0 && status == Status.OkAdd) { // 不是系统管理员添加 if (!BaseUserManager.IsAdministrator(userInfo.Id)) { // 给超级管理员群组发信息 var roleManager = new BaseRoleManager(dbHelper, userInfo); var roleIds = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators")); var userIds = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator")); // 发送请求审核的信息 //var messageEntity = new BaseMessageEntity //{ // FunctionCode = MessageFunction.WaitForAudit.ToString(), // // Pcsky 2012.05.04 显示申请的用户名 // Contents = userInfo.RealName + "(" + userInfo.IpAddress + ")" + AppMessage.UserServiceApplication + entity.UserName + AppMessage.UserServiceCheck //}; //messageEntity.Contents = result.RealName + "(" + result.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check; //var messageManager = new BaseMessageManager(dbHelper, userInfo); //messageManager.BatchSend(userIds, null, roleIds, messageEntity, false); } } return(result); }
/// <summary> /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的 /// </summary> /// <param name="userId">主键</param> /// <returns>用户信息</returns> public static BaseUserContactEntity SetCache(int userId) { BaseUserContactEntity result = null; var manager = new BaseUserContactManager(); result = manager.GetEntityByUserId(userId); if (result != null) { SetCache(result); } return(result); }
/// <summary> /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的 /// </summary> /// <param name="id">主键</param> /// <returns>用户信息</returns> public static BaseUserContactEntity SetCache(string id) { BaseUserContactEntity result = null; BaseUserContactManager manager = new BaseUserContactManager(); result = manager.GetObject(id); if (result != null) { SetCache(result); } return(result); }
/// <summary> /// 验证手机验证码 /// 2015-11-10 吉日嘎拉 手机验证码确认的代码进行优化 /// </summary> /// <param name="userInfo">用户</param> /// <param name="mobile">手机号码</param> /// <param name="code">验证码</param> /// <returns>成功验证</returns> public bool ValidateVerificationCode(BaseUserInfo userInfo, string mobile, string code) { bool result = false; if (string.IsNullOrEmpty(mobile)) { return(false); } if (string.IsNullOrEmpty(code)) { return(false); } string connectionString = string.Empty; connectionString = ConfigurationHelper.AppSettings("OpenMasDbConnection", BaseSystemInfo.EncryptDbConnection); if (!string.IsNullOrEmpty(connectionString)) { using (IDbHelper dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SqlServer, connectionString)) { string commandText = @"SELECT COUNT(1) FROM SMSSentLog WHERE DATEDIFF(Hour, CreateTime, GETDATE()) < 8 AND MessageCode = " + dbHelper.GetParameter("MessageCode") + " AND DestinationAddress = " + dbHelper.GetParameter("DestinationAddress"); object remainingNumber = dbHelper.ExecuteScalar(commandText , new IDbDataParameter[] { dbHelper.MakeParameter("MessageCode", code) , dbHelper.MakeParameter("DestinationAddress", mobile) }); if (remainingNumber != null) { result = int.Parse(remainingNumber.ToString()) > 0; } } // 手机验证码通过审核了 if (result && userInfo != null) { BaseUserContactEntity userContactEntity = BaseUserContactManager.GetObjectByCache(userInfo.Id); if (userContactEntity != null) { // 2016-02-13 吉日嘎拉 这里还需要进行缓存更新操作 userContactEntity.MobileValiated = 1; userContactEntity.MobileVerificationDate = DateTime.Now; new BaseUserContactManager().Update(userContactEntity); } } } return(result); }
/// <summary> /// 手机号码是否存在? /// </summary> /// <param name="userInfo">用户</param> /// <param name="mobile">手机号码</param> /// <returns>存在</returns> public bool Exists(BaseUserInfo userInfo, string mobile) { bool result = false; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldMobile, mobile)); var manager = new BaseUserContactManager(dbHelper, userInfo, BaseUserContactEntity.TableName); result = manager.Exists(parameters, userInfo.Id); }); return(result); }
public static BaseUserContactEntity GetUserContactObjectByCache(BaseUserInfo userInfo, string id) { BaseUserContactEntity result = null; string key = "UserContact:" + id; result = BaseUserContactManager.GetCacheByKey(key); // 远程通过接口获取数据 if (result == null) { result = GetUserContactObject(userInfo, id); } return(result); }
/// <summary> /// 解除手机认证帮定 /// </summary> /// <param name="userInfo">用户</param> /// <param name="mobile">手机号码</param> /// <returns>影响行数</returns> public int RemoveMobileBinding(BaseUserInfo userInfo, string mobile) { int result = 0; string returnCode = string.Empty; string returnMessage = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var manager = new BaseUserContactManager(dbHelper, userInfo); result = manager.RemoveMobileBinding(mobile); }); return(result); }
/// <summary> /// 获取实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>实体</returns> public BaseUserContactEntity GetUserContactObject(BaseUserInfo userInfo, string id) { BaseUserContactEntity entity = null; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); // 判断是否已经登录的用户? if (userManager.UserIsLogOn(userInfo)) { var userContactManager = new BaseUserContactManager(dbHelper, userInfo); entity = userContactManager.GetObject(id); } }); return(entity); }
/// <summary> /// 缓存预热,强制重新缓存 /// </summary> /// <returns>影响行数</returns> public static int CachePreheating() { int result = 0; // 把所有的数据都缓存起来的代码 BaseUserContactManager manager = new BaseUserContactManager(); using (IDataReader dataReader = manager.ExecuteReader()) { while (dataReader.Read()) { BaseUserContactEntity entity = BaseEntity.Create <BaseUserContactEntity>(dataReader, false); BaseUserContactManager.SetCache(entity); result++; System.Console.WriteLine(result.ToString() + " : " + entity.Telephone); } dataReader.Close(); } return(result); }
/// <summary> /// 离职处理 /// </summary> /// <param name="userEntity"></param> /// <param name="userLogonEntity"></param> /// <param name="comment"></param> /// <returns>影响行数</returns> public int Leave(BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity, string comment) { var result = 0; if (userEntity != null) { // 更新用户实体 UpdateEntity(userEntity); } // 更新登录信息 if (userLogonEntity != null) { var userLogonManager = new BaseUserLogonManager(UserInfo); userLogonManager.UpdateEntity(userLogonEntity); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && !string.IsNullOrEmpty(userEntity.NickName)) { //AfterLeaveStopIm(userEntity); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && userEntity.Id > 0) { BaseUserContactEntity userContactEntity = null; // 2015-12-08 吉日嘎拉 提高效率、从缓存获取数据 userContactEntity = BaseUserContactManager.GetEntityByCache(userEntity.Id); if (userContactEntity != null && !string.IsNullOrEmpty(userContactEntity.CompanyEmail)) { ChangeUserMailStatus(userContactEntity.CompanyEmail, true); } } return(result); }
/// <summary> /// 缓存预热,强制重新缓存 /// </summary> /// <returns>影响行数</returns> public static int CachePreheating() { var result = 0; // 把所有的数据都缓存起来的代码 var manager = new BaseUserContactManager(); var dataReader = manager.ExecuteReader(); if (dataReader != null && !dataReader.IsClosed) { while (dataReader.Read()) { var entity = BaseEntity.Create <BaseUserContactEntity>(dataReader, false); SetCache(entity); result++; System.Console.WriteLine(result + " : " + entity.Telephone); } dataReader.Close(); } return(result); }
/// <summary> /// 更新用户 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="entity">用户实体</param> /// <param name="userContactEntity">用户联系方式实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>影响行数</returns> public int UpdateUser(BaseUserInfo userInfo, BaseUserEntity entity, BaseUserContactEntity userContactEntity, out string statusCode, out string statusMessage) { int result = 0; string returnCode = string.Empty; string returnMessage = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); // 调用方法,并且返回运行结果,判断重复 // result = userManager.Update(entity, out StatusCode); // 不判断重复直接更新 if (entity != null) { // 2015-12-09 吉日嘎拉 确认更新日志功能 result = userManager.Update(entity); // 若是超级管理员,就是名字编号重复了,也应该能修改数据比较好,否则有些事情无法办理下去了,由于历史原因导致数据重复的什么的,也需要能修改才可以。 if (userInfo.IsAdministrator) { if (userManager.StatusCode == Status.ErrorUserExist.ToString() || userManager.StatusCode == Status.ErrorCodeExist.ToString()) { result = userManager.UpdateObject(entity); } } } if (userContactEntity != null) { var userContactManager = new BaseUserContactManager(dbHelper, userInfo); userContactManager.SetObject(userContactEntity); } if (result == 1) { userManager.StatusCode = Status.OKUpdate.ToString(); returnCode = userManager.StatusCode; } userManager.StatusMessage = userManager.GetStateMessage(returnCode); // 更新员工信息 if (entity != null) { if (entity.IsStaff != null && entity.IsStaff > 0) { //BaseStaffManager staffManager = new BaseStaffManager(dbHelper, result); //string staffId = staffManager.GetIdByUserId(entity.Id); //if (!string.IsNullOrEmpty(staffId)) //{ // BaseStaffEntity staffEntity = staffManager.GetObject(staffId); // staffEntity.Code = entity.Code; // staffEntity.Birthday = entity.Birthday; // staffEntity.Gender = entity.Gender; // staffEntity.UserName = entity.UserName; // staffEntity.RealName = entity.RealName; // staffEntity.QQ = entity.QQ; // staffEntity.Mobile = entity.Mobile; // staffEntity.Telephone = entity.Telephone; // staffEntity.Email = entity.Email; // staffEntity.CompanyId = entity.CompanyId; // staffEntity.SubCompanyId = entity.SubCompanyId; // staffEntity.DepartmentId = entity.DepartmentId; // staffEntity.WorkgroupId = entity.WorkgroupId; // staffManager.Update(staffEntity); //} } } returnCode = userManager.StatusCode; returnMessage = userManager.StatusMessage; }); statusCode = returnCode; statusMessage = returnMessage; return(result); }
/// <summary> /// 忘记密码按电子邮件获取 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户信息</param> /// <param name="userName">用户名</param> /// <param name="email">电子邮件</param> /// <returns>成功</returns> public bool GetPasswordByEmail(string taskId, BaseUserInfo userInfo, string userName, string email) { var result = false; var manager = new BaseUserContactManager(); var parameters = new List <KeyValuePair <string, object> >(); if (!string.IsNullOrEmpty(email)) { parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email)); } var id = manager.GetId(parameters); if (!string.IsNullOrEmpty(id)) { var userManager = new BaseUserManager(); var userNameOk = true; var userEntity = userManager.GetEntity(id); if (!string.IsNullOrEmpty(userName)) { if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName, StringComparison.Ordinal)) { userNameOk = false; userInfo = null; } } if (userNameOk) { userInfo = userManager.ConvertToUserInfo(userEntity); } } if (!string.IsNullOrEmpty(id)) { var userPassword = string.Empty; if (BaseSystemInfo.CheckPasswordStrength) { userPassword = RandomUtil.GetString(8).ToLower(); } else { userPassword = RandomUtil.GetString(8).ToLower(); // Random random = new System.Random(); // userPassword = random.Next(100000, 999999).ToString(); } // 邮件内容 var smtpClient = new SmtpClient(BaseSystemInfo.MailServer) { UseDefaultCredentials = false, Credentials = new NetworkCredential(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword), // 指定如何处理待发的邮件 DeliveryMethod = SmtpDeliveryMethod.Network }; var mailTitle = BaseSystemInfo.SoftFullName + "忘记密码"; var mailBody = "您的新密码为:" + userPassword + " " + Environment.NewLine + "<br/> " + Environment.NewLine + BaseSystemInfo.SoftFullName + "访问地址: http://www.wangcaisoft.com/"; // 读取模板文件 var file = BaseSystemInfo.StartupPath + "\\Forgot.Mail.txt"; if (System.IO.File.Exists(file)) { mailBody = System.IO.File.ReadAllText(file, Encoding.UTF8); mailBody = mailBody.Replace("{Realname}", userInfo.RealName); mailBody = mailBody.Replace("{UserPassword}", userPassword); } // 发送邮件 var mailMessage = new MailMessage(BaseSystemInfo.MailUserName, email, mailTitle, mailBody) { BodyEncoding = Encoding.Default, IsBodyHtml = true }; smtpClient.Send(mailMessage); var userManager = new BaseUserManager(userInfo); userManager.SetPassword(userInfo.UserId, userPassword); userManager.GetStateMessage(); if (userManager.StatusCode == Status.SetPasswordOk.ToString()) { result = true; } else { result = false; } } return(result); }
public int ImportUser(System.Data.IDataReader dataReader, BaseOrganizeManager organizeManager, BaseUserLogOnManager userLogOnManager, BaseUserContactManager userContactManager) { int result = 0; BaseUserEntity userEntity = this.GetObject(dataReader["ID"].ToString()); if (userEntity == null) { userEntity = new BaseUserEntity(); userEntity.Id = dataReader["ID"].ToString(); } userEntity.Id = dataReader["ID"].ToString(); userEntity.UserFrom = "K8"; userEntity.UserName = dataReader["USER_NAME"].ToString(); userEntity.IDCard = dataReader["ID_Card"].ToString(); userEntity.Code = dataReader["EMPLOYEE_CODE"].ToString(); userEntity.RealName = dataReader["REAL_NAME"].ToString(); if (string.IsNullOrWhiteSpace(userEntity.RealName)) { userEntity.RealName = dataReader["EMPLOYEE_NAME"].ToString(); } userEntity.NickName = dataReader["ONLY_USER_NAME"].ToString(); userEntity.CompanyName = dataReader["OWNER_SITE"].ToString(); userEntity.Description = dataReader["REMARK"].ToString(); // 把被删除的数据恢复过来 userEntity.DeletionStateCode = 0; if (string.IsNullOrEmpty(userEntity.CompanyId)) { userEntity.CompanyId = organizeManager.GetProperty(new KeyValuePair <string, object>(BaseOrganizeEntity.FieldFullName, userEntity.CompanyName), BaseOrganizeEntity.FieldId); if (string.IsNullOrEmpty(userEntity.CompanyId)) { System.Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName); return(0); } } // 不是内部组织机构的才进行调整 if (string.IsNullOrEmpty(userEntity.DepartmentId)) { userEntity.DepartmentName = dataReader["DEPT_NAME"].ToString(); } if (!string.IsNullOrEmpty(dataReader["IM_NAME"].ToString())) { // userEntity.QQ = dataReader["IM_NAME"].ToString(); } userEntity.Enabled = int.Parse(dataReader["BL_LOCK_FLAG"].ToString()); System.Console.WriteLine("ImportK8User:"******":" + userEntity.RealName); // 02:可以把读取到的数据能写入到用户中心的。 result = this.UpdateObject(userEntity); if (result == 0) { this.AddObject(userEntity); } // 添加用户密码表 BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id); if (userLogOnEntity == null) { userLogOnEntity = new BaseUserLogOnEntity(); userLogOnEntity.Id = userEntity.Id; // 邦定mac地址 userLogOnEntity.CheckIPAddress = 1; userLogOnEntity.UserPassword = dataReader["USER_PASSWD"].ToString(); userLogOnEntity.Salt = dataReader["SALT"].ToString(); // 是否检查机器码 MAC地址 int checkIPAddress = 1; int.TryParse(dataReader["BL_CHECK_COMPUTER"].ToString(), out checkIPAddress); userLogOnEntity.CheckIPAddress = checkIPAddress; if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogOnEntity.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } userLogOnManager.AddObject(userLogOnEntity); } else { userLogOnEntity.Id = userEntity.Id; userLogOnEntity.UserPassword = dataReader["USER_PASSWD"].ToString(); userLogOnEntity.Salt = dataReader["SALT"].ToString(); if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogOnEntity.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } result = userLogOnManager.UpdateObject(userLogOnEntity); } // 用户的联系方式 BaseUserContactEntity userContactEntity = userContactManager.GetObject(userEntity.Id); if (userContactEntity == null) { userContactEntity = new BaseUserContactEntity(); userContactEntity.Id = userEntity.Id; userContactEntity.QQ = dataReader["QQ"].ToString(); userContactEntity.Mobile = dataReader["Mobile"].ToString(); userContactEntity.Email = dataReader["Email"].ToString(); userContactManager.AddObject(userContactEntity); } else { if (!string.IsNullOrEmpty(dataReader["QQ"].ToString())) { userContactEntity.QQ = dataReader["QQ"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Mobile"].ToString())) { userContactEntity.Mobile = dataReader["Mobile"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Email"].ToString())) { userContactEntity.Email = dataReader["Email"].ToString(); } userContactManager.UpdateObject(userContactEntity); } return(result); }
/// <summary> /// 增加用户账号 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool AddUser(TAB_USEREntity user) { //1、先往中天里添加账号 BaseUserEntity userEntity = new BaseUserEntity(); BaseUserManager userManager = new BaseUserManager(); BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(); userEntity.UserFrom = "K8"; userEntity.UserName = user.USER_NAME; userEntity.Code = user.EMPLOYEE_CODE; userEntity.RealName = user.REAL_NAME; userEntity.CompanyName = user.OWNER_SITE; var organize = new BaseOrganizeManager().GetObjectByName(user.OWNER_SITE); if (organize != null) { userEntity.CompanyId = organize.Id.ToString(); } userEntity.Description = user.REMARK; userEntity.DeletionStateCode = 0; userEntity.DepartmentName = user.DEPT_NAME; userEntity.Enabled = int.Parse(user.BL_LOCK_FLAG.ToString()); bool identity = false; if (!string.IsNullOrEmpty(userEntity.Id)) { identity = true; } userEntity.Id = userManager.Add(userEntity, identity, true); //添加用户密码表 BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id); userLogOnEntity = new BaseUserLogOnEntity(); userLogOnEntity.Id = userEntity.Id; //邦定mac地址 userLogOnEntity.CheckIPAddress = 1; var salt = BaseRandom.GetRandomString(20); userLogOnEntity.Salt = salt; userLogOnEntity.UserPassword = userManager.EncryptUserPassword(user.USER_PASSWD, salt); //是否检查机器码 MAC地址 int checkIPAddress = 1; int.TryParse(user.BL_CHECK_COMPUTER.ToString(), out checkIPAddress); userLogOnEntity.CheckIPAddress = checkIPAddress; userLogOnManager.AddObject(userLogOnEntity); //用户的联系方式 BaseUserContactManager userContactManager = new BaseUserContactManager(); BaseUserContactEntity userContactEntity = new BaseUserContactEntity(); userContactEntity.Id = userEntity.Id; if (!string.IsNullOrEmpty(user.MOBILE)) { userContactEntity.Mobile = user.MOBILE; } userContactManager.AddObject(userContactEntity); //2、再往K8里加用户 TAB_USERManager tabUserManager = new TAB_USERManager(); TAB_USERPOPEDOMManager userMenuManager = new TAB_USERPOPEDOMManager(); user.CREATE_SITE = Utilities.UserInfo.CompanyName; user.CREATE_USER = Utilities.UserInfo.RealName; user.CREATE_DATE = DateTime.Now; user.USER_NAME = user.USER_NAME.Trim(); user.ID = decimal.Parse(userEntity.Id); tabUserManager.Add(user, false, true); var sql = string.Format(" UPDATE TAB_USER SET USER_PASSWORD=NULL,USER_PASSWD='{0}',SALT ='{1}', CHANGEPASSWORDDATE=to_date('{2}','yyyy-mm-dd-hh24:mi:ss') WHERE ID = '{3}'", userEntity.UserPassword, salt, DateTime.Now, user.ID); tabUserManager.ExecuteNonQuery(sql); //3、新增账号的时候默认增加新员工的权限为网点员工 var roleMenus = GetMenusByUserCode("网点员工", "", "上海"); foreach (var roleMenu in roleMenus) { TAB_USERPOPEDOMEntity userPOPEDOM = new TAB_USERPOPEDOMEntity(); userPOPEDOM.BL_INSERT = roleMenu.BL_INSERT; userPOPEDOM.BL_UPDATE = roleMenu.BL_UPDATE; userPOPEDOM.BL_DELETE = roleMenu.BL_DELETE; userPOPEDOM.USER_NAME = user.USER_NAME; userPOPEDOM.OWNER_SITE = user.OWNER_SITE; userPOPEDOM.MENU_GUID = roleMenu.MENU_GUID; userMenuManager.Add(userPOPEDOM); } return(true); }
/// <summary> /// 导入用户 /// </summary> /// <param name="dataReader"></param> /// <param name="organizationManager"></param> /// <param name="userLogonManager"></param> /// <param name="userContactManager"></param> /// <returns></returns> public int ImportUser(IDataReader dataReader, BaseOrganizationManager organizationManager, BaseUserLogonManager userLogonManager, BaseUserContactManager userContactManager) { var result = 0; var userEntity = GetEntity(dataReader["ID"].ToString()); if (userEntity == null) { userEntity = new BaseUserEntity { Id = dataReader["ID"].ToString().ToInt() }; } userEntity.Id = dataReader["ID"].ToString().ToInt(); userEntity.UserFrom = "K8"; userEntity.UserName = dataReader["USER_NAME"].ToString(); userEntity.IdCard = dataReader["ID_Card"].ToString(); userEntity.Code = dataReader["EMPLOYEE_CODE"].ToString(); userEntity.RealName = dataReader["REAL_NAME"].ToString(); if (string.IsNullOrWhiteSpace(userEntity.RealName)) { userEntity.RealName = dataReader["EMPLOYEE_NAME"].ToString(); } userEntity.NickName = dataReader["ONLY_USER_NAME"].ToString(); userEntity.CompanyName = dataReader["OWNER_SITE"].ToString(); userEntity.Description = dataReader["REMARK"].ToString(); // 把被删除的数据恢复过来 userEntity.Deleted = 0; if (userEntity.CompanyId > 0) { if (string.IsNullOrEmpty(organizationManager.GetProperty(new KeyValuePair <string, object>(BaseOrganizationEntity.FieldName, userEntity.CompanyName), BaseOrganizationEntity.FieldId))) { Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName); return(0); } } // 不是内部组织机构的才进行调整 if (userEntity.DepartmentId > 0) { userEntity.DepartmentName = dataReader["DEPT_NAME"].ToString(); } if (!string.IsNullOrEmpty(dataReader["IM_NAME"].ToString())) { // userEntity.QQ = dataReader["IM_NAME"].ToString(); } userEntity.Enabled = int.Parse(dataReader["BL_LOCK_FLAG"].ToString()); Console.WriteLine("ImportK8User:"******":" + userEntity.RealName); // 02:可以把读取到的数据能写入到用户中心的。 result = UpdateEntity(userEntity); if (result == 0) { AddEntity(userEntity); } // 添加用户密码表 var userLogonEntity = userLogonManager.GetEntityByUserId(userEntity.Id); if (userLogonEntity == null) { userLogonEntity = new BaseUserLogonEntity { UserId = userEntity.Id, // 邦定mac地址 CheckIpAddress = 1, UserPassword = dataReader["USER_PASSWD"].ToString(), Salt = dataReader["SALT"].ToString() }; // 是否检查机器码 MAC地址 var checkIpAddress = 1; int.TryParse(dataReader["BL_CHECK_COMPUTER"].ToString(), out checkIpAddress); userLogonEntity.CheckIpAddress = checkIpAddress; if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } userLogonManager.AddEntity(userLogonEntity); } else { userLogonEntity.UserId = userEntity.Id; userLogonEntity.UserPassword = dataReader["USER_PASSWD"].ToString(); userLogonEntity.Salt = dataReader["SALT"].ToString(); if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } result = userLogonManager.UpdateEntity(userLogonEntity); } // 用户的联系方式 var userContactEntity = userContactManager.GetEntityByUserId(userEntity.Id.ToString()); if (userContactEntity == null) { userContactEntity = new BaseUserContactEntity { UserId = userEntity.Id, Qq = dataReader["QQ"].ToString(), Mobile = dataReader["Mobile"].ToString(), Email = dataReader["Email"].ToString() }; userContactManager.AddEntity(userContactEntity); } else { if (!string.IsNullOrEmpty(dataReader["QQ"].ToString())) { userContactEntity.Qq = dataReader["QQ"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Mobile"].ToString())) { userContactEntity.Mobile = dataReader["Mobile"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Email"].ToString())) { userContactEntity.Email = dataReader["Email"].ToString(); } userContactManager.AddOrUpdate(userContactEntity); } return(result); }
/// <summary> /// 宋彪 2015-01-22 /// 向登录用户发送登录提醒消息 /// 1、邮件提醒;、2手机短信提醒;3、吉信提醒 /// 为了避免线程阻塞,使用一个新线程处理提醒消息的发送 /// 所有超管及IT信息中心的人员全部强制提醒 /// </summary> /// <param name="userInfo">用户登录信息</param> public void SendLogOnRemind(BaseUserInfo userInfo) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { //获取提醒实体信息 提醒要求已设置且启用 string systemName = userInfo.SystemCode; BaseUserLogonExtendManager manager = new BaseUserLogonExtendManager(); BaseUserLogonExtendEntity userLogonRemind = manager.GetObject(userInfo.Id); BaseUserContactEntity userContactEntity = new BaseUserContactManager().GetObject(userInfo.Id); WebClient webClient = new WebClient(); //提醒对象实体和联系信息实体存在则进行下一步 if (userLogonRemind != null && userContactEntity != null) { //发送吉信消息提醒 有唯一账号而且设置了在登录时发送吉信登录提醒 if (!string.IsNullOrWhiteSpace(userInfo.NickName) && userLogonRemind.JixinRemind == 1) { //吉信接口地址 string url = "http://jixin.zt-express.com:8280/mng/httpservices/msg-sendMessageToUsers.action"; NameValueCollection postValues = new NameValueCollection(); //为空则无发送者,客户无回复按钮+(v1.1) postValues.Add("sender", string.Empty); //关闭延迟 默认为30秒 +(v1.1) postValues.Add("closeDelay", "30"); //显示延迟 默认为0秒 +(v1.1) postValues.Add("showDelay", "0"); //接收者,以逗号分隔,包含中文需使用URL编码 // ReSharper disable once AssignNullToNotNullAttribute postValues.Add("receivers", System.Web.HttpUtility.UrlEncode(userInfo.NickName, System.Text.Encoding.UTF8)); //显示位置,0表示居中,1表示右下角(默认0) postValues.Add("position", "1"); //消息标题 postValues.Add("title", "中天系统账号登录提醒"); //消息内容 string content = "<div style='word-break:keep-all;'><font color='#FF7E00'>" + userInfo.NickName + "</font>,您的账号于<font color='#FF7E00'>" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "</font>登录了<font color='#FF7E00'>" + systemName + "</font></div>" + "<div style='word-break:keep-all;margin-top:5px'>登录IP:<font color='#FF7E00'>" + userInfo.IPAddress + "</font></div>" + "<div style=' word-break:keep-all;margin-top:5px'>IP参考所在地:<font color='#FF7E00'>" + DotNet.Utilities.IpHelper.GetInstance().FindName(userInfo.IPAddress) + "</font></div>" + "<div style=' word-break:keep-all;margin-top:5px'>如果不是您自己登录,请马上联系:021-31165566,或即刻<a href='http://security.zt-express.com' target='_blank'>登录安全中心</a>修改密码。</div>"; postValues.Add("content", content); postValues.Add("width", "300"); postValues.Add("height", "180"); // 向服务器发送POST数据 webClient.UploadValues(url, postValues); } //用户邮箱存在,邮箱已经认证而且设置了使用登录时发送邮件提醒 if (!string.IsNullOrWhiteSpace(userContactEntity.Email) && userContactEntity.EmailValiated == 1 && userLogonRemind.EmailRemind == 1) { string subject = userInfo.CompanyName + " - " + userInfo.NickName + " 登录" + systemName + " 系统提醒"; string body = userInfo.UserName + System.Environment.NewLine + ":<br/>" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "登录了" + systemName + ";<br/>" + System.Environment.NewLine + "编号:" + userInfo.Code + ";<br/> " + System.Environment.NewLine + "登录系统:" + systemName + ";<br/> " + System.Environment.NewLine + "登录IP:" + userInfo.IPAddress + ";<br/> " + System.Environment.NewLine + "MAC地址:" + userInfo.MACAddress + ";<br/>" + System.Environment.NewLine + "如果不是您自己登录,请马上联系021-31165566,或即刻登录系统修改密码。"; SmtpClient smtp = new SmtpClient(); //邮箱的smtp地址 smtp.Host = "mail.zto.cn";//BaseSystemInfo.MailServer; //端口号 smtp.Port = 25; //构建发件人的身份凭据类 //smtp.Credentials = new NetworkCredential(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword); smtp.Credentials = new NetworkCredential("remind", "ztoremind#@!~"); //构建消息类 MailMessage objMailMessage = new MailMessage(); //设置优先级 objMailMessage.Priority = MailPriority.High; //消息发送人 objMailMessage.From = new MailAddress("remind", "中通快递登录提醒", System.Text.Encoding.UTF8); //收件人 objMailMessage.To.Add(userContactEntity.Email); //标题 objMailMessage.Subject = subject; //标题字符编码 objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8; //正文 objMailMessage.Body = body; objMailMessage.IsBodyHtml = true; //内容字符编码 objMailMessage.BodyEncoding = System.Text.Encoding.UTF8; //发送 smtp.Send(objMailMessage); } //用户手机存在,已验证,而且设置了登录时发送手机短信提醒 需要对网点扣费 if (!string.IsNullOrWhiteSpace(userContactEntity.Mobile) && userContactEntity.MobileValiated == 1 && userLogonRemind.MobileRemind == 1) { //根据朱工建议,增加判断登陆地是否发生变化 //获取最近两次的登录记录 按时间降序查询 BaseLoginLogManager loginLogManager = new BaseLoginLogManager(userInfo); List <BaseLoginLogEntity> loginLogEntities = loginLogManager.GetList <BaseLoginLogEntity>(new KeyValuePair <string, object>(BaseLoginLogEntity.FieldUserId, UserInfo.Id), 2, " CREATEON DESC "); IpHelper ipHelper = new IpHelper(); string addressA = ipHelper.FindName(loginLogEntities[0].IPAddress); if (string.IsNullOrWhiteSpace(addressA)) { addressA = ipHelper.FindName(loginLogEntities[0].IPAddress); } string addressB = ipHelper.FindName(loginLogEntities[1].IPAddress); if (string.IsNullOrWhiteSpace(addressB)) { addressB = ipHelper.FindName(loginLogEntities[1].IPAddress); } if (loginLogEntities[0] != null && loginLogEntities[1] != null && (!string.Equals(loginLogEntities[0].IPAddress, loginLogEntities[1].IPAddress, StringComparison.OrdinalIgnoreCase) || !string.Equals(addressA, addressB, StringComparison.OrdinalIgnoreCase) )) { string url = "http://mas.zto.cn/WebAPIV42/API/Mobile/SendMessageByCompanyCode"; NameValueCollection postValues = new NameValueCollection(); postValues.Add("companyCode", userInfo.CompanyCode); postValues.Add("mobiles", userContactEntity.Mobile); string message = userInfo.NickName + ",您好!您的账号于" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "登录了" + systemName + ",登录IP:" + userInfo.IPAddress + ",如果不是您自己登录,请马上联系021-31165566,或即刻登录安全中心修改密码。"; postValues.Add("message", message); postValues.Add("customerName", userInfo.NickName); webClient.UploadValues(url, postValues); } } //微信提醒 if (!string.IsNullOrWhiteSpace(userContactEntity.WeChat) && userContactEntity.WeChatValiated == 1 && userLogonRemind.WechatRemind == 1) { string url = "http://weixin.zto.cn/Template/WeiXinLogin"; NameValueCollection postValues = new NameValueCollection(); postValues.Add("first", "您已经成功登录系统"); postValues.Add("keyword1", userInfo.NickName); postValues.Add("remark", userInfo.NickName + ",您的账号于" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + "登录了" + systemName); postValues.Add("OpenId", userContactEntity.WeChat); //postValues.Add("url", "http://security.zt-express.com/changepassword"); 详情的链接 webClient.UploadValues(url, postValues); } } } catch (Exception ex) { FileUtil.WriteMessage(userInfo.NickName + "登录提醒消息发送异常:" + ex.Message, System.Web.HttpContext.Current.Server.MapPath("~/Log/") + "Log" + DateTime.Now.ToString(BaseSystemInfo.DateFormat) + ".txt"); } }); }
/// <summary> /// 增加用户账号 /// 传入dbhelper 方法调用使用事务 避免部分同步成功 /// </summary> /// <param name="userEntity"></param> /// <param name="userContact"></param> /// <param name="userCenterDbHelper"></param> /// <param name="k8DbHelper"></param> /// <returns></returns> public bool AddUser(BaseUserEntity userEntity, BaseUserContactEntity userContact, IDbHelper userCenterDbHelper, IDbHelper k8DbHelper) { //1、先往中天里添加账号 BaseUserManager userManager = new BaseUserManager(userCenterDbHelper); userEntity.UserFrom = "Security"; userEntity.CreateBy = Utilities.UserInfo.RealName; userEntity.CreateUserId = Utilities.UserInfo.Id; bool identity = false; if (string.IsNullOrEmpty(userEntity.Id)) { identity = true; } userEntity.Id = userManager.Add(userEntity, identity, true); //添加用户密码表 BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(userCenterDbHelper); BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id); userLogOnEntity = new BaseUserLogOnEntity(); userLogOnEntity.Id = userEntity.Id; //是否验证邦定mac地址,默认绑定 userLogOnEntity.CheckIPAddress = 1; //产生盐 var salt = BaseRandom.GetRandomString(20); userLogOnEntity.Salt = salt; userLogOnEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword, salt); //是否检查机器码MAC地址 userLogOnManager.AddObject(userLogOnEntity); //添加用户的联系方式 BaseUserContactManager userContactManager = new BaseUserContactManager(userCenterDbHelper); userContact.MobileValiated = 1; userContactManager.AddObject(userContact); //2、再往K8里加用户 TAB_USERManager tabUserManager = new TAB_USERManager(k8DbHelper); TAB_USEREntity tabUserEntity = new TAB_USEREntity(); tabUserEntity.OWNER_SITE = userEntity.CompanyName; tabUserEntity.DEPT_NAME = userEntity.DepartmentName; tabUserEntity.USER_NAME = userEntity.UserName.ToLower(); tabUserEntity.EMPLOYEE_CODE = userEntity.Code; tabUserEntity.EMPLOYEE_NAME = userEntity.RealName; tabUserEntity.REAL_NAME = userEntity.RealName; tabUserEntity.ONLY_USER_NAME = userEntity.NickName.ToLower(); tabUserEntity.ID_CARD = userEntity.IDCard; tabUserEntity.MOBILE = userContact.Mobile; tabUserEntity.CREATE_SITE = Utilities.UserInfo.CompanyName; tabUserEntity.CREATE_USER = Utilities.UserInfo.RealName; tabUserEntity.CREATE_DATE = DateTime.Now; tabUserEntity.BL_LOCK_FLAG = 1; tabUserEntity.BL_TYPE = 0; tabUserEntity.BL_CHECK_COMPUTER = 1; tabUserEntity.BL_CHECK_NAME = 1; tabUserEntity.ID = decimal.Parse(userEntity.Id); tabUserEntity.USER_DATE = DateTime.Now.AddYears(3); tabUserManager.Add(tabUserEntity, false, true); //更新密码和盐 var sql = string.Format(" UPDATE TAB_USER SET USER_PASSWORD=NULL,USER_PASSWD='{0}',SALT ='{1}', CHANGEPASSWORDDATE=to_date('{2}','yyyy-mm-dd-hh24:mi:ss') WHERE ID = '{3}'", userEntity.UserPassword, salt, DateTime.Now, tabUserEntity.ID); tabUserManager.ExecuteNonQuery(sql); //3、新增账号的时候默认增加新员工的权限为网点员工 var roleMenus = GetMenusByUserCode(k8DbHelper, "网点员工", "", "上海"); TAB_USERPOPEDOMManager userMenuManager = new TAB_USERPOPEDOMManager(k8DbHelper); foreach (var roleMenu in roleMenus) { TAB_USERPOPEDOMEntity userPOPEDOM = new TAB_USERPOPEDOMEntity(); userPOPEDOM.BL_INSERT = roleMenu.BL_INSERT; userPOPEDOM.BL_UPDATE = roleMenu.BL_UPDATE; userPOPEDOM.BL_DELETE = roleMenu.BL_DELETE; userPOPEDOM.USER_NAME = tabUserEntity.USER_NAME; userPOPEDOM.OWNER_SITE = tabUserEntity.OWNER_SITE; userPOPEDOM.MENU_GUID = roleMenu.MENU_GUID; userMenuManager.Add(userPOPEDOM); } return(true); }
/// <summary> /// 忘记密码按手机号码获取 /// </summary> /// <param name="applicationCode">应用编号</param> /// <param name="accountCode">账户</param> /// <param name="password">密码</param> /// <param name="userName">用户名</param> /// <param name="mobile">手机号码</param> /// <returns>成功</returns> public bool GetPasswordByMobile(BaseUserInfo userInfo, string userName, string mobile) { bool result = false; if (!string.IsNullOrEmpty(mobile)) { BaseUserContactManager manager = new BaseUserContactManager(); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); if (!string.IsNullOrEmpty(mobile)) { parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldMobile, mobile)); } // 手机号码重复不发验证码,防止把别人的密码给修改了 DataTable dt = manager.GetDataTable(parameters); string id = string.Empty; if (dt != null && dt.Rows.Count == 1) { id = dt.Rows[0][BaseUserContactEntity.FieldId].ToString(); } BaseUserManager userManager = null; if (!string.IsNullOrEmpty(id)) { userManager = new BaseUserManager(); bool userNameOK = true; BaseUserEntity userEntity = userManager.GetObject(id); if (!string.IsNullOrEmpty(userName)) { if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName)) { userNameOK = false; userInfo = null; } } // 只有有效的用户,才能获取密码,被删除的,无效的,不可以获取密码 if (userEntity.Enabled == 0 || userEntity.DeletionStateCode == 1) { userNameOK = false; userInfo = null; } if (userNameOK) { userInfo = userManager.ConvertToUserInfo(userEntity); } else { userInfo = null; } } if (!string.IsNullOrEmpty(id) && userInfo != null) { string userPassword = string.Empty; if (BaseSystemInfo.CheckPasswordStrength) { userPassword = BaseRandom.GetRandomString(8).ToLower(); } else { userPassword = BaseRandom.GetRandomString(8).ToLower(); // Random random = new System.Random(); // userPassword = random.Next(100000, 999999).ToString(); } // 看是否有合理的请求参数 if (!string.IsNullOrEmpty(userPassword)) { // 看是否一天超过了3次了 int sendUserPasswordCount = this.GetSendUserPasswordCount(mobile); if (sendUserPasswordCount < 4) { // 应用编号 if (this.SendUserPassword(userInfo, mobile, userPassword)) { userManager = new BaseUserManager(userInfo); // 按手机号码获取的,可以自动解锁,防止密码连续输入错误,然后手机号码获取密码后,是被锁定状态,提高工作效率 userManager.SetPassword(userInfo.Id, userPassword, true); userManager.GetStateMessage(); if (userManager.StatusCode == Status.SetPasswordOK.ToString()) { result = true; } } } } } } return(result); }
/// <summary> /// 忘记密码按电子邮件获取 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户信息</param> /// <param name="userName">用户名</param> /// <param name="email">电子邮件</param> /// <returns>成功</returns> public bool GetPasswordByEmail(string taskId, BaseUserInfo userInfo, string userName, string email) { bool result = false; BaseUserContactManager manager = new BaseUserContactManager(); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); if (!string.IsNullOrEmpty(email)) { parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email)); } string id = manager.GetId(parameters); if (!string.IsNullOrEmpty(id)) { BaseUserManager userManager = new BaseUserManager(); bool userNameOK = true; BaseUserEntity userEntity = userManager.GetObject(id); if (!string.IsNullOrEmpty(userName)) { if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName)) { userNameOK = false; userInfo = null; } } if (userNameOK) { userInfo = userManager.ConvertToUserInfo(userEntity); } } if (!string.IsNullOrEmpty(id)) { string userPassword = string.Empty; if (BaseSystemInfo.CheckPasswordStrength) { userPassword = BaseRandom.GetRandomString(8).ToLower(); } else { userPassword = BaseRandom.GetRandomString(8).ToLower(); // Random random = new System.Random(); // userPassword = random.Next(100000, 999999).ToString(); } // 邮件内容 SmtpClient smtpClient = new SmtpClient(BaseSystemInfo.MailServer); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword); // 指定如何处理待发的邮件 smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; string mailTitle = BaseSystemInfo.SoftFullName + "忘记密码"; string mailBody = "您的新密码为:" + userPassword + " " + System.Environment.NewLine + "<br/> " + System.Environment.NewLine + BaseSystemInfo.SoftFullName + "访问地址: http://www.zto.cn/"; // 读取模板文件 string file = BaseSystemInfo.StartupPath + "\\Forgot.Mail.txt"; if (System.IO.File.Exists(file)) { mailBody = System.IO.File.ReadAllText(file, Encoding.UTF8); mailBody = mailBody.Replace("{Realname}", userInfo.RealName); mailBody = mailBody.Replace("{UserPassword}", userPassword); } // 发送邮件 MailMessage mailMessage = new MailMessage(BaseSystemInfo.MailUserName, email, mailTitle, mailBody); mailMessage.BodyEncoding = Encoding.Default; mailMessage.IsBodyHtml = true; smtpClient.Send(mailMessage); BaseUserManager userManager = new BaseUserManager(userInfo); userManager.SetPassword(userInfo.Id, userPassword); userManager.GetStateMessage(); if (userManager.StatusCode == Status.SetPasswordOK.ToString()) { result = true; } else { result = false; } } return(result); }
/// <summary> /// 发送邮件提醒 /// </summary> /// <param name="workFlowCurrentEntity">当前审核流实体信息</param> /// <param name="auditStatus">审核状态</param> /// <param name="auditIdea">审核意见</param> /// <param name="userIds">发送给用户主键</param> /// <param name="roleIds">发送给角色主键</param> /// <returns>影响行数</returns> public virtual int SendMail(BaseWorkFlowCurrentEntity workFlowCurrentEntity, AuditStatus auditStatus, string[] userIds, string organizeId, string roleId) { int result = 0; // 这里是检查邮件服务器是否设置了,若没设置就没必要发送邮件了 if (string.IsNullOrEmpty(BaseSystemInfo.MailServer) || string.IsNullOrEmpty(BaseSystemInfo.MailUserName) || string.IsNullOrEmpty(BaseSystemInfo.MailPassword)) { return(result); } // 这里是考虑了,同时发给多个人的情况 List <string> userList = new List <string>(); foreach (var userid in userIds) { if (!string.IsNullOrEmpty(userid)) { if (userid.IndexOf(',') > 0) { string[] users = userid.Split(',').Distinct <string>().Where(t => !string.IsNullOrEmpty(t)).ToArray(); foreach (var id in users) { if (!string.IsNullOrEmpty(id)) { userList.Add(id); } } } else { userList.Add(userid); } } } userIds = userList.ToArray(); // 不用给自己发消息了,消息多了也烦恼 userIds = StringUtil.Remove(userIds, this.UserInfo.Id); string mailTitle = workFlowCurrentEntity.ActivityFullName + " " + workFlowCurrentEntity.ObjectFullName + " " + workFlowCurrentEntity.AuditStatusName; // 邮件内容 SmtpClient smtpClient = new SmtpClient(BaseSystemInfo.MailServer); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword); // 指定如何处理待发的邮件 smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; string mailBody = string.Empty; string auditIdea = string.Empty; if (!string.IsNullOrEmpty(workFlowCurrentEntity.AuditIdea)) { auditIdea = " 批示: " + workFlowCurrentEntity.AuditIdea; } if (BaseSystemInfo.SimpleReminders) { mailBody = "有单据" + BaseBusinessLogic.GetAuditStatus(auditStatus); } else { mailBody = workFlowCurrentEntity.CreateBy + " 发出审批申请: " + "<a title='点击这里,直接查看单据' target='_blank' href='" + this.GetUrl(workFlowCurrentEntity.Id) + "'>" + workFlowCurrentEntity.ObjectFullName + "</a> " + Environment.NewLine + this.UserInfo.RealName + " " + BaseBusinessLogic.GetAuditStatus(auditStatus) + " " + Environment.NewLine + auditIdea; } for (int i = 0; i < userIds.Length; i++) { string mailTo = BaseUserContactManager.GetEmailByCache(userIds[i]); if (!string.IsNullOrEmpty(mailTo)) { try { MailMessage mailMessage = new MailMessage(BaseSystemInfo.MailUserName, mailTo, mailTitle, mailBody); mailMessage.BodyEncoding = Encoding.Default; mailMessage.IsBodyHtml = true; smtpClient.Send(mailMessage); result++; } catch { } } } return(result); }