User confirmation: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
Volt allows you to require your users to confirm their accounts via email. By default this is turned off. You can turn it on by setting the confirmation URL in the Dashboard.
VoltServer allows you to require your users to confirm their accounts via email. By default this is turned off. You can turn it on by setting the confirmation URL in the Dashboard.


Here are the advantages of logging on:
Here are the advantages of logging on:
Line 21: Line 21:
* <nowiki>/#</nowiki> - indicates you want to go to a page (form) in your app.
* <nowiki>/#</nowiki> - indicates you want to go to a page (form) in your app.
* <nowiki>/confirm</nowiki> - specifically, the confirmation form.
* <nowiki>/confirm</nowiki> - specifically, the confirmation form.
* <nowiki>{{token}}</nowiki> - substitute the reset token here. This will be passed back to Volt later to confirm the reset.
* <nowiki>{{token}}</nowiki> - substitute the reset token here. This will be passed back to VoltServer later to confirm the reset.


== Confirming the user ==
== Confirming the user ==


Once your user registers, Volt will send a confirmation email to make sure he is a legitimate user.
Once your user registers, VoltServer will send a confirmation email to make sure he is a legitimate user.


Here's an email similar to what Volt will send to your user. If the link is clicked on, your app will open. Confirmations expire after 12 hours.
Here's an email similar to what VoltServer will send to your user. If the link is clicked on, your app will open. Confirmations expire after 12 hours.


   Thanks for signing up! Please click the link below to confirm your account:
   Thanks for signing up! Please click the link below to confirm your account:
Line 37: Line 37:
The complete string will be in <code>location.hash</code> in your app.
The complete string will be in <code>location.hash</code> in your app.


Once the user clicks on the URL in the email, your app can send the confirmation to Volt using the <code>$volt.auth.confirm()</code> function.
Once the user clicks on the URL in the email, your app can send the confirmation to VoltServer using the <code>$volt.auth.confirm()</code> function.


The syntax of the function is:
The syntax of the function is:
Line 44: Line 44:


* ''token'' - string, required. The token in the URL.
* ''token'' - string, required. The token in the URL.
* ''callback'' - function(error, data), required. The function in your app to call when the request to Volt is complete (or fails).
* ''callback'' - function(error, data), required. The function in your app to call when the request to VoltServer is complete (or fails).


   <syntaxhighlight lang="JavaScript">
   <syntaxhighlight lang="JavaScript">
Line 92: Line 92:


* ''email'' - string, required. The email to resend the confirmation to.
* ''email'' - string, required. The email to resend the confirmation to.
* ''appId'' - string, optional. The Volt ID of the app to sign into. If not supplied, defaults to value set in <code>$volt.init(appId)</code>.
* ''appId'' - string, optional. The VoltServer ID of the app to sign into. If not supplied, defaults to value set in <code>$volt.init(appId)</code>.
* ''callback'' - function(error, data), required. The function in your app to call when the request to Volt is complete (or fails).
* ''callback'' - function(error, data), required. The function in your app to call when the request to VoltServer is complete (or fails).


   <syntaxhighlight lang="JavaScript">
   <syntaxhighlight lang="JavaScript">

Latest revision as of 15:19, 25 February 2021

VoltServer allows you to require your users to confirm their accounts via email. By default this is turned off. You can turn it on by setting the confirmation URL in the Dashboard.

Here are the advantages of logging on:

1. Only people who log on will be able to use your app.

2. Users can save data to serverStorage.

3. You can send emails to a logged on user.

4. You can retrieve the user's name.

Setting up the Dashboard

In the Dashboard, you can set the page in your app that handles user confirmations. The special value {{token}} is replaced by an actual confirmation token that your app can use to reset the password.

The sample string shown is a reasonable one:

  • /# - indicates you want to go to a page (form) in your app.
  • /confirm - specifically, the confirmation form.
  • {{token}} - substitute the reset token here. This will be passed back to VoltServer later to confirm the reset.

Confirming the user

Once your user registers, VoltServer will send a confirmation email to make sure he is a legitimate user.

Here's an email similar to what VoltServer will send to your user. If the link is clicked on, your app will open. Confirmations expire after 12 hours.

 Thanks for signing up! Please click the link below to confirm your account:
 
 https://signon.volt.live/#/confirm/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0NzUxNjE3OTcsImV4cCI6MTQ3NTIwNDk5NywiYXVkIjoiL2FwaS9hdXRoL2NvbmZpcm0iLCJpc3MiOiJzaWdub24udm9sdC5saXZlIiwic3ViIjoiN2J2aTR6In0.EkJz1uL3Uo59PPa24bQN2ctXZY4LRwiAVH00kvFpNN0
 
 If you didn't sign up for an account, you can ignore this message.

The complete string will be in location.hash in your app.

Once the user clicks on the URL in the email, your app can send the confirmation to VoltServer using the $volt.auth.confirm() function.

The syntax of the function is:

$volt.auth.confirm(token, callback)

  • token - string, required. The token in the URL.
  • callback - function(error, data), required. The function in your app to call when the request to VoltServer is complete (or fails).
  function confirm() {
    var queryParams = location.hash.split('/');

    $volt.auth.confirm(queryParams[2], confirmCallback);
  }

  function confirmCallback(error, data) {
    if (error) {
      if (!data) {
        data = { message: 'Network Error' };
      }
      alert(data.message);
    } else {
      alert('Your account is confirmed. Have a nice day!');
    }
  }
  Function confirm()
    Dim queryParams
    queryParams = location.hash.split("/")

    $volt.auth.confirm(queryParams[2], confirmCallback);
  End Function

  Function confirmCallback(error, data)
    If error Then
      If (!data) Then data = { message: "Network Error" }
      MsgBox data.message
    Else
      MsgBox "Your account is confirmed. Have a nice day!"
    End If
  End Function

Resending Confirmations

Occasionally an account confirmation may not be delivered due to the nature of email. Additionally account confirmations expire after 12 hours. In these cases, you can provide your users with the capability to resend an account confirmation using the $volt.auth.resend() function.

The syntax of the function is:

$volt.auth.resend(email, appId, callback)

  • email - string, required. The email to resend the confirmation to.
  • appId - string, optional. The VoltServer ID of the app to sign into. If not supplied, defaults to value set in $volt.init(appId).
  • callback - function(error, data), required. The function in your app to call when the request to VoltServer is complete (or fails).
  butResendConfirmation.onclick = function () {
    $volt.auth.resend(inpEmail.value, butResendConfirmationCallback);
  }

  function butResendConfirmationCallback(error, data) {
    if (error) {
      if (!data) {
        data = { message: 'Network Error' };
      }
      alert(data.message);
    } else {
      alert('An email is on its way to you.');
    }
  }
  Function butResendConfirmation_onclick()
    $volt.auth.forgot(inpEmail.value, butResendConfirmationCallback)
  End Function

  Function butResendConfirmationCallback(error, data)
    If (error) Then
      If (!data) Then data = { message: "Network Error" }
      MsgBox data.message
    Else
      MsgBox "An email is on its way to you."
    End If
  End Function

Reference