public async Task <HttpResponseMessage> PostRequestPasswordReset(RequestPasswordResetModel model)
        {
            // If this feature is switched off in configuration the UI will be amended to not make the request to reset password available.
            // So this is just a server-side secondary check.
            if (UmbracoConfig.For.UmbracoSettings().Security.AllowPasswordReset == false)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var identityUser = await SignInManager.UserManager.FindByEmailAsync(model.Email);

            if (identityUser != null)
            {
                var user = Services.UserService.GetByEmail(model.Email);
                if (user != null)
                {
                    var code = await UserManager.GeneratePasswordResetTokenAsync(identityUser.Id);

                    var callbackUrl = ConstructCallbackUrl(identityUser.Id, code);

                    var message = Services.TextService.Localize("resetPasswordEmailCopyFormat",
                                                                //Ensure the culture of the found user is used for the email!
                                                                UserExtensions.GetUserCulture(identityUser.Culture, Services.TextService),
                                                                new[] { identityUser.UserName, callbackUrl });

                    await UserManager.SendEmailAsync(identityUser.Id,
                                                     Services.TextService.Localize("login/resetPasswordEmailCopySubject",
                                                                                   //Ensure the culture of the found user is used for the email!
                                                                                   UserExtensions.GetUserCulture(identityUser.Culture, Services.TextService)),
                                                     message);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #2
0
        public static string Culture(User u)
        {
            if (ApplicationContext.Current == null)
            {
                return(string.Empty);
            }

            var found = UserExtensions.GetUserCulture(u.Language, ApplicationContext.Current.Services.TextService);

            return(found == null ? string.Empty : found.Name);
        }
Beispiel #3
0
        private async Task SendUserInviteEmailAsync(UserBasic userDisplay, string from, string fromEmail, IUser to, string message)
        {
            var token = await UserManager.GenerateEmailConfirmationTokenAsync((int)userDisplay.Id);

            var inviteToken = string.Format("{0}{1}{2}",
                                            (int)userDisplay.Id,
                                            WebUtility.UrlEncode("|"),
                                            token.ToUrlBase64());

            // Get an mvc helper to get the URL
            var http      = EnsureHttpContext();
            var urlHelper = new UrlHelper(http.Request.RequestContext);
            var action    = urlHelper.Action("VerifyInvite", "BackOffice",
                                             new
            {
                area   = GlobalSettings.GetUmbracoMvcArea(),
                invite = inviteToken
            });

            // Construct full URL using configured application URL (which will fall back to request)
            var applicationUri = RuntimeState.ApplicationUrl;
            var inviteUri      = new Uri(applicationUri, action);

            var emailSubject = Services.TextService.Localize("user", "inviteEmailCopySubject",
                                                             //Ensure the culture of the found user is used for the email!
                                                             UserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings));
            var emailBody = Services.TextService.Localize("user", "inviteEmailCopyFormat",
                                                          //Ensure the culture of the found user is used for the email!
                                                          UserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings),
                                                          new[] { userDisplay.Name, from, message, inviteUri.ToString(), fromEmail });

            await UserManager.EmailService.SendAsync(
                //send the special UmbracoEmailMessage which configures it's own sender
                //to allow for events to handle sending the message if no smtp is configured
                new UmbracoEmailMessage(new EmailSender(true))
            {
                Body        = emailBody,
                Destination = userDisplay.Email,
                Subject     = emailSubject
            });
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _membershipHelper = new MembershipHelper(UmbracoContext.Current);
            int UID = int.Parse(Request.QueryString["id"]);

            u = BusinessLogic.User.GetUser(UID);

            //the true admin can only edit the true admin
            if (u.Id == 0 && CurrentUser.Id != 0)
            {
                throw new Exception("Only the root user can edit the 'root' user (id:0)");
            }

            //only another admin can edit another admin (who is not the true admin)
            if (u.IsAdmin() && CurrentUser.IsAdmin() == false)
            {
                throw new Exception("Admin users can only be edited by admins");
            }

            // Populate usertype list
            foreach (UserType ut in UserType.getAll)
            {
                if (CurrentUser.IsAdmin() || ut.Alias != "admin")
                {
                    ListItem li = new ListItem(ui.Text("user", ut.Name.ToLower(), UmbracoUser), ut.Id.ToString());
                    if (ut.Id == u.UserType.Id)
                    {
                        li.Selected = true;
                    }

                    userType.Items.Add(li);
                }
            }

            var userCulture = UserExtensions.GetUserCulture(u.Language, Services.TextService);

            // Populate ui language lsit
            foreach (var lang in Services.TextService.GetSupportedCultures())
            {
                var regionCode = Services.TextService.ConvertToRegionCodeFromSupportedCulture(lang);

                var li = new ListItem(lang.DisplayName, regionCode);

                if (Equals(lang, userCulture))
                {
                    li.Selected = true;
                }

                userLanguage.Items.Add(li);
            }

            // Console access and disabling
            NoConsole.Checked = u.NoConsole;
            Disabled.Checked  = u.Disabled;

            PlaceHolder medias = new PlaceHolder();

            mediaPicker.AppAlias  = Constants.Applications.Media;
            mediaPicker.TreeAlias = "media";

            if (u.StartMediaId > 0)
            {
                mediaPicker.Value = u.StartMediaId.ToString();
            }
            else
            {
                mediaPicker.Value = "-1";
            }

            medias.Controls.Add(mediaPicker);

            PlaceHolder content = new PlaceHolder();

            contentPicker.AppAlias  = Constants.Applications.Content;
            contentPicker.TreeAlias = "content";

            if (u.StartNodeId > 0)
            {
                contentPicker.Value = u.StartNodeId.ToString();
            }
            else
            {
                contentPicker.Value = "-1";
            }

            content.Controls.Add(contentPicker);


            // Add password changer
            var passwordChanger = (passwordChanger)LoadControl(SystemDirectories.Umbraco + "/controls/passwordChanger.ascx");

            passwordChanger.MembershipProviderName = UmbracoSettings.DefaultBackofficeProvider;

            //Add a custom validation message for the password changer
            var passwordValidation = new CustomValidator
            {
                ID = "PasswordChangerValidator"
            };
            var validatorContainer = new HtmlGenericControl("div")
            {
                Visible         = false,
                EnableViewState = false
            };

            validatorContainer.Attributes["class"] = "alert alert-error";
            validatorContainer.Style.Add(HtmlTextWriterStyle.MarginTop, "10px");
            validatorContainer.Style.Add(HtmlTextWriterStyle.Width, "300px");
            var validatorContainer2 = new HtmlGenericControl("p");

            validatorContainer.Controls.Add(validatorContainer2);
            validatorContainer2.Controls.Add(passwordValidation);
            passw.Controls.Add(passwordChanger);
            passw.Controls.Add(validatorContainer);

            pp.addProperty(ui.Text("user", "username", UmbracoUser), uname);
            pp.addProperty(ui.Text("user", "loginname", UmbracoUser), lname);
            pp.addProperty(ui.Text("user", "password", UmbracoUser), passw);
            pp.addProperty(ui.Text("email", UmbracoUser), email);
            pp.addProperty(ui.Text("user", "usertype", UmbracoUser), userType);
            pp.addProperty(ui.Text("user", "language", UmbracoUser), userLanguage);

            //Media  / content root nodes
            Pane ppNodes = new Pane();

            ppNodes.addProperty(ui.Text("user", "startnode", UmbracoUser), content);
            ppNodes.addProperty(ui.Text("user", "mediastartnode", UmbracoUser), medias);

            //Generel umrbaco access
            Pane ppAccess = new Pane();

            ppAccess.addProperty(ui.Text("user", "noConsole", UmbracoUser), NoConsole);
            ppAccess.addProperty(ui.Text("user", "disabled", UmbracoUser), Disabled);

            //access to which modules...
            Pane ppModules = new Pane();

            ppModules.addProperty(ui.Text("user", "modules", UmbracoUser), lapps);
            ppModules.addProperty(" ", sectionValidator);

            TabPage userInfo = UserTabs.NewTabPage(u.Name);

            userInfo.Controls.Add(pp);

            userInfo.Controls.Add(ppAccess);
            userInfo.Controls.Add(ppNodes);

            userInfo.Controls.Add(ppModules);

            userInfo.HasMenu = true;

            var save = userInfo.Menu.NewButton();

            save.Click     += SaveUser_Click;
            save.ID         = "save";
            save.ToolTip    = ui.Text("save");
            save.Text       = ui.Text("save");
            save.ButtonType = MenuButtonType.Primary;

            sectionValidator.ServerValidate   += new ServerValidateEventHandler(sectionValidator_ServerValidate);
            sectionValidator.ControlToValidate = lapps.ID;
            sectionValidator.ErrorMessage      = ui.Text("errorHandling", "errorMandatoryWithoutTab", ui.Text("user", "modules", UmbracoUser), UmbracoUser);
            sectionValidator.CssClass          = "error";
            sectionValidator.Style.Add("color", "red");

            SetupForm();
            SetupChannel();

            ClientTools
            .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree <loadUsers>().Tree.Alias)
            .SyncTree(UID.ToString(), IsPostBack);
        }