SlideShare a Scribd company logo
UNTANGLING THE WEB
FALL 2017 WEEK 10 – AUTHENTICATION, EJS PARTIALS, DATABASES, MORE ON
USING NPM
AGENDA
• Authentication using http-auth
• A simpler database example
• EJS partials demo
• Project work time – get your database input worked out
NPM PACKAGES
• First step to providing new functionality in nodejs is to check npm to see if a package exists for what you
want to do
• Authentication, for instance
HOW TO NARROW DOWN YOUR PACKAGE CHOICES?
• Make your search as specific as possible
THEN I LOOK FOR VERSION NUMBER AND DATE
• If something has been updated recently that’s good UNLESS it’s a version 0.x or 1.x in which case I may
go with something updated a bit longer ago
• If other packages are using it that’s good
• If there is a github link and it’s got a lot of contributors and forks and stars then that’s even better
• Check the license – MIT is best, but other open source licenses are fine
USER AUTHENTICATION
• HTTP-AUTH is a very decent user authentication package for node
• It sets up HTTP basic authentication (or at least that’s what we’ll use out of the package. There are
other options)
• HTTP Basic authentication is managed by the browser through the use of session variables
• So when you close the browser you’ll have to log back in again
• I use incognito mode to test this so that it doesn’t store any information and I can log in each time I test
OTHER AUTH OPTIONS
• Two factor is a great system to prevent account problems. A good tutorial on bluemix is here:
• https://www.ibm.com/developerworks/library/se-configure-multifactor-authentication-bluemix-node.js-
applications/index.html
• OAuth is another authentication scheme that can allow you to use you facebook, google, etc. login to
control access to your website
• In a real website, these options are probably best to consider, but they are a bit more challenging to set
up
DEMO – ADDING BASIC AUTH TO THE SAMPLE
WEBSITE
• https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
EXERCISE
• On your website (locally or on bluemix), add basic authentication for all of your pages
EJS
• EJS is a simple templating engine
• It is used for things like headers and footers, but also to pass variables from node into your html
• This way you can do data operations on the server side and just display on the client side
• Good tutorial: https://scotch.io/tutorials/use-ejs-to-template-your-node-application
• This is also a good resource: http://www.embeddedjs.com/getting_started.html
EJS EXERCISE
• https://ionicabizau.github.io/ejs-playground/
• On this playground, I’d like you to make a list of 5 animals and for each animal have as script calculate
the number of letters in the name of the animal and list those values
• Syntax is here: http://www.embeddedjs.com/getting_started.html
• Remember the = sign for printing variables!!
EJS SOLUTION
•
<%
var animals = ["Orangutan", "Margay", "Liger", "Goat", "Rat"];
%>
•
These animals are amazing:
<% for(var i = 0; i < animals.length; ++i) {%>
- <%=animals[i]%>
<%=animals[i].length%>
<% } %>
•
PASSING VARIABLES FROM THE SERVER
• In routes/index.html
• Pull of the request and pass as a locals object
• In app.js
• Set as an app.locals variable
• In either case you can use from within templates <%=
PROCESS TO UNDERSTAND THE SAMPLE WEBSITE
• Tearing out the more complex parts to replace them with simpler parts
HOMEWORK 10 (DUE NOV 22 BEFORE CLASS)
• Create a web site using nodejs that uses basic authentication (use the http-auth module)
• Do not allow the page to be displayed if a valid logon is not given
• Use an ejs partial to provide a footer that shows the logged in user
• Submit this as a github repository and email a screenshot of it running on your machine
• (no live website is required for this homework)
HOMEWORK 11 (DUE NOV 22ND BEFORE CLASS)
• Create a project that has a database of animals and how many legs they have
• Allow the user to enter an animal from the web page
• This should be running as a project on bluemix, with the database in cloudant
• Each person should have their own project and database (although the databases can be on the same
cloudant instance on the same bluemix account)
• Submit the github repository, the running website address, and a screenshot of the database

More Related Content

PPTX
Untangling11
PPTX
Untangling - fall2017 - week 9
PPTX
Untangling - fall2017 - week 8
PPTX
Untangling spring week11
PPTX
Untangling - fall2017 - week 7
PPTX
Untangling spring week10
PPTX
Untangling spring week5
PPTX
Untangling spring week9
Untangling11
Untangling - fall2017 - week 9
Untangling - fall2017 - week 8
Untangling spring week11
Untangling - fall2017 - week 7
Untangling spring week10
Untangling spring week5
Untangling spring week9

What's hot (20)

PPTX
Untangling spring week8
PPTX
Untangling spring week4
PPTX
Untangling spring week12
PPTX
Untangling fall2017 week1
PPTX
Untangling7
PPTX
Untangling the web week 2 - SEO
PPTX
Untangling spring week2
PPTX
A Personal Journey
PDF
Engage 2019: Modernising Your Domino and XPages Applications
PPTX
Job DSL Plugin for Jenkins
PPTX
Untangling fall2017 week2
PDF
Why use Go for web development?
PDF
APIs: A Better Alternative to Page Objects
PPTX
Configuration As Code: The Job DSL Plugin
PPTX
Jenkins Job DSL plugin
PDF
Dev112 let's calendar that
PPTX
Untangling6
PDF
The Job DSL Plugin: Introduction & What’s New
PPTX
Engage 2019 - De04. Java with Domino After XPages
PPTX
Automated Acceptance Testing from Scratch
Untangling spring week8
Untangling spring week4
Untangling spring week12
Untangling fall2017 week1
Untangling7
Untangling the web week 2 - SEO
Untangling spring week2
A Personal Journey
Engage 2019: Modernising Your Domino and XPages Applications
Job DSL Plugin for Jenkins
Untangling fall2017 week2
Why use Go for web development?
APIs: A Better Alternative to Page Objects
Configuration As Code: The Job DSL Plugin
Jenkins Job DSL plugin
Dev112 let's calendar that
Untangling6
The Job DSL Plugin: Introduction & What’s New
Engage 2019 - De04. Java with Domino After XPages
Automated Acceptance Testing from Scratch
Ad

Similar to Untangling - fall2017 - week 10 (20)

PPTX
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
PDF
KrishnaToolComparisionPPT.pdf
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
PDF
[Struyf] Automate Your Tasks With Azure Functions
PPTX
AngularJS One Day Workshop
PPTX
Geek Sync | Deployment and Management of Complex Azure Environments
PDF
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
PDF
Tech Talk on Cloud Computing
PPTX
Cloud Platforms for Java
PDF
Testing mit Codeception: Full-stack testing PHP framework
PDF
Node.js Development Workflow Automation with Grunt.js
PPTX
Azure Functions Real World Examples
PDF
Adobe AEM CQ5 - Developer Introduction
PPTX
Testing for Logic App Solutions | Integration Monday
PPTX
Cypress report
PPTX
How to build webapps with tools
PDF
Beyond Domino Designer
PDF
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
PDF
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
PDF
Introduction to Microsoft Flow and Azure Functions
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
KrishnaToolComparisionPPT.pdf
Continuous Delivery - Automate & Build Better Software with Travis CI
[Struyf] Automate Your Tasks With Azure Functions
AngularJS One Day Workshop
Geek Sync | Deployment and Management of Complex Azure Environments
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Tech Talk on Cloud Computing
Cloud Platforms for Java
Testing mit Codeception: Full-stack testing PHP framework
Node.js Development Workflow Automation with Grunt.js
Azure Functions Real World Examples
Adobe AEM CQ5 - Developer Introduction
Testing for Logic App Solutions | Integration Monday
Cypress report
How to build webapps with tools
Beyond Domino Designer
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
Introduction to Microsoft Flow and Azure Functions
Ad

More from Derek Jacoby (14)

PPTX
Untangling - fall2017 - week6
PPTX
Untangling - fall2017 - week5
PPTX
Untangling the web - fall2017 - class 4
PPTX
Untangling the web fall2017 class 3
PPTX
Untangling fall2017 week2_try2
PPTX
Untangling spring week7
PPTX
Untangling spring week6
PPTX
Untangling spring week3
PPTX
Untangling spring week1
PPTX
Untangling the web11
PPTX
Untangling the web10
PPTX
Untangling the web9
PPTX
Untangling8
PPTX
Untangling4
Untangling - fall2017 - week6
Untangling - fall2017 - week5
Untangling the web - fall2017 - class 4
Untangling the web fall2017 class 3
Untangling fall2017 week2_try2
Untangling spring week7
Untangling spring week6
Untangling spring week3
Untangling spring week1
Untangling the web11
Untangling the web10
Untangling the web9
Untangling8
Untangling4

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Classroom Observation Tools for Teachers
GDM (1) (1).pptx small presentation for students
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Module 4: Burden of Disease Tutorial Slides S2 2025
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Classroom Observation Tools for Teachers

Untangling - fall2017 - week 10

  • 1. UNTANGLING THE WEB FALL 2017 WEEK 10 – AUTHENTICATION, EJS PARTIALS, DATABASES, MORE ON USING NPM
  • 2. AGENDA • Authentication using http-auth • A simpler database example • EJS partials demo • Project work time – get your database input worked out
  • 3. NPM PACKAGES • First step to providing new functionality in nodejs is to check npm to see if a package exists for what you want to do • Authentication, for instance
  • 4. HOW TO NARROW DOWN YOUR PACKAGE CHOICES? • Make your search as specific as possible
  • 5. THEN I LOOK FOR VERSION NUMBER AND DATE • If something has been updated recently that’s good UNLESS it’s a version 0.x or 1.x in which case I may go with something updated a bit longer ago • If other packages are using it that’s good • If there is a github link and it’s got a lot of contributors and forks and stars then that’s even better • Check the license – MIT is best, but other open source licenses are fine
  • 6. USER AUTHENTICATION • HTTP-AUTH is a very decent user authentication package for node • It sets up HTTP basic authentication (or at least that’s what we’ll use out of the package. There are other options) • HTTP Basic authentication is managed by the browser through the use of session variables • So when you close the browser you’ll have to log back in again • I use incognito mode to test this so that it doesn’t store any information and I can log in each time I test
  • 7. OTHER AUTH OPTIONS • Two factor is a great system to prevent account problems. A good tutorial on bluemix is here: • https://www.ibm.com/developerworks/library/se-configure-multifactor-authentication-bluemix-node.js- applications/index.html • OAuth is another authentication scheme that can allow you to use you facebook, google, etc. login to control access to your website • In a real website, these options are probably best to consider, but they are a bit more challenging to set up
  • 8. DEMO – ADDING BASIC AUTH TO THE SAMPLE WEBSITE • https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
  • 9. EXERCISE • On your website (locally or on bluemix), add basic authentication for all of your pages
  • 10. EJS • EJS is a simple templating engine • It is used for things like headers and footers, but also to pass variables from node into your html • This way you can do data operations on the server side and just display on the client side • Good tutorial: https://scotch.io/tutorials/use-ejs-to-template-your-node-application • This is also a good resource: http://www.embeddedjs.com/getting_started.html
  • 11. EJS EXERCISE • https://ionicabizau.github.io/ejs-playground/ • On this playground, I’d like you to make a list of 5 animals and for each animal have as script calculate the number of letters in the name of the animal and list those values • Syntax is here: http://www.embeddedjs.com/getting_started.html • Remember the = sign for printing variables!!
  • 12. EJS SOLUTION • <% var animals = ["Orangutan", "Margay", "Liger", "Goat", "Rat"]; %> • These animals are amazing: <% for(var i = 0; i < animals.length; ++i) {%> - <%=animals[i]%> <%=animals[i].length%> <% } %> •
  • 13. PASSING VARIABLES FROM THE SERVER • In routes/index.html • Pull of the request and pass as a locals object • In app.js • Set as an app.locals variable • In either case you can use from within templates <%=
  • 14. PROCESS TO UNDERSTAND THE SAMPLE WEBSITE • Tearing out the more complex parts to replace them with simpler parts
  • 15. HOMEWORK 10 (DUE NOV 22 BEFORE CLASS) • Create a web site using nodejs that uses basic authentication (use the http-auth module) • Do not allow the page to be displayed if a valid logon is not given • Use an ejs partial to provide a footer that shows the logged in user • Submit this as a github repository and email a screenshot of it running on your machine • (no live website is required for this homework)
  • 16. HOMEWORK 11 (DUE NOV 22ND BEFORE CLASS) • Create a project that has a database of animals and how many legs they have • Allow the user to enter an animal from the web page • This should be running as a project on bluemix, with the database in cloudant • Each person should have their own project and database (although the databases can be on the same cloudant instance on the same bluemix account) • Submit the github repository, the running website address, and a screenshot of the database