Developer forum

Forum » Templates » set password email using marketing

set password email using marketing

Jose Caudevilla
Reply

Hello,

I imported a set of users by excel using a data integration. 

Imported users haven´t password, i want that all the imported users can set a password by themselves.

My idea is send a marketing mail to all this users. In this mail i want to generate a link that will go to my "ChangePassword" page.

I tried to use the GetString("DWPasswordRecoveryUrl")  and  GetString("DWUsers:User:PasswordRecoveryUrl") values but it doenst work

Here is my set password email template code:

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using Dynamicweb.Rendering;
@using System.Web;
@using Dynamicweb.Security.UserManagement;
@MasterPageFile("../../Designs/Rapido/EmailMaster.cshtml")
@Include("../../Designs/Rapido/EmailHelpers_NAS.cshtml")

@CreatePreheader()

<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" width="500" id="emailBody">
	
  	@RenderHeaderSection()
        @RenderMessage()  
        @RenderMessageGraciasConfianza()
  	@RenderFooterContact()
  	@RenderFooterSocial()
        @RenderFooterLegal_NAS_B2C()
</table>

@helper RenderHeaderSection()
{
    @RenderHeaderImage();
}

@helper RenderMessage()
{

	
    Column message = new Column();
    message.header = Translate("Set a passowrd");
    message.text.Add("PasswordRecoveryUrl "+ GetString("DWUsers:User:PasswordRecoveryUrl")); //doesnt work

	message.text.Add("<a href='login?Username={{Email:User.UserName}}&PwToken={{Email:User.LoginToken}}&activate=true'>Click here to set your password</a>"); //it logins automatically
    @CreateRow(message);
	@RenderButton(GetString("DWPasswordRecoveryUrl"), "Set password"); //doesnt work
}

 

Is there any way to get DWPasswordRecoveryUrl value or send my password emails? 

 

Thanks, 

Jose.

 

 

 

  


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Jose,

 

You need to do 2 things:

  • When setting up the newsletter check Render content for each recipient
  • In the templates you have to do some additional changes. Here's the code you have to generate for the token (instead of the tag)

 

if (Pageview != null && Pageview.Context != null)
{
    var user = Pageview.Context.GetValue("User") as User;
    if (user != null)
    {
        string token = System.Guid.NewGuid().ToString();
        string resetLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(GetPageIdByNavigationTag("SignInPage")) + "?Username=" + user.UserName + "&RecoveryToken=" + token;
        
        // Set the token on the user
        user.PasswordRecoveryTokenExpirationTime = System.DateTime.UtcNow.AddHours(Dynamicweb.Configuration.SystemConfiguration.Instance.GetInt32("/Globalsettings/Modules/UserManagement/ExtranetPasswordSecurity/RecoveryTokenTimeout"));
        user.PasswordRecoveryToken = token;
        user.Save();
        
    }
}

 

The resetLink variable will be your href. I would urge you to test without the username querystring parameter. If you're using the email as the username some security agencies mention that as a security risk.

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Jose Caudevilla
Reply

Hi Nuno,

 

Thanks for your answer.

I put your code into my template but the pageview is null

Here is my code with your code:

 

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using Dynamicweb.Rendering;
@using System.Web;
@using Dynamicweb.Security.UserManagement;
@MasterPageFile("../../Designs/Rapido/EmailMaster.cshtml")
@Include("../../Designs/Rapido/EmailHelpers_NAS.cshtml")

@CreatePreheader()

<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" width="500" id="emailBody">
	
  	@RenderHeaderSection()
    @RenderMessage()  
    @RenderMessageGraciasConfianza()
  	@RenderFooterContact()
  	@RenderFooterSocial()
    @RenderFooterLegal_NAS_B2C()
</table>

@helper RenderHeaderSection()
{
    @RenderHeaderImage();
}

@helper RenderMessage()
{
    if (Pageview != null && Pageview.Context != null)
    {
	  var user = Pageview.Context.GetValue("User") as User;
      if (user != null)
        {
            string token = System.Guid.NewGuid().ToString();
            string resetLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(GetPageIdByNavigationTag("SignInPage")) + "?Username=" + user.UserName + "&RecoveryToken=" + token;

            // Set the token on the user
            user.PasswordRecoveryTokenExpirationTime = System.DateTime.UtcNow.AddHours(Dynamicweb.Configuration.SystemConfiguration.Instance.GetInt32("/Globalsettings/Modules/UserManagement/ExtranetPasswordSecurity/RecoveryTokenTimeout"));
            user.PasswordRecoveryToken = token;
            user.Save();

			Column message = new Column();

            message.header = Translate("Establecer una contraseña");
            message.text.Add("Hola " + GetString("Ecom:Order.Customer.Name") + ", ");
            message.text.Add(" ");
            message.text.Add("Gracias por tu pedido. ");
            message.text.Add(" ");
            message.text.Add("A continuación te informamos de los detalles de tu pedido:");
            @CreateRow(message);

            @RenderButton(resetLink, "Establecer contraseña");

        }
        
    }
	
	
}

And this is the page where i put the template, maybe here is the error:

 

Kind Regards.

Jose

 

 

 
Jose Caudevilla
Reply

Hello:

 

I forgoted to check Render content for each recipient.

It works perfect. Thanks Nuno.

Find regards.

Jose

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Jose,

 

I was just coming back to this. I am glad it worked out for you.

 

Nuno Aguiar

 

You must be logged in to post in the forum