All guides Backups and undo: getting an earlier version of your app back Files and images your app's users upload: taking, storing, showing and sharing them Plans and limits: how many projects you can have, the Exotool notice, and what happens at the limit Resources: connecting an Exotool app to outside services Sign-in and permissions: users, logging in and who may do what in your app Storing data: objects, sets and where your app keeps them Taking payments: cards, charges and holds with Stripe or PayPal
Sign-in and permissions: users, logging in and who may do what in your app
This guide is for the person whose app needs to know who is using it. It covers how an app gets users and a login, how people register, log in and log out, how to keep a screen or an action for signed-in people or for an administrator, codes sent by mail as a second check, and the administrator's password of a deployed app. It is about the users of the app you build, not about your own Exotool account or signing in to the editor, which it leaves out.
Contents
- Users, sessions and the built-in administrator
- The login form
- Letting people register
- The current user, and logging out
- Where permissions are decided
- Keeping a screen or an action for some people
- Data that belongs to one user
- Accounts made by an administrator, and changing a password
- A code by mail as a second check
- The administrator's password of a deployed app
- When something does not work
1. Users, sessions and the built-in administrator
An app can have users of its own: accounts with a user name, a password, optionally an
e-mail address, and a type. The type is a word you choose ("member", "instructor"); it
is the account's role. An account gets the type "normal" when you give none, and the type
"admin" makes it an administrator.
A session is the server's record of one visit from one device. It is either logged in as a user or not.
An app starts with one account, made the first time its server program runs: admin (type
admin, password admin). So you can try a login in the preview as admin. A deployed app gets
its own admin password (section 10). Every other account is one that somebody registers or an
administrator makes.
Apps built before 24 November 2026 also had a second built-in account, guest. It is no longer
made, and an app loses its untouched one the first time it runs after being built again.
A user name is an e-mail address, or at least 3 characters made of letters and digits, with single underscores allowed between them. A password has at least 5 characters. User names are unique.
2. The login form
The element is Login Form v3 (type name login_form3). It goes in the body of a page or a
popup. You do not add input rows to it: the whole form, with its Username and Password
fields and its Sign In button, is in the element's Wrapper Template, and what a press
does is in its Do On Action. Information is the help text under the button.
When the button is pressed, the form's values are put in the variable _loginvalues_
(_loginvalues_.username, _loginvalues_.password), and the Do On Action runs. A new login
form comes with code that begins like this:
_session_ = get_current_session()
logout_session(_session_)
login_status = login_session(_session_, _loginvalues_.username, _loginvalues_.password)
_loginvalues_.password = null
logged_in = login_status.logged_in
login_error = login_status.login_error
After a success it copies user_name, user_id, user_type and user_is_admin from
login_status in the same way; after a failure it shows alert(login_error).
login_session(session, username, password) checks the name and the password on the server
and, when they are right, logs the session in. Its result holds logged_in (true or false),
login_error (Invalid user name, No such user, Blank or illegal password or
Invalid Password) and, after a success, user_name, user_id, user_type, user_email
and user_is_admin. A failed login is not an error of the app: your code decides what to
show. After the action the form clears its password field by itself.
Going on after the login. Draw a connector from the login form to the screen that follows,
and give it the condition logged_in (Set Condition on the connector's menu). It is
followed only after a successful login.
3. Letting people register
In the login form's properties, Pre-Sets offers the preset login with register. It gives the form two views: Log In, and Sign up with an e-mail address, a password, its confirmation and a Register button. Its setting Use E-Mails as User Names (No or Yes) decides whether the sign-up view also asks for a user name or uses the e-mail address as one.
With this preset the variable action tells the Do On Action what was pressed: submit (log
in), register, sel_sign_up and sel_log_in (switch between the two views) and
sel_forgot_password. The registration itself is one call:
_reg_status = register_user(_loginvalues_.username, _loginvalues_.password,
_loginvalues_.confirm_password, _loginvalues_.email)
registered = _reg_status.registered
registration_error = _reg_status.registration_error
register_user(username, password, confirm_password [, email] [, type]) makes a new account
without an administrator. It returns a structure: registered (true or false),
registration_error (the message when it failed, such as That user already exists or
The passwords do not match) and user_id.
- Registering does not log the person in. The preset shows the Log In view again. A
connector from the form with the condition
registeredis followed after a success. - The type decides the role. With no type the account is
"normal";"admin"makes an administrator. Never take the type from a field the person fills in (section 5). - Forgot password is a link with a placeholder alert; no reset flow is covered here.
4. The current user, and logging out
The login form's code leaves logged_in, login_error, user_name, user_id, user_type
and user_is_admin for the rest of the app, to greet the person or to choose what a template
shows. Do not name variables of your own like them.
To ask the server who is signed in, in any activity:
sess = get_current_session()
me = sess.logged_in ? sess.user.name : ""
get_current_session() returns the session, making one if there is none. sess.user is the
account (sess.user.name, .type, .email); read it only when sess.logged_in is true.
To log out, put logout() in an activity, followed by logged_in = false, and lead back to
the login screen. logout() logs the session out on the server and leaves your variables as
they were, which is why the second statement is there.
5. Where permissions are decided
The device is never trusted. A permission is decided on the server, in a value the device cannot write. Three rules make this work:
- Some functions run only on the server, the session and user functions among them. A statement that uses one runs on the server.
- Their results are the server's. A variable that holds the result of a server-only function is set only on the server, which keeps it for every later activity. The device never writes it, and receives it only when a statement that runs on the device reads it.
- A condition on a server variable is checked by the server. After
adminp = is_admin_user(), a connector with the conditionadminpis followed only when the server says true, and everything after it runs under the same gate.
Three ways to lose this protection: deciding on user_is_admin, which is a convenience for
display and not a check; copying a permission to the device (declare_location flag client
followed by flag = adminp), because a connector gated on flag trusts the device; and
feeding a permission into an always statement, which runs on the device. Hiding a button in
a template is not a protection either: protect the activity the button leads to.
6. Keeping a screen or an action for some people
Start the protected part with an activity that asks the server, and put the answer on the connector that leads on:
// the administrator only
adminp = is_admin_user()
// signed-in people, and a role of your own
sess = get_current_session()
signedp = sess.logged_in
staffp = sess.logged_in ? sess.user.type == "instructor" : false
Give the connector to the protected part the condition adminp (or signedp, staffp), and
a second connector the Default Condition, leading to a message. is_admin_user() always
asks the server and the stored account, and returns false when nobody is signed in, so it is
safe as the only guard.
Asking for a login only when it is needed. The sample client_call_test_7 (category
SYSTEM : Samples) has a reusable "Require Login" part: a call into a sub-view that starts with
a decision. The connector with the condition logged_in goes straight to the end element; the
default connector opens a popup with a login form, whose logged_in connector leads to
close_popup() and the end element. The end element returns to just after the call.
7. Data that belongs to one user
Stored objects belong to the app, not to a user: every user can read them, signed in or not,
unless your design says otherwise. To keep data for each user, store the owner on the object
when it is made (note.owner = sess.user.name, with sess and me as in section 4) and show
only the owner's objects:
mine = subset(cloudobjects_of_type("Note"), "owner", me)
Derive every other set from this one with further subset calls: then only those objects are
ever copied to the device. An object fetched by its identifier (locate_cloudobject,
expect_cloudobject) is outside this fence: guard the activity that fetches it (section 6).
8. Accounts made by an administrator, and changing a password
create_user(username, password [, type]) makes an account and returns the new user. It
works only when the caller is signed in as an administrator; for anyone else it raises an
error and makes nothing.
change_password(user, password) sets a new password; user is a user object, such as the
sess.user of section 4. Only an administrator, or the user whose password it is, may call
it; otherwise it raises an error and the app shows an alert. So change_password alone
cannot reset a password that someone has forgotten.
9. A code by mail as a second check
Two functions send a code by mail and check it. They need an E-mail Server resource.
// after a successful login: mail a code to the signed-in user
sess = get_current_session()
result = send_tfa_code(sess.user, "Your sign-in code")
if (result != "OK") { alert(result) }
// in the next activity: ask for the code and check it
typed = prompt("Enter the code we mailed you", "")
verified = verify_tfa_code(upper(trim(typed)))
send_tfa_codetakes an e-mail address or a user object (it then mails the account's e-mail address, or the user name when that is one). It returns"OK"or an error message.- The code has 6 characters, digits and capital letters. The optional arguments are, in this
order: the subject, a sender name (not used at present), and a mail body of your own, which
must contain
%CODE%where the code goes. verify_tfa_code(code [, lifespan])returns true or false. A code is valid for ten minutes unless you givelifespan, in seconds. A code that verified cannot be used again.- Only one code is active in a session, and it must be typed in the session that asked for it.
- The login has already succeeded when the code is sent: gate the protected part on
verified.
Codes by text message: send_sms(to, body) sends a text message, but send_tfa_code sends by
mail only and verify_tfa_code checks only its codes. This guide does not cover building a
code check of your own.
10. The administrator's password of a deployed app
A deployed app has its own store. Its first run makes the admin account of section 1, and its
data starts empty: accounts registered in the preview are not there.
When the app has a login form, the Deploy dialog shows The administrator's password at the
first deployment to a host, with the fields Password for admin and The same password again
(at least 8 characters). The password is kept only as a hash inside the deployed app, and the
first run gives it to admin.
Later deployments to the same host do not ask again, and a deployment never resets the
password; change it in the app, with an activity that calls change_password. An app with no
login form is not asked, and its admin keeps the password admin: if such an app holds data
worth protecting, add a login form before you deploy, so that the password gets set.
11. When something does not work
| What you see | Likely cause | What to do |
|---|---|---|
| "No such user" in the deployed app for an account that works in the preview | The deployed app has its own store, which starts empty | Register or create the account in the deployed app |
admin / admin is refused in the deployed app |
The password was set in the Deploy dialog at the first deployment | Use that password |
| "Invalid User name" at registration | The name is shorter than 3 characters or has other characters than letters, digits and underscores | Choose another name, or use e-mail addresses as user names |
| After registering, the person is still on the form | Registering does not log in | Log in on the Log In view; follow the condition registered to say so |
| Nothing happens after a correct login | No connector leaves the form, or its condition is not logged_in |
Draw the connector and set its condition |
| A protected screen opens for the wrong people | The gate uses user_is_admin, a client copy, or only a hidden button |
Gate the connector on a server variable: adminp = is_admin_user() (sections 5 and 6) |
create_user makes nothing |
The caller is not signed in as an administrator | Sign in as admin, or use register_user |
change_password shows an alert |
The caller is neither that user nor an administrator | Sign in as the user, or as an administrator |
send_tfa_code returns an error about the E-mail Server resource |
The project's e-mail role is not set | Make an E-mail Server resource, set the role, build again |
send_tfa_code returns "The user did not have an email address" |
The account has no e-mail address and its name is not one | Pass the e-mail address, or register users with one |
verify_tfa_code returns false for the right code |
Ten minutes passed, a newer code was sent, the code was used, or it was typed in lower case or on another device | Send a new code; pass upper(trim(typed)) |