public string chongzhimima(string tel, string password, string yanzhengma) { if (tel == null) { return("{error:'电话号码不能为空'}"); } if (yanzhengma == null) { return("{error:'验证码不能为空'}"); } string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$"; Regex rgx = new Regex(pattern); if (!rgx.IsMatch(tel)) { return("{error:'电话号不正确'}"); } if (password == null) { return("{error:'密码不能为空'}"); } if (password.Length < 6) { return("{error:'密码长度不能小于6'}"); } using (Entity entity = new Entity()) { UserSMS userSMS = entity.UserSMS .Where(o => o.Tel == tel && o.State == 0) .OrderByDescending(o => o.SentTime) .FirstOrDefault(); if (userSMS == null) { return("{error:'验证码不正确'}"); } User user = entity.User .Where(o => o.Tel == tel) .FirstOrDefault(); if (user == null) { return("{error:'账号不存在'}"); } string passwordTemp = CommonSecurity.SHA1MD5MD5(password); user.PassWord = passwordTemp; userSMS.State = 1; entity.SaveChanges(); Authentication authentication = new Authentication(user.Tel, password); return(authentication.tokenUserTime()); } }
public string getyanzhengma(string tel, string ip) { DateTime dateTime = DateTime.Now; using (Entity entity = new Entity()) { DateTime dt = dateTime.AddDays(-1); var registerList = entity.UserSMS.Where(o => o.Ip == ip && o.SentTime > dt); if (registerList.Count() > 0) { if (registerList.Count() >= 20) { return("{error:'今天接收验证码数目已达上限'}"); } } registerList = entity.UserSMS.Where(o => o.Tel == tel && o.SentTime > dt); if (registerList.Count() > 0) { if (registerList.Count() >= 20) { return("{error:'该手机号码今天接收验证码数目已达上限'}"); } } Random random = new Random(); string yzm = random.Next(1000, 9999).ToString(); UserSMS userSMS = new UserSMS() { Ip = ip, Tel = tel, SentTime = dateTime, Yanzhengma = yzm, State = 0 }; userSMS.SerialNumber = DateTime.Now.ToString("yyyyMMddhhmmssfff" + random.Next(100, 999).ToString()); entity.UserSMS.Add(userSMS); entity.SaveChanges(); ThreadPool.QueueUserWorkItem(delegate(object a) { string tt = @"您的验证码是" + userSMS.Yanzhengma + " 请在10分钟内使用!"; string bb = SMS.sendSMS(userSMS.Tel, tt, userSMS.SerialNumber); }); } return("{message:'成功'}"); }
public string forget(string tel, string yanzhengma) { if (tel == null) { return("{error:'电话号码不能为空'}"); } if (yanzhengma == null) { return("{error:'验证码不能为空'}"); } using (Entity entity = new Entity()) { UserSMS userSMS = entity.UserSMS .Where(o => o.Tel == tel && o.State == 0) .OrderByDescending(o => o.SentTime) .FirstOrDefault(); if (userSMS == null) { return("{error:'验证码不正确'}"); } } return("{message:'成功'}"); }
public string regist(string tel, string password, string yanzhengma, string xingbie) { if (tel == null) { return("{error:'电话号码不能为空'}"); } if (yanzhengma == null) { return("{error:'验证码不能为空'}"); } if (xingbie == null || (xingbie != "男" && xingbie != "女")) { return("{error:'性别不正确'}"); } string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$"; Regex rgx = new Regex(pattern); if (!rgx.IsMatch(tel)) { return("{error:'电话号不正确'}"); } if (password == null) { return("{error:'密码不能为空'}"); } if (password.Length < 6) { return("{error:'密码长度不能小于6'}"); } using (Entity entity = new Entity()) { UserSMS userSMS = entity.UserSMS .Where(o => o.Tel == tel && o.State == 0) .OrderByDescending(o => o.SentTime) .FirstOrDefault(); if (userSMS == null) { return("{error:'验证码不正确'}"); } if (entity.User.Where(o => o.Tel == tel).Count() > 0) { return("{error:'用户已经存在'}"); } string passwordTemp = CommonSecurity.SHA1MD5MD5(password); User user = new User() { Tel = tel, PassWord = passwordTemp, NickName = "分享玩家", CreatTime = DateTime.Now, UpdateTime = DateTime.Now, State = 1, Gender = xingbie }; entity.User.Add(user); user.UserExtend = new UserExtend(); user.UserExtend.Banned = 0; userSMS.State = 1; user.UserExtend.ExperienceLevel = 1; ExperienceLevel experienceLevel = entity.ExperienceLevel.Where(o => o.ExperienceLevelValue == user.UserExtend.ExperienceLevel).FirstOrDefault(); user.UserExtend.ExperienceValue = experienceLevel.ExperienceValueMin; if (user.Gender == "男") { user.UserExtend.ExperienceName = experienceLevel.NameMan; } else { user.UserExtend.ExperienceName = experienceLevel.NameWoman; } user.InitBeforeSave(); entity.SaveChanges(); Authentication authentication = new Authentication(user.Tel, password); if (!string.IsNullOrEmpty(authentication.state)) { return(authentication.state); } return(authentication.tokenUserTime()); } }