Log in: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
After you've [[First_app|initialized]], you can use Volt to control who is allowed to use your app. Only users who have registered will be able to log into your app.
After you've [[First_app|initialized]], you can use VoltServer to control who is allowed to use your app. Only users who have registered will be able to log into your app.


== Checking if user is logged in ==
== Checking if user is logged in ==
Line 23: Line 23:
== Logging In ==
== Logging In ==


Logging in identifies your user to the Volt server. Here is a typical log in screen:
Logging in identifies your user to the VoltServer server. Here is a typical log in screen:


[[File:Logging-in-and-out.png]]
[[File:Logging-in-and-out.png]]
Line 35: Line 35:
* ''email'' - string, required. The email address of the user.
* ''email'' - string, required. The email address of the user.
* ''password'' - string, required. The user's password.
* ''password'' - string, required. The user's password.
* ''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 login is complete (or fails).
* ''callback'' - function(error, data), required. The function in your app to call when the login is complete (or fails).



Latest revision as of 15:23, 25 February 2021

After you've initialized, you can use VoltServer to control who is allowed to use your app. Only users who have registered will be able to log into your app.

Checking if user is logged in

Use the $volt.auth.isLoggedIn() to check if a user is logged in:

  if ($volt.auth.isLoggedIn()) {
    // Ok to do processing
  } else {
    // ask user to log in
  }
  If $volt.auth.isLoggedIn() Then
    'Ok to do processing
  Else
    'ask user to log in
  End If

Logging In

Logging in identifies your user to the VoltServer server. Here is a typical log in screen:

Once you have have obtained the user's email and password (either from a screen like the above or otherwise), you can call the $volt.auth.login() function to log the user in.

The syntax of the function is:

$volt.auth.login(email, password, appId, callback)

  • email - string, required. The email address of the user.
  • password - string, required. The user's password.
  • 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 login is complete (or fails).
  butSignOn.onclick = function () {
    $volt.auth.login(inpEmail.value, inpPassword.value, signOnCallback);
  }

  function signOnCallback(error, data) {
    if (error) {
      if (!data) {
        data = { message: 'Network Error' };
      }
      alert(data.message);
    } else {
      alert('User successfully logged in');
    }
  }
  Sub butSignOn.onclick()
    $volt.auth.login(inpEmail.value, inpPassword.value, signOnCallback);
  End Sub

  Function signOnCallback(error, data)
    If error Then
      If (!data) Then data = { message: "Network Error" }
      MsgBox data.message
    Else
      MsgBox "User successfully logged in"
    End If
  End Sub

Once the user is logged in, he stays logged in. The info is save to localStorage so the next time the app is run, the user does not have to log in again.

Logging Out

You can log your user out by using $volt.auth.logout():

  $volt.auth.logout();
  $volt.auth.logout()

AppStudio Users

AppStudio includes a form for handling login duties, called frmSignOn. If you include it in your app, you can call it as follows:

  butSignIn.onclick = function() {
    showSignIn(signInCallback);
  };

  function signInCallback() {
    butSignIn.disabled = true;
    NSB.MsgBox('SignIn successful.');
  }
  Function butSignIn_onclick()
    showSignIn(signInCallback)
  End Function

  Function signInCallback()
    butSignIn.disabled = True
    MsgBox "SignIn successful."
  End Function

Reference