コード例 #1
0
        public ActionResult Register(PersonalDetails personalDetails, GuestOptions guestOptions)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            var existingMember = Services.MemberService.GetByEmail(personalDetails.Email);

            if (existingMember != null)
            {
                ModelState.AddModelError("Email", "There is already a member registered with the supplied email address.");
                return(CurrentUmbracoPage());
            }

            if (_guestRegistrationPage == null || !_guestRegistrationPage.GuestCodes.Contains(guestOptions.GuestCode, StringComparer.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("GuestCode", "The guest code does not match any available codes.");
                return(CurrentUmbracoPage());
            }

            Logger.Info(typeof(RegistrationController), $"New guest registration request: {JsonConvert.SerializeObject(personalDetails)}");

            string rootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host,
                                           Request.Url.Port == 80 ? string.Empty : ":" + Request.Url.Port);
            string successUrl = string.Format("{0}/the-club/confirm-registration", rootUrl);

            //TODO - Register guest
            var member        = _memberProvider.CreateMember(personalDetails, new string[] { MSTCRoles.Guest });
            var memberOptions = new MemberOptions()
            {
                MembershipType = MembershipTypeEnum.Guest,
                OpenWaterIndemnityAcceptance = guestOptions.OpenWaterIndemnityAcceptance,
                GuestCode = guestOptions.GuestCode,
            };

            _memberProvider.UpdateMemberDetails(member, personalDetails, memberOptions);

            //Login the member
            FormsAuthentication.SetAuthCookie(member.Username, true);

            string content = GetRegEmailContent(personalDetails, guestOptions);

            _emailProvider.SendEmail(EmailProvider.MembersEmail, EmailProvider.SupportEmail,
                                     "New MSTC guest registration", content);

            var model = new RegistrationCompleteModel()
            {
                PromptForConfirmation = false,
                IsRegistered          = true
            };

            TempData["Model"] = model;

            return(Redirect(successUrl));
        }
コード例 #2
0
        public ActionResult ConfirmPayment(RegistrationCompleteModel model)
        {
            model.PromptForConfirmation = false;
            RegistrationDetails registrationDetails = _sessionProvider.RegistrationDetails;

            if (registrationDetails == null || string.IsNullOrWhiteSpace(_sessionProvider.GoCardlessRedirectFlowId))
            {
                TempData["Model"] = model;
                return(CurrentUmbracoPage());
            }

            string mandateId = _goCardlessProvider.CompleteRedirectRequest(_sessionProvider.GoCardlessRedirectFlowId, _sessionProvider.SessionId);

            registrationDetails.PersonalDetails.DirectDebitMandateId = mandateId;

            var regDetails  = registrationDetails.PersonalDetails;
            int costInPence = _membershipCostCalculator.Calculate(registrationDetails.MemberOptions, DateTime.Now);

            model.Cost = (costInPence / 100m).ToString("N2");
            var paymentDescription = MemberProvider.GetPaymentDescription(registrationDetails.MemberOptions);
            var paymentResponse    = _goCardlessProvider.CreatePayment(Logger, regDetails.DirectDebitMandateId, regDetails.Email, costInPence, paymentDescription);

            model.IsRegistered = paymentResponse == PaymentResponseDto.Success;

            if (model.IsRegistered)
            {
                var member = _memberProvider.CreateMember(regDetails, new string[] { MSTCRoles.Member });
                _memberProvider.UpdateMemberDetails(member, registrationDetails.PersonalDetails, registrationDetails.MemberOptions);

                //Login the member
                FormsAuthentication.SetAuthCookie(member.Username, true);

                string content = GetRegEmailContent(registrationDetails, true);
                _emailProvider.SendEmail(EmailProvider.MembersEmail, EmailProvider.SupportEmail,
                                         "New MSTC member registration", content);

                _sessionProvider.RegistrationDetails      = null;
                _sessionProvider.GoCardlessRedirectFlowId = null;
                TempData["Model"] = model;
                return(CurrentUmbracoPage());
            }
            else
            {
                string content = GetRegEmailContent(registrationDetails, false);
                _emailProvider.SendEmail(EmailProvider.SupportEmail, EmailProvider.SupportEmail,
                                         "MSTC member registration problem", content);
            }

            TempData["Model"] = model;
            return(CurrentUmbracoPage());
        }