CRUDE register by email - how too

58 views
Skip to first unread message

Lee Sandberg

unread,
Dec 22, 2014, 9:28:42 AM12/22/14
to str...@googlegroups.com
I am trying hard to figure out how to get register by email to wiork.

I get emails when using it. 

But the link in the email is wrong just 0.0.0.0

When I cut and paste the correct domain it works. You can enter the page once, not twice. So thas sweet and well.

To change the 0.0.0.0 to the correct domain I was toold to use the Structr-UI/Data (crude tool)

I made a crude guess that it ment adding a Mail Template.

Have no clue how to contect it to the outgoung register by email, email.

May be it's by what it's named as right know it's called SIGN_UP_TEXT,  have no clue if thats correct.

The Locale is set to: ${this.name}, ${this.eMail}

The text is set to:

send_html_mail('structr-m...@mydomain.com', 'mydomainname', this.eMail, this.name, template('SIGN_UP_SUBJECT', 'en_US', this), template('SIGN_UP_HTML','en_US', this), template('SIGN_UP_TEXT','en_US', this)) 

Working with all this is a bit flimsy. Right know when fiddling with this the register_thank_you page stopped working 404.
Not found. This just worked.

It works when the page is public.

After this the user ofcourse has too choose a valid password, click on a disclamer notice too continue.

Any thoughts would be nice.











Eric Schleicher

unread,
Dec 22, 2014, 11:38:41 AM12/22/14
to str...@googlegroups.com
Hi lee, 

This is how i setup registration emails.  

I have a signup page, which has a button that wired up to post to the registration endpoint with the user's email address (i'm not having them set a password at this point).

I made sure to have the autologin=true  setup in the structr.conf so that a confirmationKey is populated when the user node is created and so the user can perform a one time login using the confirmationKey as a login token. (it sounds like you have this working already)

#[from my structr.conf]

# JSON/REST servlet
<< default configuration values>>
JsonRestServlet.user.autologin = true



# HTML servlet
<<<defautl configuration values>>>
HtmlServlet.user.autologin = true



For my application, I create three MailTemplate Entries for the signup

one WELCOME_EMAIL_MESSAGE_PLAINTEXT  (local: en_US)
one WELCOME_EMAIL_MESSAGE_HTML (local: en_US)
one WELCOME_EMAIL_SUBJECT (local: en_US)

which i use as the values in the send_html_mail() function much as you did.

But to control the uri for the host name that goes in the outbound email, i did the following: 

Since the public uri for my server isn't the same as the system hostname or resolvable through DNS, I created a SystemConfig Entity where I store certain 'global' type lookup values that i use throughout my system.  In this entity, there are two attributes, one called configName (string) and configValue (string) with a uniqueness constraint on the configName, to ensure that i can have only one valid value.  

In #crud. I created a node with a key value pair with a configName or  'host_uri' and a configvalue with the FQDN for the structr instance.

To control the substitution of the proper FQDN, in the mail template, I use the store() and retrieve() functions to lookup the value from the SystemConfig Entity that i created and use it in the first secions of the url for the link.

so the first line of my the message MailTemplates look like this:

${store('confirmation_host', get(find('SystemConfig', 'configName', 'host_uri'), configValue))}

now this value is available throughout the MailTemplate

in the HTML version of the template the 'code' for the confirmation link looks something like this.

<a href="http://${retrieve('confirmation_host')}confirm_registration?key=${this.confirmationKey}&target=account-setup&onerror=register-error">http://${retrieve('confirmation_host')}/confirm_registration?key=${this.confirmationKey}&target=account-setup&onerror=register-error</a>

This solutions works for me...

Hope that helps.

-Eric 



On Monday, December 22, 2014 6:28:42 AM UTC-8, Lee Sandberg wrote:
I am trying hard to figure out how to get register by email to wiork.

I get emails when using it. 

But the link in the email is wrong just 0.0.0.0

When I cut and paste the correct domain it works. You can enter the page once, not twice. So thas sweet and well.

To change the 0.0.0.0 to the correct domain I was toold to use the Structr-UI/Data (crude tool)

I made a crude guess that it ment adding a Mail Template.

Have no clue how to contect it to the outgoung register by email, email.

May be it's by what it's named as right know it's called SIGN_UP_TEXT,  have no clue if thats correct.

The Locale is set to: ${this.name}, ${this.eMail}

The text is set to:

send_html_mail('structr-mail-dae...@mydomain.com', 'mydomainname', this.eMail, this.name, template('SIGN_UP_SUBJECT', 'en_US', this), template('SIGN_UP_HTML','en_US', this), template('SIGN_UP_TEXT','en_US', this)) 

Lee Sandberg

unread,
Dec 23, 2014, 6:01:56 AM12/23/14
to str...@googlegroups.com
Thanks Eric for you resque.

I have some questions though,

First.you write "I created a SystemConfig Entity" what exactlly do you mean, how do you write that?

I guess your not working with Stuctrs cloud service as I am. I don't have access to the config file, if thats where I need to set this entity up.
I guess this can't be done through the Struct-UI?
I have to ask the providers for help in changing the config file, I guess.


I did as you described I made three different MailTemplates one for each

WELCOME_EMAIL_MESSAGE_PLAINTEXT  (local: en_US)
WELCOME_EMAIL_MESSAGE_HTML (local: en_US)
WELCOME_EMAIL_SUBJECT (local: en_US)

Should both WELCOME_EMAIL_MESSAGE_PLAINTEXT and WELCOME_EMAIL_MESSAGE_HTML have the 
${store('confirmation_host', get(find('SystemConfig', 'configName', 'host_uri'), configValue))}    ?

and then the WELCOME_EMAIL_MESSAGE_HTML should have 
<a href="http://${retrieve('confirmation_host')}confirm_registration?key=${this.confirmationKey}&target=account-setup&onerror=register-error">http://${retrieve('confirmation_host')}/confirm_registration?key=${this.confirmationKey}&target=account-setup&onerror=register-error</a>      ?

Shouldn't WELCOME_EMAIL_MESSAGE_PLAINTEXT also have something like it?

Somehow my server isn't allowing the first time access to the register_thanks page.... I guess the conf file isn't corrrect it was before though.
Maybe the version of the Structr was updated and it got reseted to the default.

Well I feel very noob about all this. this technique you use Eric could be a great add on to the tutorial. 

Thanks again Eric

Lee Sandberg

unread,
Dec 28, 2014, 3:35:27 PM12/28/14
to str...@googlegroups.com
The node you create in #crude, what type is it?


Den måndagen den 22:e december 2014 kl. 17:38:41 UTC+1 skrev Eric Schleicher:

Eric Schleicher

unread,
Dec 28, 2014, 4:54:04 PM12/28/14
to str...@googlegroups.com
Hi Lee.

Sorry if i wasn't clear in my original response.   I'll try to answer very clearly here.

I created a new entity in the schema editor from within Structr-ui.  You don't need any special access to accomplish this task.  

So I (arbitrarily) decided to call this entity SystemConfig (as i intend to stick other "global" values here for my application).  


Then navigating over to  the data page (/#crud) you can "Create new SystemConfig" and set the 

configName to: host_uri

and

configValue to: structr.mydomain.com (or whatever the publicly resolvable DNS name for the structr instance is)

in summary, this was done entirely within the normal backend UI...  nothing special.

I made the node (just to make sure) visibleToPublicUsers and visibleToAuthenticatedUsers  to ensure i didn't run into permissions issues reading the values.



Moving on...

Should both WELCOME_EMAIL_MESSAGE_PLAINTEXT and WELCOME_EMAIL_MESSAGE_HTML have the 
${store('confirmation_host', get(find('SystemConfig', 'configName', 'host_uri'), configValue))}    ?

short answer:  Yes, as I understand, each MailTemplate is evaluated separately, so they each need a line to load the "variable" if you're using it as i outlined.

Shouldn't WELCOME_EMAIL_MESSAGE_PLAINTEXT also have something like it?


the plaintext version should definitely have a link in it, but not one formatted as HTML.

So you should have something similar to this bolded section as a example plain text version of the MailTemplate:

${store('confirmation_host', get(find('SystemConfig', 'configName', 'host_uri'), configValue))}
Hi ${this.name}, 

Thanks for signing up!  please click the following confirmation link to complete your registration and activate your account

http://${retrieve('confirmation_host')}/confirm_registration?key=${this.confirmationKey}&target=account-setup&onerror=register-error

Regards, 

the guys from the site sending you this email

This way you create the temporary variable at the beginning of the MailTemplate and then use it later on.  in this example you could just do the lookup inline, but generally do it this way for readability.

Moving on...

unless you have a page called register_thanks, getting a 404 is an expected result.   
from the confirmation url in this example, there are two request values in the string:

target=account-setup & onerror=register-error

these are two pages that the registration endpoint will route traffic to for the success or failure scenarios.  you can change these values to anything you like, as long as you have something at those locations.  thee aren't special pages within a default structure implementation, you get to create them and do whatever you like on them, or route the success or failure wherever you would like.

if you're not sure if the structr.conf files have the values for auto login set, you can check using the config() function

I believe that ${config('JsonRestServlet.user.autologin')} and ${config('HtmlServlet.user.autologin')} will show you the currently configured values (if you just stick that in a page somewhere).

If those look set correctly, then make sure that the "thanks" page is visible to authenticated users...

A good way to check what's going on is to look and see if the confirmationKey goes away for the user after clicking on the link on the email.  if it does, the user is getting logged in, but you might have a permission issue with the page that you're sending the user to... because of permissions, not login.  


Tip: You can paste the confirmation key back into the user record from /#crud if you want to try the link again.

Hope this helps.

Lee Sandberg

unread,
Dec 29, 2014, 9:05:14 AM12/29/14
to str...@googlegroups.com
Thanks again Eric for your clarifications.

"I believe that ${config('JsonRestServlet.user.autologin')} and ${config('HtmlServlet.user.autologin')} will show you the currently configured values (if you just stick that in a page somewhere)."

Pasted both into a page with H1 in front.

Doesn't display anything before or after a registration attempt.

And when I change the content of the text of the three Email_Templates 

It doesn't show anywhere. It feels like I working on two different instances of the server....or that it has been overridden by an invisable MailTemplate instances

Sigh...

It always returns an email that looks like this.

"Structr Mail Daemon structr-mail-daemon@localhost

2:50 PM (0 minutes ago)
Click here to finalize registration."


The link goes to http://0.0.0.0/confirm_registration?key=dd5b018c-572d-42c9-adfa-21c01d9d8f71&target=register_thanks&onerror=register_error

And if I replace the 0.0.0.0 with my domain adress by hand I get closer but,a can't find page 404. It's visible to authorized users. (This used to work)

Its seams that my instance is hard coded and I can't change anything.


Regards

Lee

Lee Sandberg

unread,
Dec 29, 2014, 9:09:31 AM12/29/14
to str...@googlegroups.com
The EmailTemplates shouldn't have any new attributes right?

Lee Sandberg

unread,
Dec 29, 2014, 9:34:38 AM12/29/14
to str...@googlegroups.com
Or maybe it should have some special name to override the default one?

Axel Morgner

unread,
Dec 30, 2014, 11:15:16 AM12/30/14
to str...@googlegroups.com
Hi Lee,

I'm currently writing some documentation about the e-mail system, covering the registration process and also how to use the mail templates.

Thanks Eric for chiming in here!

Best,
Axel


Am 29.12.2014 um 15:34 schrieb Lee Sandberg:
Or maybe it should have some special name to override the default one?

Den måndagen den 29:e december 2014 kl. 15:09:31 UTC+1 skrev Lee Sandberg:
The EmailTemplates shouldn't have any new attributes right?


As I'm building the e-mail stuff for the portal right now, I thought it would be a good idea to write down all these steps again and publish it as a new tutorial. I hope to get it finished by today.
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/structr/f82dc509-9c53-4d4e-804b-286fb713dfa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Axel Morgner · CEO Structr (c/o Morgner UG) · Twitter @amorgner · Skype axel.morgner
Hanauer Landstr. 291a · 60314 Frankfurt, Germany · Phone +49 151 40522060
https://structr.org - Structr: A revolutionary Software based on Neo4j
https://structr.com - Structr and Neo4j Hosting

Lee Sandberg

unread,
Dec 31, 2014, 5:54:03 AM12/31/14
to str...@googlegroups.com
One more question how does a user reset there password if it's only allowed to use the register by once?
...

Axel Morgner

unread,
Dec 31, 2014, 1:05:39 PM12/31/14
to str...@googlegroups.com
There's no special Reset Password function yet, but you can use the registration function to build one.

We will soon make the registration process easier to customize, and include a built-in reset password function as well.
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Axel Morgner

unread,
Dec 31, 2014, 1:10:56 PM12/31/14
to str...@googlegroups.com
Did you make the MailTemplate objects visible to public users as well? It's important because the registration process is running in a public user context (users are treated as public until successfully confirmed). And set the locale attribute to 'en_EN'.
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Axel Morgner

unread,
Dec 31, 2014, 1:11:06 PM12/31/14
to str...@googlegroups.com
No, this is not necessary.
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Axel Morgner

unread,
Dec 31, 2014, 1:13:07 PM12/31/14
to str...@googlegroups.com
You can find a an explanation here:

http://docs.structr.org/#Registration%20Process

This will be extended by more detailed documentation next year. :-)



Am 29.12.2014 um 15:34 schrieb Lee Sandberg:
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Lee Sandberg

unread,
Dec 31, 2014, 9:44:54 PM12/31/14
to str...@googlegroups.com
Thanks Axel.

You received this message because you are subscribed to a topic in the Google Groups "structr" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/structr/yDhnw-UHQOI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to structr+u...@googlegroups.com.

To post to this group, send email to str...@googlegroups.com.

Lee Sandberg

unread,
Jan 1, 2015, 10:54:51 AM1/1/15
to str...@googlegroups.com
Hi Axel

Where did the tutorial material go you put up yesturday?

It was theire and now it's not.


Regards

Lee



...

Lee Sandberg

unread,
Jan 1, 2015, 5:38:00 PM1/1/15
to str...@googlegroups.com
The old documents said nothing about ajax, just set:

data-structr-action   registration
data-structr-reload  true
data-structr-attributes  eMail, password

should this all be replaced with

$.ajax({
    url: '/structr/rest/registration',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({
        eMail: $('#e-mail').val()
    }),
    statusCode: {
        201: function() {
          console.log('Registration successful!');
        }
    }
});


Right know anyway it seams like my email adress isn't allowed in to the register_thanks page even once. Even if I remove the user with that email each time from Structrs database.

I tried removing cockies as well, dosn't help.

This one time access seams to work some times and then not at all. Which is good, I just whish I could test it more easily,





Den onsdagen den 31:e december 2014 kl. 19:13:07 UTC+1 skrev Axel Morgner:
...

Axel Morgner

unread,
Jan 2, 2015, 7:51:25 AM1/2/15
to str...@googlegroups.com
The data-structr-Attributes are a shortcut to bind a button and a form field to the 'registration' action. In Structr's frontend edit mode, there's a file called 'structr-app.js' which does the actual AJAX call.

Needs to be clarified in the docs, agreed.

BTW: You can't set a password at registration. The password attribute is not evaluated in the POST request, for obvious security reasons.
--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages