public ActionResult Edit(string id, SmsUser user) { SmsUserContext con = new SmsUserContext(); SmsUser muser; try { // TODO: Add update logic here if (ModelState.IsValid) { user.ID = id; con.updateUser(user); return(RedirectToAction("Index")); } else { muser = con.getUser(id); return(View(muser)); } } catch { muser = con.getUser(id); return(View(muser)); } }
// GET: SmsUser/Edit/5 public ActionResult Edit(string id) { SmsUserContext con = new SmsUserContext(); SmsUser user = con.getUser(id); return(View(user)); }
public async Task <IActionResult> SavePhone(SmsUser model) { if (ModelState.IsValid) { await _smsSender.SendSMS(model.PhoneNumber, "Test code"); return(View("SendCode", new SendCodeModel { PhoneNumber = model.PhoneNumber })); } return(View("~/Views/Home/Index.cshtml", model)); }
public async Task <bool> AddSmsUser(SmsUser user) { if (await _context.SmsUsers.AnyAsync(x => x.PhoneNumber == x.PhoneNumber)) { return(false); } _context.SmsUsers.Add(user); await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Register(SmsRegisterModel smsRegisterModel, string returnUrl) { SmsUser smsUser = new SmsUser { Email = smsRegisterModel.Email, UserName = smsRegisterModel.Email }; var result = await userManager.CreateAsync(smsUser, smsRegisterModel.Password); if (result.Succeeded) { //如果需要邮件确认 if (userManager.Options.SignIn.RequireConfirmedEmail) { var code = await userManager.GenerateEmailConfirmationTokenAsync(smsUser); byte[] bytearr = Encoding.UTF8.GetBytes(code); code = WebEncoders.Base64UrlEncode(bytearr); var callbackUrl = Url.Action ("ConfirmEmail", "Account", new { area = "Admin", userId = smsUser.Id, code = code, returnUrl = returnUrl }, Request.Scheme); await EmailSender.SendEmailAsync(smsUser.Email, "邮件确认", $"<a href='{callbackUrl}'>点击确认</a>"); return(Json(new { code = 0, msg = "需要邮件确认" })); } //账户确认 if (userManager.Options.SignIn.RequireConfirmedAccount) { return(Json(new { code = 0, msg = "需要确认账户" })); } else { await signInManager.SignInAsync(smsUser, isPersistent : false); return(Json(new { code = 0, msg = "注册成功" })); } } string err = string.Empty; foreach (var error in result.Errors) { err += error.Description + ","; } return(Json(new { code = 0, msg = $"错误消息:{err}" })); }
public ActionResult Create(SmsUser user) { try { if (ModelState.IsValid) { SmsUserContext con = new SmsUserContext(); con.createUser(user); return(RedirectToAction("Index")); } // TODO: Add insert logic here else { return(View()); } } catch { return(View()); } }
public async Task <IActionResult> ConfirmEmail(string userId, string code) { if (Request.IsAjax()) { if (!string.IsNullOrWhiteSpace(userId) && !string.IsNullOrWhiteSpace(code)) { SmsUser smsUser = await userManager.FindByIdAsync(userId); byte[] bytearr = WebEncoders.Base64UrlDecode(code); code = Encoding.UTF8.GetString(bytearr); var result = await userManager.ConfirmEmailAsync(smsUser, code); if (result.Succeeded) { return(Json(new { code = 0, msg = "激活成功" })); } else { return(Json(new { code = 0, msg = result.Errors.Select(m => m.Description) })); } } } return(View()); }
public ActionResult Index(SmsUser smsUser) { return(View()); }