public JsonResult Register(string returnUrl, UserRegisterModel usr, string InviteCode, string VerifyCode = "") { if (ModelState.IsValid) { var icm = new InviteCodeManager(); if (!icm.Valid(InviteCode)) { return(Json(new { result = false, msg = "您的邀请码已被使用或无效,请重新获取邀请码." })); } if (string.IsNullOrEmpty(VerifyCode) || !string.Equals(CurrentVerifyCode, VerifyCode, StringComparison.InvariantCultureIgnoreCase)) { return(Json(new { result = false, msg = "您输入的验证码错误,请重新输入." })); } if (UserHelper.Exists(usr.UserName)) { return(Json(new { result = false, msg = "您选择用户名已被注册,请重新输入一个." })); } if (!usr.Password.Equals(usr.ConfirmPassword, StringComparison.InvariantCultureIgnoreCase)) { return(Json(new { result = false, msg = "您两次输入的密码不一致,请重试." })); } if (string.IsNullOrEmpty(usr.Email) || !usr.Email.IsEmail()) { return(Json(new { result = false, msg = "您输入的邮箱格式不正确,请重新输入." })); } if (UserHelper.Register(usr)) { //使用邀请码 icm.UseInviteCode(InviteCode, Membership.GetUser(usr.UserName).ProviderUserKey.ToString(), usr.UserName); #region /*(-_-)*/ 发送激活邮件/*(-_-)*/ //生成激活邮件 var cm = new ConfirmationManager(usr.UserName); var code = cm.Generator(); //发送邮件 var confirmUrl = string.Format("http://yqurl.com/User/Confirmation/{0}", code); var email = new EmailManager(usr.Email, "跃迁网用户验证邮件", string.Format("请点击链接以下链接,若不能点击请复制到浏览器地址栏。<a href=\"0\" target=\"_blank\">{0}</a>", confirmUrl)); email.SendEmail(); #endregion return(Json(new { result = true, msg = "注册成功!将转到用户中心.", url = string.IsNullOrEmpty(returnUrl) ? "/User" : returnUrl })); } } return(Json(new { result = false, msg = "注册失败,请重试!" })); }
public ActionResult Register(string returnUrl, string invite = "") { ViewBag.ReturnUrl = returnUrl; if (Request.IsAuthenticated && Roles.IsUserInRole(User.Identity.Name, "User")) { if (!string.IsNullOrEmpty(returnUrl)) { return(RedirectPermanent(returnUrl)); } return(RedirectToAction("Index", "User")); } if (!string.IsNullOrEmpty(invite)) { var icm = new InviteCodeManager(); if (!icm.Valid(invite)) { return(Content("您的邀请码无效,请先去获取邀请码吧!")); } ViewBag.InviteCode = invite; return(View()); } return(Content("未开放未测!")); }