34 Triggers and Targets

34.1 Nitrogen Actions

34.1.1 Triggers and Targets

You can also specify the Trigger and Target directly in wf:wire/N. It takes three forms:

% Specify a trigger and target.wf:wire(Trigger, Target, Actions)
% Use the same element for both trigger and target.wf:wire(TriggerAndTarget, Actions)
% Assume the trigger and/or target is provided in the actions. % If not, then wire the action directly to the page. % (Useful for catching keystrokes.)wf:wire(Actions)

35 Quick Review

35.1 Nitrogen Actions

35.1.1 Quick Review

Elements make HTML.

Actions make Javascript.

An action can be wired using the actions property, or wired
later with wf:wire/N. Both approaches can take a single
action or a list of actions.

An action looks for trigger and target properties. These
can be specified in a few different ways.

Everything we have seen so far happens on the client.

36 PART 5 AGENDA

36.1 Nitrogen Events

What is a Postback?

Your First Postback

Event Properties

More Event Examples

Postback Shortcuts

Modifying Elements

37 What is a Postback?

37.1 Nitrogen Events

37.1.1 What is a Postback?

A postback briefly transfers control from the browser to the
Nitrogen server. It is initiated when an event fires with the
postback property set. For example:

#event { type=click, postback=my_click_event }

The postback tag can be any valid Erlang term. You use this to
differentiate incoming events.

49 Session State

49.1 Remembering State

49.1.1 Session State

Using Session State:

% Set a session state variablewf:session(Key, Value)
% Get a session state variablewf:session(Key)
wf:session_default(Key, DefaultValue)

Key and Value can be any valid Erlang term.

Exercise: Modify my_page.erl to display TWO counters. When the
user presses the 'Submit' button, one counter should get
incremented, the other counter should get doubled. The server
should remember the counters even if the user closes and then re-opens
the browser.

51.1 Security

52 Limiting Access to a Page

52.1 Security

52.1.1 Limiting Access to a Page

Nitrogen contains functions to help you build password protected websites:

Nitrogen is built for role-based security. You set the roles for
a current session, and check those roles later.

For example, the user may have the friend and manager
roles, but not the administrator role.

Authentication/authorization info is stored in the session.

53 Authentication and Authorization Functions

53.1 Security

53.1.1 Authentication and Authorization Functions

Functions to set the user/role:

% Get/set the current user for this session.wf:user(), wf:user(User)
% Get/set whether the current session has the specified role.wf:role(Role), wf:role(Role, IsInRole)

54 Page Redirection Functions

54.1 Security

54.1.1 Page Redirection Functions

Functions kick the user to a login page:

% Redirect the user to a different page.wf:redirect(Url)
% Redirect the user to the login page.wf:redirect_to_login(LoginUrl)
% Redirect the user back to the original page they % tried to access. wf:redirect_from_login(DefaultUrl)

55 Creating a Secure Page - Step 1

55.1 Security

55.1.1 Creating a Secure Page - Step 1

Check for the managers role at the top of a page. If the user
doesn't have the role, go to a login page.