コード例 #1
0
        public ActionResult Register(string userName, string email, string password, string confirmPassword, string returnUrl = null)
        {
            ViewData["PasswordLength"] = MinPasswordLength;

            if (ValidateRegistration(userName, email, password, confirmPassword))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = _membershipService.CreateUser(new CreateUserParams(userName, password, email, false)) as UserRecord;

                if (user != null)
                {
                    if (user.EmailStatus == UserStatus.Pending)
                    {
                        //_userService.SendChallengeEmail(user.As<UserPart>(), nonce => Url.MakeAbsolute(Url.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl));

                        _userEventHandler.SentChallengeEmail(user);
                        return(RedirectToAction("ChallengeEmailSent"));
                    }

                    if (user.RegistrationStatus == UserStatus.Pending)
                    {
                        return(RedirectToAction("RegistrationPending"));
                    }

                    _authenticationService.SignIn(user, false /* createPersistentCookie */);
                    return(this.RedirectLocal(returnUrl));
                }

                ModelState.AddModelError("_FORM", ErrorCodeToString(/*createStatus*/ MembershipCreateStatus.ProviderError));
            }

            // If we got this far, something failed, redisplay form
            return(View("Register"));
        }
コード例 #2
0
        public ActionResult Register(string userName, string email, string password, string confirmPassword, string returnUrl = null)
        {
            // ensure users can register
            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();

            if (!registrationSettings.UsersCanRegister)
            {
                return(HttpNotFound());
            }

            ViewData["PasswordLength"] = MinPasswordLength;

            if (ValidateRegistration(userName, email, password, confirmPassword))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = _membershipService.CreateUser(new CreateUserParams(userName, password, email, null, null, false));

                if (user != null)
                {
                    if (user.As <UserPart>().EmailStatus == UserStatus.Pending)
                    {
                        var siteUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl;
                        if (String.IsNullOrWhiteSpace(siteUrl))
                        {
                            siteUrl = HttpContext.Request.ToRootUrlString();
                        }

                        _userService.SendChallengeEmail(user.As <UserPart>(), nonce => Url.MakeAbsolute(Url.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl));

                        _userEventHandler.SentChallengeEmail(user);
                        return(RedirectToAction("ChallengeEmailSent", new { ReturnUrl = returnUrl }));
                    }

                    if (user.As <UserPart>().RegistrationStatus == UserStatus.Pending)
                    {
                        return(RedirectToAction("RegistrationPending", new { ReturnUrl = returnUrl }));
                    }

                    _userEventHandler.LoggingIn(userName, password);
                    _authenticationService.SignIn(user, false /* createPersistentCookie */);
                    _userEventHandler.LoggedIn(user);

                    return(this.RedirectLocal(returnUrl));
                }

                ModelState.AddModelError("_FORM", T(ErrorCodeToString(/*createStatus*/ MembershipCreateStatus.ProviderError)));
            }

            // If we got this far, something failed, redisplay form
            var shape = _orchardServices.New.Register();

            return(new ShapeResult(this, shape));
        }
コード例 #3
0
        public ActionResult Register(string userName, string email, string password, string confirmPassword, string returnUrl = null, bool createPersistentCookie = false)
        {
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Request.QueryString["ReturnUrl"];
            }
            // ensure users can register
            var membershipSettings = _membershipService.GetSettings();

            if (!membershipSettings.UsersCanRegister)
            {
                return(HttpNotFound());
            }

            ViewData["PasswordLength"]              = membershipSettings.GetMinimumPasswordLength();
            ViewData["LowercaseRequirement"]        = membershipSettings.GetPasswordLowercaseRequirement();
            ViewData["UppercaseRequirement"]        = membershipSettings.GetPasswordUppercaseRequirement();
            ViewData["SpecialCharacterRequirement"] = membershipSettings.GetPasswordSpecialRequirement();
            ViewData["NumberRequirement"]           = membershipSettings.GetPasswordNumberRequirement();

            var shape = _orchardServices.New.Register();

            // validate user part, create a temp user part to validate input
            var userPart = _contentManager.New("User");

            if (userPart != null && !_frontEndProfileService.UserHasNoProfilePart(userPart.As <IUser>()))
            {
                shape.UserProfile = ((IFrontEndEditService)_frontEndProfileService).BuildFrontEndShape(
                    _contentManager.UpdateEditor(userPart, this),
                    _frontEndProfileService.MayAllowPartEdit,
                    _frontEndProfileService.MayAllowFieldEdit);
                if (!ModelState.IsValid)
                {
                    _orchardServices.TransactionManager.Cancel();
                    return(new ShapeResult(this, shape));
                }
            }

            if (ValidateRegistration(userName, email, password, confirmPassword))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = _membershipService.CreateUser(new CreateUserParams(userName, password, email, null, null, false));

                if (user != null)
                {
                    if (!_frontEndProfileService.UserHasNoProfilePart(user))
                    {
                        // we know userpart data is ok, now we update the 'real' recently published userpart
                        ((IFrontEndEditService)_frontEndProfileService).BuildFrontEndShape(
                            _contentManager.UpdateEditor(user, this),
                            _frontEndProfileService.MayAllowPartEdit,
                            _frontEndProfileService.MayAllowFieldEdit);
                    }

                    var userPart2 = user.As <UserPart>();
                    if (user.As <UserPart>().EmailStatus == UserStatus.Pending)
                    {
                        _userService.SendChallengeEmail(user.As <UserPart>(), nonce => Url.AbsoluteAction(() => Url.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce })));

                        _userEventHandler.SentChallengeEmail(user);
                        return(RedirectToAction("ChallengeEmailSent", "Account", new { area = "Orchard.Users" }));
                    }

                    if (user.As <UserPart>().RegistrationStatus == UserStatus.Pending)
                    {
                        return(RedirectToAction("RegistrationPending", "Account", new { area = "Orchard.Users" }));
                    }

                    _userEventHandler.LoggingIn(userName, password);
                    _authenticationService.SignIn(user, createPersistentCookie);
                    _userEventHandler.LoggedIn(user);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(this.RedirectLocal(returnUrl));
                    }

                    return(Redirect(string.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix) ?
                                    "~/" :
                                    "~/" + _shellSettings.RequestUrlPrefix.Trim('/')));
                }

                ModelState.AddModelError("_FORM", T(ErrorCodeToString(/*createStatus*/ MembershipCreateStatus.ProviderError)));
            }

            // If we got this far, something failed, redisplay form
            //var shape = _orchardServices.New.Register();
            return(new ShapeResult(this, shape));
        }
コード例 #4
0
        public HttpResponseMessage Register(Register Register)
        {
            // ensure users can register
            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();

            if (!registrationSettings.UsersCanRegister)
            {
                return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new uError("Method Not Allowed", 405)));
            }

            if (Register.Password.Length < MinPasswordLength)
            {
                return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new uError("Method Not Allowed", 405)));
            }

            if (!_profileService.VerifyUserUnicity(Register.Email, Register.Email))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, new uError("Conflict on the Server", 409)));
            }
            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(Register.ApiKey);

            if (apprecord == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new uError("Not Found", 404)));
            }

            if (ValidateRegistration(Register))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = _membershipService.CreateUser(new CreateUserParams(Register.Email, Register.Password, Register.Email, null, null, false));

                if (user != null)
                {
                    UserProfilePart profile = user.As <UserProfilePart>();
                    if (profile != null)
                    {
                        profile.FirstName = Register.FirstName;
                        profile.LastName  = Register.LastName;
                    }
                    if (user.As <UserPart>().EmailStatus == UserStatus.Pending)
                    {
                        var siteUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl;
                        //if (String.IsNullOrWhiteSpace(siteUrl))
                        //{
                        //    siteUrl = Request.ToRootUrlString();
                        //}
                        //var url = Url.Route("challengeemail", new { controller = "login", action = "ChallengeEmail", returnUrl = "hello" });

                        var _Url = new System.Web.Mvc.UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

                        _profileService.SendChallengeMail(
                            apprecord,
                            user.As <UserPart>(),
                            nonce =>

                            _Url.MakeAbsolute(
                                _Url.Action("ChallengeEmail", "Account", new
                        {
                            Area  = "Contrib.Foundation.UserProfile",
                            nonce = nonce
                        }
                                            )
                                )

                            //_Url.MakeAbsolute(
                            //    _Url.Action("ChallengeEmail", "login", new
                            //        {
                            //            httproute = true,
                            //            area = "Contrib.Foundation.UserProfile",
                            //            nonce = nonce
                            //        }
                            //    )
                            //)

                            //protocolChallengeEmail(nonce)
                            );
                        _userEventHandler.SentChallengeEmail(user);
                        return(Request.CreateResponse(HttpStatusCode.Created, new uError("Create", 201, false)));
                    }

                    if (user.As <UserPart>().RegistrationStatus == UserStatus.Pending)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotModified, new uError("Not Modified", 304)));
                    }

                    _authenticationService.SignIn(user, false);
                    return(Request.CreateResponse(HttpStatusCode.OK, new uError("OK", 200)));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new uError("Internal Server Error", 500)));
            }

            return(Request.CreateResponse(HttpStatusCode.InternalServerError, new uError("Internal Server Error", 500)));;
        }
コード例 #5
0
        public ActionResult Register(UserRegistrationViewModel viewModel, string returnUrl = null)
        {
            var membershipSettings = membershipService.GetSettings();

            // ensure users can register
            if (!membershipSettings.UsersCanRegister)
            {
                return(HttpNotFound());
            }

            if (!ModelState.IsValid)
            {
                return(new ShapeResult(this, CreateRegisterShape(viewModel, membershipSettings)));
            }

            // Generate a username from username + random 8 characters this will be useful for searching later
            var username = $"{viewModel.FirstName.Trim()}-{RandomHelper.GenerateRandomCharacters(8)}";

            if (ValidateRegistration(username, viewModel.Email, viewModel.Password, viewModel.ConfirmPassword))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = membershipService.CreateUser(
                    new CreateUserParams(
                        username,
                        viewModel.Password,
                        viewModel.Email,
                        null,
                        null,
                        false
                        )
                    );

                if (user != null)
                {
                    UpdateUserProfile(user, viewModel);
                    TempData["Email"] = viewModel.Email;

                    if (user.As <UserPart>().EmailStatus == UserStatus.Pending)
                    {
                        var siteUrl = orchardService.WorkContext.CurrentSite.BaseUrl;
                        if (string.IsNullOrWhiteSpace(siteUrl))
                        {
                            siteUrl = HttpContext.Request.ToRootUrlString();
                        }

                        // To make it available in an email template without changing Orchard.User core project
                        HttpContext.Items["userProfilePart"] = user.As <BasicUserProfilePart>();

                        userService.SendChallengeEmail(
                            user.As <UserPart>(),
                            nonce => Url.MakeAbsolute(
                                Url.Action("ChallengeEmail",
                                           "Account",
                                           new { Area = "Orchard.Users", nonce }),
                                siteUrl
                                )
                            );

                        userEventHandler.SentChallengeEmail(user);
                        return(RedirectToAction(
                                   nameof(OrchardAccountController.ChallengeEmailSent),
                                   "Account",
                                   new { ReturnUrl = returnUrl, Area = "Orchard.Users" }
                                   ));
                    }

                    if (user.As <UserPart>().RegistrationStatus == UserStatus.Pending)
                    {
                        return(RedirectToAction(
                                   nameof(OrchardAccountController.RegistrationPending),
                                   "Account",
                                   new { ReturnUrl = returnUrl, Area = "Orchard.Users" }
                                   ));
                    }

                    userEventHandler.LoggingIn(username, viewModel.Password);
                    // Force log in user
                    authenticationService.SignIn(user, false /* createPersistentCookie */);
                    userEventHandler.LoggedIn(user);
                    return(this.RedirectLocal(returnUrl));
                }

                ModelState.AddModelError(
                    "_FORM",
                    T(ErrorCodeToString(/*createStatus*/ MembershipCreateStatus.ProviderError))
                    );
            }

            // If we got this far, something failed, redisplay form
            return(new ShapeResult(this, CreateRegisterShape(viewModel, membershipSettings)));
        }