a. Create the LBUser class with an id, a name, and a password. e. Add a method to verify passwords.

Similar documents
A Smalltalk by the Seaside Implementing a Website the OO-Way

Reading an sent with Voltage Secur . Using the Voltage Secur Zero Download Messenger (ZDM)

Authorware Install Directions for IE in Windows Vista, Windows 7, and Windows 8

Online Sharing User Manual

Technical Guide for Remote access

Enterprise Asset Management System

Nick lunes 3 de septiembre de 12

VP-ASP Shopping Cart Quick Start (Free Version) Guide Version 6.50 March

Reporting Relationship Self Service Guide

Human Computer Interaction Final Project Tutorial. Hardware Inventory Management System (HIMS) By M. Michael Nourai

Google Sites: Site Creation and Home Page Design

Instructions for the Integrated Travel Manager (ITM) Self Service Password Reset (May 2011)

The Welcome screen displays each time you log on to PaymentNet; it serves as your starting point or home screen.

Managed Security Web Portal USER GUIDE

Worldspan Go! Internet Connection Office Management Instructions

USER GUIDE MANTRA WEB EXTRACTOR.

Supplier Management System User Guide

TriCore Secure Web Gateway User Guide 1

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

Remedy ITSM Service Request Management Quick Start Guide

Integrating Autotask Service Desk Ticketing with the Cisco OnPlus Portal

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Smart Web. User Guide. Amcom Software, Inc.

GroupWise Web Access 8.0

Baylor Secure Messaging. For Non-Baylor Users

TRIM: Web Tool. Web Address The TRIM web tool can be accessed at:


Umbraco v4 Editors Manual

Appendix A How to create a data-sharing lab

OUTLOOK WEB APP (OWA): MAIL

The goal with this tutorial is to show how to implement and use the Selenium testing framework.

Scan to Quick Setup Guide

Instance Creation. Chapter

Corporate Telephony Toolbar User Guide

User Guide. Voice Services Self Care Portal. Logging In. Welcome to the Self Care Portal

CAMPAIGNS...5 LIST BUILDER FORMS...

SOS SO S O n O lin n e lin e Bac Ba kup cku ck p u USER MANUAL

Introduction. Office of Web and New Media Missouri State University 901 S. National Ave. Springfield, MO 65897

MAXA-COOKIE-MANAGER - USER MANUAL - SW-Release V 5.0 / Document Rev. 1.1

Providers can access the precertification tool by logging in to the Amerigroup provider self service website or the Availity Web Portal.

QUANTIFY INSTALLATION GUIDE

MicroStrategy Quick Guide: Running the PI Report ITU Data Mart Support Group Go to reporting.gmu.edu and click on Login to Microstrategy

Last updated: October 4, einvoice. Attorney Manual

IBM Business Monitor V8.0 Global monitoring context lab

Merging Labels, Letters, and Envelopes Word 2013

User Manual. [Outlook Web App 2013]

Web Forms for Marketers 2.3 for Sitecore CMS 6.5 and

EBOX Digital Content Management System (CMS) User Guide For Site Owners & Administrators

Enterprise Toolbar User s Guide. Revised March 2015

Basic tutorial for Dreamweaver CS5

Getting Started with the Aloha Community Template for Salesforce Identity

What is Microsoft Excel?

State of Michigan Data Exchange Gateway. Web-Interface Users Guide

TBR System Office Performance Management Employee s Guide

Content Author's Reference and Cookbook

External End User Training Guide: Secure Extract

1. Open the Account Settings window by clicking on Account Settings from the Entourage menu.

Employee Express - PIV Card Registration Instructions

Getting Started Guide

How To Create An Easybelle History Database On A Microsoft Powerbook (Windows)

Client configuration and migration Guide Setting up Thunderbird 3.1

I N R O A D S, I N C. T R A I N I N G A N D D E V E L O P M E N T

Access and Login. Single Sign On Reference. Signoff

SmartBar for MS CRM 2013

Joostrap RWD Bootstrap Template

AgencyDash Data Management Solution Version 2.0 Help Guide. Release Date: July 1, 2008 Last Updated: August 17, 2010 Simtech Solutions Inc.

Departmental User Dashboard

Using the Educator Dashboard

SIGN Surgical Database Training Manual

PASTPERFECT-ONLINE DESIGN GUIDE

Banner Web Time Entry Approver s Handbook

Customer Database Pro Tutorial

CONNECTING TO THE DTS WIRELESS NETWORK USING WINDOWS VISTA

Using Entrust certificates with Microsoft Office and Windows

ConvincingMail.com Marketing Solution Manual. Contents

GP REPORTS VIEWER USER GUIDE

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

User Manual Sitecore Content Manager

Config Guide. Gimmal Smart Tiles (SharePoint-Hosted) Software Release 4.4.0

Web Work Module User s Guide

Table of Contents. Welcome Login Password Assistance Self Registration Secure Mail Compose Drafts...

To complete this workbook, you will need the following file:

Iceberg Commerce Video Gallery Extension 2.0 For Magento Version 1.3, 1.4, 1.5, 1,6

Table of Contents. Search Results.21. Equipment Change Request...10 Equipment Removal Request...11 Disposed..12 Not found 12

Company Setup 401k Tab

How to create an template

Using the Homes for Sale in the Mountains Web Site A Guide for Advertisers

Microsoft FrontPage 2003

Manager Approval of Timesheets

PEP 4 Georgia First Marketplace (Sciquest)

TM SysAid Chat Guide Document Updated: 10 November 2009

Installation & Configuration Guide Professional Edition

Secure Messaging Quick Reference Guide

Excel Pivot Tables. Blue Pecan Computer Training Ltd - Onsite Training Provider :: :: info@bluepecan.co.

PHI Audit Us er Guide

Unified Monitoring Portal Online Help Account Admin

EPM Performance Suite Profitability Administration & Security Guide

ACT State Testing Online Services Tutorial

Remote Storage Area (RSA) Basics

Employee User Guide Applying for Jobs

Transcription:

Many web sites and web applications limit access based on a user. We will demonstrate this functionality by identifying some functionality that is available only to registered users. 1. Create a class to model the user. a. Create the LBUser class with an id, a name, and a password. Object subclass: #LBUser instancevariablenames: 'id name password' classvariablenames: '' category: 'LosBoquitas' name ^ name. password: anobject b. Create accessors using the class refactoring menu (accepting all the proposed new methods). Note that one of the created methods is name1 (to return the name instance variable). This happened because there was already a name method (here it happens to be in a superclass), and the refactoring tool did not want to override the existing method. We do want to override the method, so add a name method. c. To remove the name1 method, select name1 in the method list, right-click, and select remove method. If there are any senders of name1 you will be asked to confirm the delete. d. In general, it is considered a poor practice to store passwords. Instead, applications should store some sort of one-way encryption of the password. To do this, modify the password: method that was generated so that instead of storing the passed-in string, we store a hash of the string. This is (only) a little bit more secure than a free-text string. password := anobject hash. e. Add a method to verify passwords. verifypassword: astring ^astring hash = password. initialize f. Add a method to initialize the values of the instance variables. super initialize. id := ''. name := ''. password := 0. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 1

<= auser g. Add a method to support sorting. ^self id <= auser id. h. Define a class instance variable to hold a cache of users (this is similar to what we did on LBEvent to cache events). Make sure that LBUser is selected, and then click on the class button below the class list. This will replace the class definition with a place to define class instance variables. LBUser class instancevariablenames: 'users' users i. Add the following class-side method to return the user list. users isnil iftrue: [ users := IdentitySet with: (self new id: 'admin'; name: 'Site Administrator'; password: 'passwd'; yourself). ^users. j. Add the following class-side method to lookup a user. userwithid: idstring password: passwordstring ^self users detect: [:each each id = idstring and: [each verifypassword: passwordstring]] ifnone: [nil 2. In LBMain class>># initialize (the initialize method on the class-side of LBMain) we define our application to use WASession. This is an object that holds various session information that is available to all components. We would like to hold a user as part of the session, so we will create a subclass that has an additional instance variable. a. Define LBSession with user as an instance variable. WASession subclass: #LBSession instancevariablenames: 'user' classvariablenames: '' category: 'LosBoquitas' b. Create instance variable accessors using the class refactoring menu. c. Modify LBMain class>>initialize to use this new session class. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 2

initialize " LBMain initialize. " super initialize. (self registerasapplication: 'boquitas') preferenceat: #sessionclass put: LBSession; d. Initialize LBMain so that it uses the new class. You can click anywhere on the third line of the method which contains the LBMain initialize comment and press <Ctrl>+<d> (for do-it ). 3. Create a login component that we can use. a. Create a class LBLoginComponent with two instance variables, userid and password. WAComponent subclass: #LBLoginComponent instancevariablenames: 'userid password' classvariablenames: '' category: 'LosBoquitas' b. Add a render method to show that it is being called. rendercontenton: html html heading: self class name. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 3

4. Refactor LBMain>># rendersidebaron: so that we have more small methods rather than a few large methods. This is a much-favored practice in the Smalltalk community. a. Select the four lines of code defining the home anchor in the class LBMain and the method # rendersidebaron:. Right-click after selecting the code and select refactor source and then extract method. b. This will pop up a dialog asking for a new name for the method. Enter renderhomeanchoron: html as the text and click OK or press <Enter>. c. This will show a Changes dialog on the ExtractMethodRefactoring where you can see two methods involved. One is a new method ( renderhomeanchoron: ) and the other is a modified method ( rendersidebaron: ). If you select the modified method you can see the current code (in red type) and code that will be installed if you click the accept 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 4

button (in green). Note that the refactoring will change the formatting somewhat and overstates the extent of the changes. Go ahead and click accept. d. In a similar manner, extract the Events -link creation code. Note that the refactoring changed the placement of the square brackets in the method. This means that we can no longer select full lines, but must select through the yourself but not the closing square bracket. Extract this code into a new method named rendereventsanchoron: html and accept the changes. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 5

5. Add a Login anchor. a. First, edit rendereventsanchoron: to add a break at the end so that subsequent elements are on a new line. rendereventsanchoron: html html anchor callback: [mainarea := LBScheduleComponent new]; with: 'Events'. html break. b. Next, create a new method very similar to the above to render the login link. renderloginanchoron: html html anchor callback: [mainarea := LBLoginComponent new]; with: 'Login'. html break. c. Finally, modify rendersidebaron: to call our new method (and get back our formatting). rendersidebaron: html html div id: 'sidebar'; class: 'section'; with: [ html heading level2; with: 'Menu'. self renderhomeanchoron: html; rendereventsanchoron: html; renderloginanchoron: html; d. In a web browser, navigate to the application and note the new link. Clicking on the link should show the login component. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 6

6. Add a login form to the login component. renderuseron: html a. Add various render methods to LBLoginComponent. Note that we can set focus to a particular field using explicit JavaScript. It would be more elegant to use a library (such as jquery), but this demonstrates the general capability. htmlid html div: [ html label for: (htmlid := html nextid); with: 'User:'. html textinput id: htmlid; value: userid; callback: [:value userid := value]; script: 'document.getelementbyid(', htmlid printstring, ').focus()'; renderpasswordon: html htmlid html div: [ html label for: (htmlid := html nextid); with: 'Password:'. html passwordinput id: htmlid; value: password; callback: [:value password := value]; warning self session user notnil iftrue: [ ^'Logged in as ', self session user name. (userid isnil or: [userid isempty]) iftrue: [ ^'Please enter User ID and Password'. ^'Login failed!'. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 7

renderwarningon: html html div: [ html span: ''; span: self warning; rendersubmiton: html html div: [ html submitbutton callback: [self login]; with: 'Login'. renderformon: html html form class: 'loginform'; with: [ self renderuseron: html; renderpasswordon: html; renderwarningon: html; rendersubmiton: html; rendercontenton: html self renderformon: html. b. Return to the web browser and click the Login link. Note that the formatting is not quite right since the text entry fields are not aligned. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 8

c. Edit LBFileLibrary>># boquitascss so that the lines beginning with.eventeditor now begin with form (referring to the element rather than the class). In this way CSS applies to both forms. form { display: table; } form > div { display: table-row; } form > div > * { display: table-cell; } form textarea { height: 4em; width: 40em; } form div.hidden { display: none; } login d. Refresh the browser and note that the fields are now aligned in a table layout. e. Clicking the Login button should give an error since the login method is not yet implemented. Add the following method to LBLoginComponent. user user := LBUser userwithid: userid password: password. self session user: user. user notnil iftrue: [ userid := nil. password := nil. f. Now try the application again. If you give a wrong user ID/password, you should get a message displayed with that information. If you give a correct user ID/password ( admin and passwd ), you should get a message identifying the logged in user. g. Modify rendercontenton: so that if a user is logged in we do not display the login form. rendercontenton: html self session user isnil iftrue: [ self renderformon: html. ] iffalse: [ html heading: 'Welcome, ', self session user name. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 9

7. Modify LBMain to handle the presence of a session user. a. Instead of always rendering a login link, we need an alternative. Add a renderlogouton: method. renderlogoutanchoron: html html anchor callback: [self session user: nil]; with: 'Logout ', self session user name. b. Modify the renderloginanchoron: method to remove the break at the end. renderloginanchoron: html html anchor callback: [mainarea := LBLoginComponent new]; with: 'Login'. renderuseron: html c. Create a renderuseron: method that will call one or the other of the above methods. self session user isnil iftrue: [ self renderloginanchoron: html. ] iffalse: [ self renderlogoutanchoron: html. html break. d. Modify the rendersidebaron: method so that it calls the renderuseron: method instead of the renderloginanchoron: method. rendersidebaron: html html div id: 'sidebar'; class: 'section'; with: [ html heading level2; with: 'Menu'. self renderhomeanchoron: html; rendereventsanchoron: html; renderuseron: html; e. Try the application with various combinations of correct and incorrect passwords. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 10

8. Restrict some features to logged-in users. a. Modify LBScheduleComponent>>#renderContentOn: as follows: rendercontenton: html listcomponent rows: LBEvent events assortedcollection. html render: listcomponent. self session user notnil iftrue: [ html anchor callback: [self add]; with: 'Add'. initialize b. Try the application when logged in and when not logged in. The Add link should appear and disappear based on the user state. c. Modify LBScheduleComponent>>#initialize as follows: columns super initialize. columns := OrderedCollection new add: self whoreportcolumn; add: self whatreportcolumn; add: self whenreportcolumn; add: self wherereportcolumn; self session user notnil iftrue: [ columns add: self actionreportcolumn. listcomponent := WATableReport new columns: columns; rowperiod: 1; d. Try the application when logged in and when not logged in. The delete link should appear and disappear based on the user state. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 11

9. Change the window title based on the subcomponent being viewed. a. As we discovered in chapter 4, the #updateroot method provides a way to set the title of the web browser window (and/or tab) to something appropriate for the page being displayed. Now we have a main component (LBMain) and three subcomponents (LBHome, LBLoginComponent, and LBScheduleComponent). Add LBHome>>#updateRoot as follows: updateroot: anhtmlroot super updateroot: anhtmlroot. anhtmlroot title: anhtmlroot title, ' -- Home'. b. Add LBLoginComponent>>#updateRoot as follows: updateroot: anhtmlroot super updateroot: anhtmlroot. anhtmlroot title: anhtmlroot title, ' -- Login'. c. Add LBScheduleComponent>>#updateRoot as follows: updateroot: anhtmlroot super updateroot: anhtmlroot. anhtmlroot title: anhtmlroot title, ' -- Event'. children d. Try navigating to the various subcomponents and observe that the title does not change. This is because Seaside is rendering the page head element (which contains the page title element) before it discovers what components will be included in the page which are in the page body element. To provide a solution to this problem, Seaside inquires of each component for a list of children before it starts rendering. This allows the subcomponents to participate more fully in preparing the page. Add LBMain>>#children as follows: ^super children, (Array with: mainarea). e. Now try navigating to the various subcomponents and observe that the title does change to match the current subcomponent. While the #children method is not necessary to process callbacks in Seaside 3.0 (as it was in earlier version of Seaside), it is considered good practice to do so. The absence of the #children method can cause subtle errors where components are displayed but seem to be ignored for some purposes. 10. Save your Pharo image. 5-Sep-16 Copyright 2016 by GemTalk Systems LLC 12