public ActionResult Close(string id) { using (SystemDbContext mydb = new SystemDbContext()) { List<UserModels> tmp = mydb.Users.Where(p => p.CompanyId.Equals(id)).ToList(); foreach(UserModels user in tmp) user.IsProved = false; mydb.Entry(tmp).State = System.Data.Entity.EntityState.Modified; mydb.SaveChanges(); return RedirectToAction("Index"); } }
public JsonResult GenerateVerifyCode() { var PhoneNumber = Request["PhoneNumber"]; string code = (new Random().Next(1111, 9999)).ToString(); string content = "盆景办公提醒您,您的验证码为:" + code; //向用户发送验证码 // int rect = sendOnce(PhoneNumber, content); int rect = 1; //短信验证发送失败! if (rect <= 0) { return Json(new { errorcode = rect }); } using (var vCode = new SystemDbContext()) { var tmp = vCode.VerifyCodes.Find(PhoneNumber); DateTime createTime = System.DateTime.Now; //电话在数据库中已经存在,更新Code和CreateTime以及OverTime就可以 if (tmp != null) { tmp.Code = code; tmp.CreateTime = createTime; tmp.OverTime = createTime.AddSeconds(VerifyCodeOverTimeSeconds); vCode.Entry(tmp).State = System.Data.Entity.EntityState.Modified; vCode.SaveChanges(); } else { VerifyCode tmpCode = new VerifyCode(); tmpCode.Code = code; tmpCode.PhoneNumber = PhoneNumber; tmpCode.CreateTime = createTime; tmpCode.OverTime = createTime.AddSeconds(VerifyCodeOverTimeSeconds); vCode.VerifyCodes.Add(tmpCode); vCode.SaveChanges(); } } return Json(new { errorcode="1"}); }
public ActionResult ForgotPasswordApply(UserPasswordInfo info, HttpPostedFileBase image) { SystemDbContext db = new SystemDbContext(); if (ModelState.IsValid) { //UserPasswordInfo info = new UserPasswordInfo(); db.UserPasswordInfos.Add(info); if (image != null) { info.BusinessLicenseType = image.ContentType;//获取图片类型 //view.BusinessLicence = new byte[image.ContentLength];//新建一个长度等于图片大小的二进制地址 // image.InputStream.Read(view.BusinessLicence, 0, image.ContentLength);//将image读取到Logo中 info.BusinessLicense = new byte[image.ContentLength]; image.InputStream.Read(info.BusinessLicense, 0, image.ContentLength); } DateTime time = DateTime.Now; /*利用Expression表达式树可以解决:LINQ to Entities 不识别方法“System.DateTime AddMinutes(Double)*/ Expression<Func<UserPasswordInfo, bool>> where = p => p.UserName == info.UserName && (p.SubmitTime.AddMinutes(2) >= time); // var item = from p in db.UserPasswordInfos where (p.UserName == info.UserName && (p.SubmitTime.AddMinutes(2)<=time)) select p; var item = db.UserPasswordInfos.Where(where.Compile()).ToList(); if (item.Count() == 0) { /*审核状态字段*/ // info.AuditStatus = "ture"; info.SubmitTime = time; db.SaveChanges(); // return RedirectToAction("ForgotPasswordInfo"); return RedirectToAction("ForgotPassword"); } else return RedirectToAction("ForgotPasswordInfoError"); } return View(info); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { //首先核对用户的短信验证码是否合法 using (var vCode = new SystemDbContext()) { var CurrentUserCode = vCode.VerifyCodes.Find(model.PhoneNumber); DateTime CurTime = System.DateTime.Now; if (CurTime > CurrentUserCode.OverTime) //用户短信验证码超时 { ModelState.AddModelError("", "抱歉,您的验证码已经过期!"); return View(model); } else if (!CurrentUserCode.Code.Equals(model.Code)) { ModelState.AddModelError("", "抱歉,您的验证码输入错误!"); return View(model); } } //验证企业全称是否已经被注册 using (var vUser = new SystemDbContext()) { var tmp = vUser.Users.Where(p => p.CompanyFullName.Equals(model.CompanyFullName)).ToList(); if (tmp.Count != 0) { ModelState.AddModelError("", "抱歉,该企业全称已经被注册!"); return View(model); } } var user = new ApplicationUser { CompanyFullName = model.CompanyFullName, PhoneNumber = model.PhoneNumber, UserName = model.PhoneNumber, IsProved = false, //是否审核的标志 IsAvailable = true, //是否是可用的管理员 IsRoot = true //注册企业号的人默认就是企业的超级管理员 }; //生成企业ID号 user.CompanyId = Generate.GenerateCompanyId(); string CompanyDbName = "Bonsaii" + user.CompanyId; user.ConnectionString = ConfigurationManager.AppSettings["UserDbConnectionString"] + CompanyDbName + ";" ; //"Data Source = localhost,1433;Network Library = DBMSSOCN;Initial Catalog = " + CompanyDbName + ";User ID = test;Password = admin;"; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //添加注册的企业信息到Companies数据表当中 using (SystemDbContext sys = new SystemDbContext()) { Company company = new Company() { CompanyId = user.CompanyId, FullName = user.CompanyFullName, TelNumber = user.UserName, UserName = user.UserName }; sys.Companies.Add(company); sys.SaveChanges(); } /** * 注册成功并不会为企业创建独有的数据库,只有系统平台的超级管理员通过相应用户的审核之后才会为用户创建数据库 * */ // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // 有关如何启用帐户确认和密码重置的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=320771 // 发送包含此链接的电子邮件 // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "确认你的帐户", "请通过单击 <a href=\"" + callbackUrl + "\">這裏</a>来确认你的帐户"); return RedirectToAction("Login", "Account"); } AddErrors(result); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return View(model); }
public ActionResult SwitchIsAvailable(string id) { using (SystemDbContext con = new SystemDbContext()) { UserModels user = con.Users.Find(id); user.IsAvailable = user.IsAvailable ? false : true; con.SaveChanges(); } return RedirectToAction("Index"); }