/// <summary> /// 获取修改登录密码,核心企业入驻的短信验证码 /// </summary> /// <param name="JSon"></param> /// <param name="version"></param> /// <returns></returns> public ResultCaptcha GetCaptcha(string JSon, string version) { string phonenumb = string.Empty; string Type = string.Empty; int typeint = 0; string typename = string.Empty; string phonenum = string.Empty; List <Hi.Model.SYS_Users> userList = null; Hi.BLL.SYS_Users bll_user = new Hi.BLL.SYS_Users(); try { #region//JSon取值 JsonData JInfo = JsonMapper.ToObject(JSon); if (JInfo.Count > 0 && JInfo["PhoneNumb"].ToString().Trim() != "" && JInfo["Type"].ToString().Trim() != "") { phonenumb = JInfo["PhoneNumb"].ToString(); Type = JInfo["Type"].ToString(); } else { return(new ResultCaptcha() { Result = "T", Description = "参数异常" }); } #endregion //double loginnum = 0; //if (double.TryParse(phonenumb, out loginnum))//如果输入的登录名是整数,则先判断是否是手机号登录,不是手机号登录的话,再判断是否是账号名登录 //{ // userList = bll_user.GetList("", // "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); //} //if (userList == null || userList.Count <= 0)//不是手机号登录的话,再判断是不是账号名登录 //{ // userList = bll_user.GetList("", // "UserName = '******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); // //如果两种情况都没找到,就是账号不存在 // if (userList == null || userList.Count <= 0) // return new ResultCaptcha() { Result = "F", Description = "账号不存在" }; //} Hi.Model.SYS_Users user = new Hi.Model.SYS_Users(); switch (Type) { case "1": double loginnum = 0; if (double.TryParse(phonenumb, out loginnum)) //如果输入的登录名是整数,则先判断是否是手机号登录,不是手机号登录的话,再判断是否是账号名登录 { userList = bll_user.GetList("", "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); } if (userList == null || userList.Count <= 0) //不是手机号登录的话,再判断是不是账号名登录 { userList = bll_user.GetList("", "UserName = '******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); //如果两种情况都没找到,就是账号不存在 if (userList == null || userList.Count <= 0) { return new ResultCaptcha() { Result = "F", Description = "账号不存在" } } ; } user = userList[0]; typeint = -5; typename = "修改登录密码"; phonenum = user.Phone; break; case "2": //首先验证这手机号是否已经注册 List <Hi.Model.SYS_Users> list_users = bll_user.GetList("", "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); //如果已经注册,就不发送验证码,并提示 if (list_users != null && list_users.Count > 0) { return new ResultCaptcha() { Result = "F", Description = "该手机号码已注册过账号,请使用未注册的手机号码注册" } } ; typeint = -10; typename = "核心企业注册"; phonenum = phonenumb; break; default: return(new ResultCaptcha() { Result = "F", Description = "操作类型不存在" }); } //获取六位随机数 string PhoneCode = new Common().CreateRandomCode(6); GetPhoneCode getphonecode = new GetPhoneCode(); getphonecode.GetUser( System.Configuration.ConfigurationManager.AppSettings["PhoneCodeAccount"].ToString(), System.Configuration.ConfigurationManager.AppSettings["PhoneCodePwd"].ToString()); //手机发送验证码 string rstr = getphonecode.ReturnSTR(phonenum, PhoneCode); //信息发送成功的话需要在sys_phonecode表中插入一条数据 if (rstr == "Success") { Hi.Model.SYS_PhoneCode phonecode = new Hi.Model.SYS_PhoneCode(); phonecode.Type = typeint; phonecode.Module = typename; phonecode.Phone = phonenum; phonecode.PhoneCode = PhoneCode; phonecode.IsPast = 0; phonecode.UserID = user.ID; phonecode.UserName = ""; phonecode.CreateDate = DateTime.Now; phonecode.ts = DateTime.Now; phonecode.modifyuser = user.ID; int i = new Hi.BLL.SYS_PhoneCode().Add(phonecode); if (i > 0)//新增成功的话拼接返回参数 { ResultCaptcha resultcaptcha = new ResultCaptcha(); resultcaptcha.Result = "T"; resultcaptcha.Description = "返回成功"; resultcaptcha.SendId = i.ToString(); resultcaptcha.Captcha = PhoneCode; resultcaptcha.PhoneNumb = phonenum; return(resultcaptcha); } else { return(new ResultCaptcha() { Result = "F", Description = "验证码异常" }); } } else { return(new ResultCaptcha() { Result = "F", Description = "发送失败 " + rstr }); } } catch (Exception ex) { Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "GetCaptcha:" + JSon); return(new ResultCaptcha() { Result = "F", Description = "参数异常" }); } }
/// <summary> /// 修改密码 /// </summary> /// <param name="JSon"></param> /// <param name="version"></param> /// <returns></returns> public ResultLoginCaptcha GetLoginCaptcha(string JSon, string version) { string phonenumb = string.Empty; string password = string.Empty; string SendID = string.Empty; string Captcha = string.Empty; List <Hi.Model.SYS_Users> userList = new List <Hi.Model.SYS_Users>(); Hi.BLL.SYS_Users bll_user = new Hi.BLL.SYS_Users(); try { #region//JSon取值 JsonData JInfo = JsonMapper.ToObject(JSon); if (JInfo.Count > 0 && JInfo["PhoneNumb"].ToString().Trim() != "" && JInfo["Pwd"].ToString().Trim() != "" && JInfo["SendId"].ToString().Trim() != "" && JInfo["Captcha"].ToString().Trim() != "") { phonenumb = JInfo["PhoneNumb"].ToString(); password = JInfo["Pwd"].ToString(); SendID = JInfo["SendId"].ToString(); Captcha = JInfo["Captcha"].ToString(); } else { return(new ResultLoginCaptcha() { Result = "F", Description = "参数异常" }); } #endregion #region //判断登录账号是否存在 double loginnum = 0; //如果传入的登录账号是整数,先判断是否手机号登录 if (double.TryParse(phonenumb, out loginnum)) { userList = bll_user.GetList("", "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); } if (userList.Count <= 0) { userList = bll_user.GetList("", "UserName = '******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); //如果两种情况都没找到,就是账号不存在 if (userList == null || userList.Count <= 0) { return new ResultLoginCaptcha() { Result = "F", Description = "账号不存在" } } ; } Hi.Model.SYS_Users user = userList[0]; //验证验证码是否正确 Hi.Model.SYS_PhoneCode code = new Hi.BLL.SYS_PhoneCode().GetModel(int.Parse(SendID)); if (code != null && code.dr == 0) { if (code.ts.AddMinutes(30) < DateTime.Now || code.IsPast == 1) { return new ResultLoginCaptcha() { Result = "F", Description = "验证码过期" } } ; if (code.UserID.ToString() != user.ID.ToString()) { return new ResultLoginCaptcha() { Result = "F", Description = "非本人操作" } } ; if (code.PhoneCode != Captcha) { return new ResultLoginCaptcha() { Result = "F", Description = "验证码错误" } } ; } else { return(new ResultLoginCaptcha() { Result = "F", Description = "验证码不可用" }); } if (user.UserPwd == new GetPhoneCode().md5(password)) { return(new ResultLoginCaptcha() { Result = "F", Description = "新密码不能与老密码相同" }); } code.IsPast = 1; code.ts = DateTime.Now; code.modifyuser = user.ID; //更新sys_phonecode中此验证码的状态为已使用 if (new Hi.BLL.SYS_PhoneCode().Update(code)) { user.UserPwd = new GetPhoneCode().md5(password); user.ts = DateTime.Now; user.modifyuser = user.ID; //更新登录密码 if (new Hi.BLL.SYS_Users().Update(user)) { return(new ResultLoginCaptcha() { Result = "T", Description = "修改成功" }); } else { return(new ResultLoginCaptcha() { Result = "F", Description = "修改失败" }); } } else { return(new ResultLoginCaptcha() { Result = "F", Description = "验证码异常" }); } #endregion } catch (Exception ex) { Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "GetLoginCaptcha:" + JSon); return(new ResultLoginCaptcha() { Result = "F", Description = "参数异常" }); } }
public ResultLogin Login(string JSon, string version) { try { #region JSon取值 string LoginName = string.Empty; string PassWord = string.Empty; List <Hi.Model.SYS_Users> userList = null; Hi.BLL.SYS_Users bll_user = new Hi.BLL.SYS_Users(); int phone = 0; JsonData JInfo = JsonMapper.ToObject(JSon); if (JInfo.Count > 0 && JInfo["LoginName"].ToString() != "" && JInfo["PassWord"].ToString() != "") { LoginName = JInfo["LoginName"].ToString(); PassWord = JInfo["PassWord"].ToString(); } else { return(new ResultLogin() { Result = "F", Description = "参数为空异常" }); } #endregion //if (int.TryParse(LoginName, out phone))//如果登录账号输入的是整数,先判断是否手机号登录,没对应的手机号,再判断账号登录 //{ // userList = bll_user.GetList("", // "Phone = " + LoginName + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); //} if (version.ToLower() != "android" && version.ToLower() != "ios" && float.Parse(version) >= 8) { PassWord = AESHelper.Encrypt_MD5(PassWord); } double phone_double = 0; if (double.TryParse(LoginName, out phone_double))//如果登录账号输入的是整数,先判断是否手机号登录,没对应的手机号,再判断账号登录 { userList = bll_user.GetList("", "Phone = '" + LoginName + "' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); } if (userList == null || userList.Count <= 0) { userList = new Hi.BLL.SYS_Users().GetList("", " UserName='******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", ""); if (userList == null || userList.Count == 0) { return new ResultLogin() { Result = "F", Description = "账号密码错误" } } ; } //if (userList == null || userList.Count == 0) // return new ResultLogin() { Result = "F", Description = "账号密码错误" }; List <User> UserList = new List <User>(); foreach (var user in userList) { if (user.UserPwd != PassWord) { return new ResultLogin() { Result = "F", Description = "账号密码错误" } } ; List <Hi.Model.SYS_CompUser> compUserList = new Hi.BLL.SYS_CompUser().GetList("", "UserID='" + user.ID + "' and IsAudit=2 and IsNull(dr,0)=0 and isnull(IsEnabled,0) = 1", ""); if (compUserList != null && compUserList.Count > 0) { foreach (var compUser in compUserList) { User resultUser = new User(); resultUser.UserID = compUser.UserID; resultUser.CompID = compUser.CompID; resultUser.TrueName = user.TrueName; resultUser.Sex = user.Sex; resultUser.Phone = user.Phone; resultUser.IsEnabled = user.IsEnabled; //列表无判断,前台要使用此状态 Hi.Model.BD_Company comp = new Hi.BLL.BD_Company().GetModel(compUser.CompID); if (comp != null) { resultUser.Erptype = comp.Erptype; resultUser.CompName = comp.CompName; } else { // return new ResultLogin() { Result = "F", Description = "核心企业异常" }; } resultUser.UType = compUser.UType; resultUser.CType = compUser.CType; // 1:核心企业 2:经销商 resultUser.CompUserID = compUser.ID; if (compUser.CType == 2) { resultUser.DisID = compUser.DisID; Hi.Model.BD_Distributor dis = new Hi.BLL.BD_Distributor().GetModel(compUser.DisID); if (dis == null) { return new ResultLogin() { Result = "F", Description = "经销商异常" } } ; if (dis.IsEnabled == 0 || dis.dr == 1) { continue; } resultUser.DisName = dis.DisName; } UserList.Add(resultUser); } } else { return(new ResultLogin() { Result = "F", Description = "未找到登录信息" }); } } return(new ResultLogin() { Result = "T", Description = "登录成功", UserList = UserList }); } catch (Exception ex) { Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "Login:"******"F", Description = "参数异常" }); } }