How to email the id or username of the user when they log in

I’m building an admin area and it’s going really well. I’m using the Security Enforcer for it (of course!) and have created a server action to send me an email when someone logs in and that works fine.

But I really want the email to contain the id or username of who has just logged in but I’m just not having any success.

In the login server action I have…

  • database connection
  • security provider
  • security login
  • database query

and I’ve added ''set value" and given it a value of {{siteSecurity.identity}}

Then, in the server action which sends the email, I’ve tried inserting a global variable of all types but it’s not inserting anything.

When using the ‘Set Value’ server action, how is that stored? Is it a session variable?

Cheers, Jon.

Hi @sitestreet
In your email body you can directly use: {{siteSecurity.identity}} expression. No need to put it in a set value step.
The set value is just a variable, not a session variable.

You can also use something like: {{[0].username}} in the mail body.

1 Like

Thanks @Teodor. I had my Send Email step in a different server action. I’ve now put it into the same server action as the security provider and the ID now inserts into the email.

I also have a database query in that server action but I’m not able to insert any fields from it into the email. Attached is what I see in the data bindings.

What do you need to to with the dynamic data in the email body?

I just want to show the real name of the logged in user (or email address) rather than just have their ID. I was expecting the Database Query to have sub-branches containing all the fields.

No, it’s not possible to select query items like that from within the mail body.
Please check my previous reply. You can add these manually:

{{[0].username}} or {{[0].email}} etc. whatever field you want to display.

Thanks. I have tried manually entering them as you suggested but it’s not appearing in the email. I’ll keep trying.

Yes, of course it won’t work with the wrong expressions i provided :slight_smile:
It must be: {{queryLoggedInUser[0].username}} sorry about the confusion!

1 Like

Aah, that was the problem. I was keeping the .data part in. It’s now working perfectly with {{queryLoggedInUser[0].uEmail}}

Many thanks. Now I know the syntax, I can use this much more often.

1 Like

We are going to improve this and make it available in the data picker, by adding a special “query single record” step in server action. So you won’t have to add this manually any longer :slight_smile:


Database Single Query has been integrated in Wappler 2.2.3: