Condition to register

Hello, I’ve finished my user log in, reset pass, but I’m having a problem with the registration page.

What I’m trying to do is to allow people to create a user in my page only if they have a unique code and a verification number that I give them, this is because my page it’s only for my costumers and each of them have a unique code.

So… I’ve tried creating a query in the server action file to lookup the values… WHERE Code = Input_Code and Verification = Input_verification.

Then using a conditional, if the verification and the code values are correct, it allows the person to create a user.

I’m trying to do this for a while know but I can’t seem to make it work.

Any help of how doing this? Thanks

Hi @salvuccicarlos,
from what I understand you could achieve the above by adding a user level and verifying it through security provider. Consider this

  1. Create a user-level named ‘superuser’ or anything you want.
  2. Create a column in your db named user level and give to these users a level of 3 for example
  3. So when the user level for this user is 3 then give them the ability to add a new user.

Hope it helped
Thank you!

1 Like

+1 :+1:

Just in case you are doing something similar to me (for which @t11 usually perfectly valid approach isn’ suitable).

I also have users from customers who sign in to the same platform as other customers but should only be able to perform actions for their users/records. Even more complex was that I can have single users that have access to several customer areas so need to be able to switch between them.

  1. in the DB I have tables for: user, customer, activations
  2. When creating the user they are given a corresponding record (foreign key) in activations with a further foreign key link to the customer record. There can be multiple activation records per user, linking to each of the customer sections that they have access to.
  3. When the user logs in I set a ‘last_customer_uid’ (link to customer table) field in the users table to remember which customer they were last logged in to (although you then have to make sure it copes with a NULL value or assign the new customer uid when creating a new one)
  4. Each customer has a unique ‘private key’ that is only ever seen server-side (I usually use a concatenation of fields from the customer record and hash to create a code - include a timestamp, if you keep them private, to make it less guessable)
  5. Each user has a unique ‘private key’ that also is only ever seen server-side (I usually use a concatenation of fields from the user’s record and hash to create a code)
  6. A public key is then created as a hash of the two private key values within a database view and is retrieved via Server Connect db query.
  7. The public key can then be sent with the relevant user identity and customer uid (obtained through login) to verify server-side. It is unique per user and per organisation so (I think) would be incredibly difficult to manipulate.
  8. Permissions can be set in the activations record for the user/customer combination

It is a bit of a trial to get set up, but once working I find it pretty effective.

Ok, my English is not very good so if there is any misunderstanding, that might be the cause.

Being more detailed about how my system should work, I’m going to list my tables and fields.

TABLES:

  1. Costumers

    ID
    Verification number
    Name

  2. Users

    ID
    email
    password
    Customer ID

The steps should be the following ones:

  1. A costumer complete the registration form and the server checks if the email doesn’t exist (validation).
  2. The server makes a query to the DB to check if (Conditional) the ID and the verification number retrieves one costumer. If the server retrieves one costumer, it enables the registration and creates a new user with the Costumer ID.
  3. If the query doesn’t bring any costumer (else condition), the page shows an error.

Query example:

The problem that I’m having is that while testing this and debbugin with chrome, it always brings the error.

This are the steps I’ve created (the create new record is not implemented yet because first I want to solve this main issue).

Note: Response 100 should show the name of the costumer (is just to test the steps). Response 400 shows the error (the page is only showing this one).

I believe the problem is with the query. I created an alert to show how many records counts from the query and shows me 0. I don’t understand why, because I’m using the correct ID and verification numbers to test the query.

Thanks!

Hi Carlos!

First the validation…You don’t necessarily need to do a query action for this. After your database connection step, add a Validate Data action. Here’s an an example from my app that makes sure the email address doesn’t already exist in our users table:

If this doesn’t pass, the workflow will stop.

You also can remove the Response actions. Currently you are telling the server to do a query, the loop through all the query results and send a response back to the client, for each of those results, and then send another response. So, it really doesn’t serve much of a purpose.

If you want to see results coming back from the query, just click output in the query properties on that action.

You also mention debugging. You can click the debugging box on the query properties, which will output a bunch of debug info, but it will no longer send the standard output of results. Use this only to see the sql, parameters, etc. that are in use.

Also, make sure the debug is turn on in the settings:

Hope that helps,

–Ken

1 Like

@salvuccicarlos
Server connect runs the steps in the order they are placed. Currently your repeat first runs the response 100 and then the response 400 - so you will always see response 400, as it is the last step.

You don’t need a repeat here. Just use the condition step after the query, and use the query {{query2}} as an expression.

If the query returns results, the steps in “Then” will run. If the query returns no results, the steps under “Else” will run.
For returning test data better use a SetValue step, instead of set Response :slight_smile:

Ok, so I’m trying to return the value to check if the query it’s ok. But it doesn’t work. I don’t know how to get the value of the table column.

This is how I’m doing the server steps:

The value I need is from the column “Nombre” from my database, that is why I put it as the name and global name of the set value properties.

This is my database:

image

Hi Carlos,

If you are trying to validate the data in your query, you can click output on the query and see all the columns you selected in your browser developer console.

If you really want to see the value from a single column like nombre, add a repeat step after your query action, and set the expression to {{query2}}. Inside that you can use a set value, with output ticked, and give it any name you’d like (it does not have to correspond to the column name.) Looks like this:

Here is the developer console in the browser when you call this server connect workflow:

You can see the result of the query itself in “query2” and you can see the repeat out where it also sets a “test_value”.

This is the result I’m getting

This is the query

This are the steps

I really don’t understand what’s wrong.

This is my table data

You have the debug option turned on for the query action – you only use that to see what the sql parameters and statement look like. Turn that off, and you will see the results output.

1 Like

These steps look right to me.

You just need to use {{query2[0].Nombre}} in the setvalue step.

And yes, of course turn that debug mode off. It's only used for debugging purposes!

This was the error!! I got the value I wanted… All because it was in debug mode?? I don’t understand the use for that server connection action

Its used to display debug info, when we are debugging problems.
You usually don't turn on debug options without a purpose.

Ok, and what would be a debug problem?

I got it enable in the DMX zone

Well, if you have any issue with your server returning errors or similar, enabling the debug mode helps us to debug the problem by reading the debug info.
You don’t need this enabled for your production work.

1 Like