public VerificationCodePage(string mainActionText, bool mainActionStyleDanger) { InitializeComponent(); _vm = BindingContext as VerificationCodeViewModel; _vm.Page = this; _vm.MainActionText = mainActionText; _mainActionButton.StyleClass = new[] { mainActionStyleDanger ? "btn-danger" : "btn-primary" }; }
VerificationCodeViewModel GetVerificationCode(string mobile, bool sendViaSMS) { var model = this._cache.Get <string, VerificationCodeViewModel>(mobile, ctx => { var code = new VerificationCodeViewModel(mobile, this._codeGenerator.GenerateNewVerifyCode()); ctx.Monitor(this._clock.When(TimeSpan.FromMinutes(2))); if (sendViaSMS) { this._sMSHelper.Send(new QCloudSMS(mobile, SMSNotifyTypes.VerifyCode, code.Code, 2.ToString())); } return(code); }); return(model.Request()); }
public ActionResult GenerateCode(VerificationCodeViewModel model) { if (!ValidateHelper.IsMobile(model.Phone)) { var r = new { Successed = false, Message = "请检查手机号" }; return(Json(r)); } Random rad = new Random(); int mobile_code = rad.Next(1000, 10000); var validateInfo = new SMSValidateInfo() { ValidateType = 0, Phone = model.Phone, VerificationCode = string.Format("{0}", mobile_code) }; bool bl = InsertValidateCode(validateInfo); if (!bl) { var r = new { Successed = false, Message = "发送失败" }; return(Json(r)); } try { bl = SMSes.Instance.SendSCVerifySMS(model.Phone, string.Format("{0}", mobile_code)); if (!bl) { var r = new { Successed = false, Message = "发送失败" }; return(Json(r)); } else { var r = new { Successed = true, Message = "OK" }; return(Json(r)); } } catch (Exception ex) { var r = new { Successed = false, Message = "发送失败" + ex.Message }; return(Json(r)); } }
public ActionResult VerificationCode(VerificationCodeViewModel verificationCode) { if (ModelState.IsValid) { var user = db.Users.FirstOrDefault(u => u.UserVerificationCode == verificationCode.UserVerificationCode); if (user != null) { Random random = new Random(); int MyUserCode = random.Next(10000000, 99000000); int MyVerificationCode = 0; bool isValidCod = false; while (!isValidCod) { Random random1 = new Random(); MyVerificationCode = random1.Next(100000, 990000); var userverificationcode = db.Users.FirstOrDefault(j => j.UserVerificationCode == MyVerificationCode.ToString()); if (userverificationcode == null) { isValidCod = true; } } user.IsActive = true; user.UserVerificationCode = MyVerificationCode.ToString(); db.SaveChanges(); if (user.Role.RoleName == "Admin") { return(Redirect("/Admin/Dashboard/Index")); } return(Redirect("/Customer/Index")); } else { ModelState.AddModelError("UserCode", "Your activation code is invalid"); } } return(View(verificationCode)); }
public ActionResult CheckVerificationCode(VerificationCodeViewModel model) { var validateInfo = new SMSValidateInfo() { ValidateType = 0, Phone = model.Phone, VerificationCode = string.Format("{0}", model.Code) }; bool bl = CheckSMSValidate(validateInfo); if (!bl) { var r = new { Successed = false, Message = "验证失败" }; return(Json(r)); } else { var r = new { Successed = true, Message = "验证成功" }; return(Json(r)); } }