コード例 #1
0
ファイル: LoginJoinController.cs プロジェクト: formist/LinkMe
        protected ActionResult TryJoin(MemberJoin join, CheckBoxValue acceptTerms, Func <IErrorHandler> createErrorHandler)
        {
            try
            {
                join = join ?? new MemberJoin();

                // Process the post to check validations.

                if (acceptTerms == null || !acceptTerms.IsChecked)
                {
                    ModelState.AddModelError(new[] { new TermsValidationError("AcceptTerms") }, createErrorHandler());
                }

                // Try to join.

                if (acceptTerms != null && acceptTerms.IsChecked)
                {
                    var account = new MemberAccount
                    {
                        FirstName    = join.FirstName,
                        LastName     = join.LastName,
                        EmailAddress = join.EmailAddress,
                    };

                    var credentials = new AccountLoginCredentials
                    {
                        LoginId         = join.EmailAddress,
                        Password        = join.JoinPassword,
                        ConfirmPassword = join.JoinConfirmPassword,
                    };

                    _accountsManager.Join(HttpContext, account, credentials, true);
                    return(RedirectToUrl(JoinUrl));
                }

                // Not accepting terms so cannot proceed but also check whether any other fields fail validation.

                join.Prepare();
                join.Validate();
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, createErrorHandler());
            }

            return(null);
        }
コード例 #2
0
        public ActionResult Join(MemberJoin joinModel, bool acceptTerms)
        {
            try
            {
                joinModel = joinModel ?? new MemberJoin();

                // Process the post to check validations.

                if (acceptTerms)
                {
                    // Try to join.

                    var account = new MemberAccount
                    {
                        FirstName    = joinModel.FirstName,
                        LastName     = joinModel.LastName,
                        EmailAddress = joinModel.EmailAddress,
                    };

                    var credentials = new AccountLoginCredentials
                    {
                        LoginId         = joinModel.EmailAddress,
                        Password        = joinModel.JoinPassword,
                        ConfirmPassword = joinModel.JoinConfirmPassword,
                    };

                    _accountsManager.Join(HttpContext, account, credentials, true);
                }
                else
                {
                    ModelState.AddModelError(new[] { new TermsValidationError("AcceptTerms") }, new StandardErrorHandler());

                    // Not accepting terms so cannot proceed but also check whether any other fields fail validation.

                    joinModel.Prepare();
                    joinModel.Validate();
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }