public void New_member_sends_Approve_Member_email() { var model = RegisterModel.CreateModel(); model.Name = "Member name"; model.Email = "*****@*****.**"; var member = new Mock <IMember>(); member.SetupGet(x => x.Id).Returns(123); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); var token = Guid.NewGuid().ToString(); _tokenReader.Setup(x => x.TokenFor(member.Object.Id)).Returns((token, DateTime.Now)); _emailFormatter.Setup(x => x.FormatEmailContent("Approve member", "Approve member body", It.IsAny <Dictionary <string, string> >())) .Callback <string, string, Dictionary <string, string> >((subject, body, tokens) => { Assert.Equal(model.Name, tokens["name"]); Assert.Equal(model.Email, tokens["email"]); Assert.Equal(token, tokens["token"]); Assert.Equal(Request.Object.Url.Authority, tokens["domain"]); }) .Returns(("Approve member", "Approve member body")); using (var controller = CreateController(model, createMemberSucceeds: true)) { controller.CreateMember(model); _emailSender.Verify(x => x.SendEmail(model.Email, "Approve member", "Approve member body")); } }
public void Email_matching_requested_email_within_expiry_period_sends_Member_Exists_email() { var model = RegisterModel.CreateModel(); model.Name = "Member name"; model.Email = "*****@*****.**"; var otherMember = new Mock <IMember>(); var expiryDate = DateTime.Now.AddHours(12); otherMember.Setup(x => x.GetValue <DateTime>("requestedEmailTokenExpires", null, null, false)).Returns(expiryDate); _tokenReader.Setup(x => x.HasExpired(expiryDate)).Returns(false); base.MemberService.Setup(x => x.GetMembersByPropertyValue("requestedEmail", model.Email, StringPropertyMatchType.Exact)).Returns(new[] { otherMember.Object }); _emailFormatter.Setup(x => x.FormatEmailContent("Member exists", "Member exists body", It.IsAny <Dictionary <string, string> >())) .Callback <string, string, Dictionary <string, string> >((subject, body, tokens) => { Assert.Equal(model.Name, tokens["name"]); Assert.Equal(model.Email, tokens["email"]); Assert.Equal(Request.Object.Url.Authority, tokens["domain"]); }) .Returns(("Member exists", "Member exists body")); using (var controller = CreateController(model)) { controller.CreateMember(model); _emailSender.Verify(x => x.SendEmail(model.Email, "Member exists", "Member exists body")); } }
public JsonResult Register(string name, string email, string password, string repassword) { RegisterModelVM register = new RegisterModelVM() { Email = email, Name = name, Password = password, Repassword = repassword }; var message = ""; if (register.isModelValid()) { var model = RegisterModel.CreateModel(); var memberService = Services.MemberService; var member = memberService.CreateMemberWithIdentity(email, email, name, "Member"); memberService.Save(member); memberService.SavePassword(member, password); Members.Login(email, password); message = "Success"; } else { message = "Fail"; } return(Json(message)); }
/// <summary> /// Creates a model to use for registering new members with custom member properties /// </summary> /// <param name="memberTypeAlias"></param> /// <returns></returns> public virtual RegisterModel CreateRegistrationModel(string memberTypeAlias = null) { var provider = _membershipProvider; if (provider.IsUmbracoMembershipProvider()) { memberTypeAlias = memberTypeAlias ?? Constants.Conventions.MemberTypes.DefaultAlias; var memberType = _memberTypeService.Get(memberTypeAlias); if (memberType == null) { throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias); } var builtIns = Constants.Conventions.Member.GetStandardPropertyTypeStubs().Select(x => x.Key).ToArray(); var model = RegisterModel.CreateModel(); model.MemberTypeAlias = memberTypeAlias; model.MemberProperties = GetMemberPropertiesViewModel(memberType, builtIns).ToList(); return(model); } else { var model = RegisterModel.CreateModel(); model.MemberTypeAlias = string.Empty; return(model); } }
public MemberViewModel() { _member = new Member(null); RegisterModel = RegisterModel.CreateModel(); RegisterModel.UsernameIsEmail = false; RegisterModel.LoginOnSuccess = false; }
public void Duplicate_email_sets_ViewData_FormSuccess_to_true() { var model = RegisterModel.CreateModel(); using (var controller = CreateController(model, createMemberSucceeds: false, emailFieldError: "A member with this username already exists.")) { var result = controller.CreateMember(model); Assert.True((bool)controller.TempData["FormSuccess"]); } }
public void Duplicate_email_returns_RedirectToUmbracoPageResult() { var model = RegisterModel.CreateModel(); using (var controller = CreateController(model, createMemberSucceeds: false, emailFieldError: "A member with this username already exists.")) { var result = controller.CreateMember(model); Assert.IsType <RedirectToUmbracoPageResult>(result); } }
public void Email_in_TempData_for_view() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; using (var controller = CreateController(model)) { controller.CreateMember(model); Assert.Equal(controller.TempData["Email"], model.Email); } }
public void Other_error_is_added_to_ModelState_and_returns_baseResult() { var model = RegisterModel.CreateModel(); using (var controller = CreateController(model, createMemberSucceeds: false, emailFieldError: "Some other error.")) { var result = controller.CreateMember(model); Assert.True(controller.ModelState.ContainsKey(string.Empty)); Assert.Equal("Some other error.", controller.ModelState[string.Empty].Errors[0].ErrorMessage); Assert.Equal(_createMemberSuccessResult, result); } }
public void New_member_returns_RedirectToUmbracoPageResult() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(Mock.Of <IMember>()); using (var controller = CreateController(model, createMemberSucceeds: true)) { var result = controller.CreateMember(model); Assert.IsType <RedirectToUmbracoPageResult>(result); } }
public void Invalid_ModelState_returns_UmbracoPageResult_and_does_not_attempt_to_create_member() { var model = RegisterModel.CreateModel(); using (var controller = CreateController(model, createMemberSucceeds: true)) { controller.ModelState.AddModelError(string.Empty, "Any error"); var result = controller.CreateMember(model); _createMemberExecuter.Verify(x => x.CreateMember(controller.HandleRegisterMember, model), Times.Never); Assert.IsType <UmbracoPageResult>(result); } }
public void New_member_is_assigned_to_All_Members() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; var member = new Mock <IMember>(); member.SetupGet(x => x.Id).Returns(123); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); MemberService.Setup(x => x.AssignRole(member.Object.Id, Groups.AllMembers)); using (var controller = CreateController(model, createMemberSucceeds: true)) { controller.CreateMember(model); MemberService.VerifyAll(); } }
public void Fail_to_create_member_does_not_save_additional_properties() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; var member = new Mock <IMember>(); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); using (var controller = CreateController(model, createMemberSucceeds: false)) { var result = controller.CreateMember(model); base.MemberService.Verify(x => x.GetByEmail(model.Email), Times.Never); base.MemberService.Verify(x => x.Save(member.Object, true), Times.Never); } }
public void Email_matching_requested_email_within_expiry_period_does_not_attempt_to_create_member() { var model = RegisterModel.CreateModel(); var otherMember = new Mock <IMember>(); var expiryDate = DateTime.Now.AddHours(12); otherMember.Setup(x => x.GetValue <DateTime>("requestedEmailTokenExpires", null, null, false)).Returns(expiryDate); _tokenReader.Setup(x => x.HasExpired(expiryDate)).Returns(false); base.MemberService.Setup(x => x.GetMembersByPropertyValue("requestedEmail", model.Email, StringPropertyMatchType.Exact)).Returns(new[] { otherMember.Object }); using (var controller = CreateController(model)) { var result = controller.CreateMember(model); _createMemberExecuter.Verify(x => x.CreateMember(controller.HandleRegisterMember, model), Times.Never); } }
public void Email_matching_requested_email_within_expiry_period_sets_ViewData_FormSuccess_to_true() { var model = RegisterModel.CreateModel(); var otherMember = new Mock <IMember>(); var expiryDate = DateTime.Now.AddHours(12); otherMember.Setup(x => x.GetValue <DateTime>("requestedEmailTokenExpires", null, null, false)).Returns(expiryDate); _tokenReader.Setup(x => x.HasExpired(expiryDate)).Returns(false); base.MemberService.Setup(x => x.GetMembersByPropertyValue("requestedEmail", model.Email, StringPropertyMatchType.Exact)).Returns(new[] { otherMember.Object }); using (var controller = CreateController(model)) { var result = controller.CreateMember(model); Assert.True((bool)controller.TempData["FormSuccess"]); } }
public void Email_matching_requested_email_within_expiry_period_returns_RedirectToUmbracoPageResult() { var model = RegisterModel.CreateModel(); var otherMember = new Mock <IMember>(); var expiryDate = DateTime.Now.AddHours(12); otherMember.Setup(x => x.GetValue <DateTime>("requestedEmailTokenExpires", null, null, false)).Returns(expiryDate); _tokenReader.Setup(x => x.HasExpired(expiryDate)).Returns(false); base.MemberService.Setup(x => x.GetMembersByPropertyValue("requestedEmail", model.Email, StringPropertyMatchType.Exact)).Returns(new[] { otherMember.Object }); using (var controller = CreateController(model)) { var result = controller.CreateMember(model); Assert.IsType <RedirectToUmbracoPageResult>(result); } }
public void Creating_a_new_member_is_logged() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; var member = new Mock <IMember>(); member.SetupGet(x => x.Id).Returns(123); member.SetupGet(x => x.Username).Returns(model.Email); member.SetupGet(x => x.Key).Returns(Guid.NewGuid()); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); using (var controller = CreateController(model, createMemberSucceeds: true)) { controller.CreateMember(model); _logger.Verify(x => x.Info(typeof(CreateMemberSurfaceController), LoggingTemplates.CreateMember, member.Object.Username, member.Object.Key, typeof(CreateMemberSurfaceController), nameof(CreateMemberSurfaceController.CreateMember))); } }
public void New_member_is_not_logged_in_automatically() { var model = RegisterModel.CreateModel(); model.Email = "*****@*****.**"; var member = new Mock <IMember>(); member.SetupGet(x => x.Id).Returns(123); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); using (var controller = CreateController(model, createMemberSucceeds: true)) { controller.CreateMember(model); _createMemberExecuter.Setup(x => x.CreateMember(controller.HandleRegisterMember, model)) .Callback((Func <RegisterModel, ActionResult> executeFunction, RegisterModel modelToExecute) => { Assert.False(modelToExecute.LoginOnSuccess); }); } }
public void New_member_saves_email_and_token() { var model = RegisterModel.CreateModel(); var token = Guid.NewGuid().ToString(); var tokenExpiry = DateTime.UtcNow.AddDays(1); var member = new Mock <IMember>(); member.SetupGet(x => x.Id).Returns(123); _tokenReader.Setup(x => x.TokenFor(member.Object.Id)).Returns((token, tokenExpiry)); MemberService.Setup(x => x.GetByEmail(model.Email)).Returns(member.Object); using (var controller = CreateController(model, createMemberSucceeds: true)) { var result = controller.CreateMember(model); member.Verify(x => x.SetValue("totalLogins", 0, null, null), Times.Once); member.Verify(x => x.SetValue("approvalToken", token, null, null), Times.Once); member.Verify(x => x.SetValue("approvalTokenExpires", tokenExpiry, null, null), Times.Once); base.MemberService.Verify(x => x.Save(member.Object, true), Times.Once); } }
public void Duplicate_email_sends_Member_Exists_email() { var model = RegisterModel.CreateModel(); model.Name = "Member name"; model.Email = "*****@*****.**"; _emailFormatter.Setup(x => x.FormatEmailContent("Member exists", "Member exists body", It.IsAny <Dictionary <string, string> >())) .Callback <string, string, Dictionary <string, string> >((subject, body, tokens) => { Assert.Equal(model.Name, tokens["name"]); Assert.Equal(model.Email, tokens["email"]); Assert.Equal(Request.Object.Url.Authority, tokens["domain"]); }) .Returns(("Member exists", "Member exists body")); using (var controller = CreateController(model, createMemberSucceeds: false, emailFieldError: "A member with this username already exists.")) { controller.CreateMember(model); _emailSender.Verify(x => x.SendEmail(model.Email, "Member exists", "Member exists body")); } }
public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")] RegisterFormViewModel model) { try { // Save Plan Id for the view ViewData["PlanId"] = model.PlanId; var enrollAfterLogin = Convert.ToInt32(model.PlanId != null).ToString(); // Check the Member Id (Y number) if (model.PlanId == null) // Enrolled user { ModelState.Remove("registerModel.Zipcode"); var errorMessage = ValidateMemberIdCore(model.MemberId, model.DateOfBirth, true); if (errorMessage != null) { ModelState.AddModelError("registerModel.MemberId", errorMessage); } // check if yNumber is already registered in umbraco var registeredUsername = GetMemberRegisteredUsernameWithYNumber(model.MemberId); if (registeredUsername != null) { ModelState.AddModelError("registerModel.MemberId", "The Member ID you have entered is registered with existing user name: " + registeredUsername); } // if there's no error, try to get plan ID from api var planId = MakeInternalApiCall <string>("GetHealthPlanIdByMemberId", new Dictionary <string, string> { { "memberId", model.MemberId } }); if (planId != null) { ViewData["PlanId"] = model.PlanId; model.PlanId = planId; } } else { // is new user // Validate ZipCode if (!ComparePlansSurfaceController.IsValidZipCodeInternal(model.Zipcode)) { ModelState.AddModelError("registerModel.Zipcode", "Invalid Zip Code"); } } if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } // Create registration model and bind it with view model var registerModel = RegisterModel.CreateModel(); registerModel.Name = model.Username.Trim(); registerModel.UsernameIsEmail = false; registerModel.Email = model.Email.Trim(); registerModel.Username = model.Username.Trim(); registerModel.Password = model.Password.Trim(); registerModel.RedirectUrl = "for-members/verify-account/"; registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "firstName", Value = model.FirstName.Trim() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "lastName", Value = model.LastName.Trim() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "ssn", Value = model.Ssn.TrimNullable() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "zipCode", Value = model.Zipcode.TrimNullable() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "phoneNumber", Value = model.Phone.TrimNullable() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "yNumber", Value = model.MemberId.TrimNullable() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "healthplanid", Value = model.PlanId.TrimNullable() }); registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "enrollmentpageafterlogin", Value = enrollAfterLogin }); MembershipCreateStatus status; Members.RegisterMember(registerModel, out status, false); switch (status) { case MembershipCreateStatus.Success: // Sign the user out (Umbraco wont stop auto logging in - this is a hack to fix) Session.Clear(); FormsAuthentication.SignOut(); // Set the user to be not approved var memb = Membership.GetUser(model.Username); memb.IsApproved = false; Membership.UpdateUser(memb); // Send the user a verification link to activate their account var sendVerificationLinkModel = new SendVerificationLinkModel(); sendVerificationLinkModel.UserName = model.Username; sendVerificationLinkModel.RedirectUrl = "/for-members/verify-account/"; return(RedirectToAction("SendVerificationLink_GET", "EmailSurface", sendVerificationLinkModel)); case MembershipCreateStatus.InvalidUserName: ModelState.AddModelError("registerModel.Username", "Username is not valid"); break; case MembershipCreateStatus.InvalidPassword: ModelState.AddModelError("registerModel.Password", PasswordNotStrongEnough); break; case MembershipCreateStatus.InvalidQuestion: case MembershipCreateStatus.InvalidAnswer: //TODO: Support q/a http://issues.umbraco.org/issue/U4-3213 throw new NotImplementedException(status.ToString()); case MembershipCreateStatus.InvalidEmail: ModelState.AddModelError("registerModel.Email", "Email is invalid"); break; case MembershipCreateStatus.DuplicateUserName: ModelState.AddModelError("registerModel.Username", "A member with this username already exists"); break; case MembershipCreateStatus.DuplicateEmail: ModelState.AddModelError("registerModel.Email", "A member with this e-mail address already exists"); break; case MembershipCreateStatus.UserRejected: case MembershipCreateStatus.InvalidProviderUserKey: case MembershipCreateStatus.DuplicateProviderUserKey: case MembershipCreateStatus.ProviderError: //don't add a field level error, just model level ModelState.AddModelError("registerModel", "An error occurred creating the member: " + status); break; default: throw new ArgumentOutOfRangeException(); } return(CurrentUmbracoPage()); } catch (Exception ex) { // Create an error message with sufficient info to contact the user string additionalInfo = "Could not register user " + model.Username + "."; // Add the error message to the log4net output log4net.GlobalContext.Properties["additionalInfo"] = additionalInfo; return(CurrentUmbracoPage()); } }
public ActionResult Regsiter([Bind(Prefix = "registerModel")] MemberRegisterViewModel model) { ResponseModel result = new ResponseModel(); string code = Session["code"] == null ? string.Empty : Session["code"].ToString(); if (code != model.Code) { result.Success = false; result.Msg = "验证码错误,请重新获取验证码"; return(Json(result, JsonRequestBehavior.AllowGet)); } IMember validatemember = Services.MemberService.GetMembersByPropertyValue("tel", model.Phone).FirstOrDefault(); if (validatemember != null) { result.Success = false; result.Msg = "该手机号已经注册,请用手机号进行登录"; result.IsRedirect = false; return(Json(result, JsonRequestBehavior.AllowGet)); } RegisterModel registerModel = RegisterModel.CreateModel(); registerModel.Email = model.Phone + "@qq.com"; registerModel.Password = model.Password; registerModel.Name = "匿名"; MembershipCreateStatus status; //注册用户 var member = Members.RegisterMember(registerModel, out status, true); switch (status) { case MembershipCreateStatus.DuplicateEmail: case MembershipCreateStatus.DuplicateProviderUserKey: case MembershipCreateStatus.DuplicateUserName: { result.Success = false; result.Msg = "用户重复,请重新注册!"; break; } case MembershipCreateStatus.InvalidAnswer: break; case MembershipCreateStatus.InvalidEmail: { result.Success = false; result.Msg = "邮箱格式不正确请重新输入!"; break; } case MembershipCreateStatus.InvalidPassword: break; case MembershipCreateStatus.InvalidProviderUserKey: break; case MembershipCreateStatus.InvalidQuestion: break; case MembershipCreateStatus.InvalidUserName: break; case MembershipCreateStatus.ProviderError: break; case MembershipCreateStatus.Success: { var m = Services.MemberService.GetByUsername(member.UserName); m.SetValue("tel", model.Phone); //m.SetValue("fundAccount", "1000"); Services.MemberService.SavePassword(m, model.Password); Services.MemberService.Save(m); result.Success = true; //result.Msg = "欢迎您的加入,您成功注册,我们额外赠送1000元定期宝一个月"; result.Msg = "欢迎您的加入,您成功注册"; result.IsRedirect = true; //result.RedirectUrl = "/memberinfo?show=true"; result.RedirectUrl = "/memberinfo"; EventHandlers.CustomRaiseEvent.RaiseRegistered(m); //赠送5000元定期宝一月期 //System.Threading.Tasks.Task.Factory.StartNew((ser) => //{ // ServiceContext sc = ser as ServiceContext; // IContentType ct = sc.ContentTypeService.GetContentType("PayRecords"); // IContent content = sc.ContentService.CreateContent(m.Name + "赠送定期宝", ct.Id, "PayRecords"); // content.SetValue("username", m.Name); // content.SetValue("email", m.Username); // content.SetValue("amountCny", 1000); // content.SetValue("mobilePhone", m.GetValue<string>("tel")); // content.SetValue("rechargeDateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // content.SetValue("expirationtime", DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss")); // content.SetValue("memberPicker", m.Id); // content.SetValue("payBillno", "注册赠送的定期宝"); // content.SetValue("isdeposit", true); // content.SetValue("isexpired", false); // content.SetValue("buyproduct", 2337); // content.SetValue("isGive", true); // sc.ContentService.Save(content); // EventHandlers.CustomRaiseEvent.RaiseContentCreated(content); //}, Services); break; } case MembershipCreateStatus.UserRejected: break; default: break; } return(Json(result, JsonRequestBehavior.AllowGet)); }