prototyping a social network - polito.it...license • this work is licensed under the creative...

34
Prototyping a Social Network AngularJS: Firebase integration with AngularFire

Upload: others

Post on 25-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Prototyping a

Social

NetworkAngularJS: Firebase integration with

AngularFire

Page 2: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Pizza++

AngularJS: Firebase integration with AngularFire5/7/2017 2

Page 3: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Pizza++ Feature Set

• Find top pizzas to eat near me

• Post pizzas

• Rate pizzas

• Review (comment) pizzas

• Discuss about pizzas with my friends

5/7/2017 3AngularJS: Firebase integration with AngularFire

Page 4: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Pizza++

• Ingredients for frontend

– HTML5

– CSS3, with the help of the Bootstrap framework

(http://getbootstrap.com)

– JS, with the AngularJS framework

(http://angularjs.org/)

• Ingredients for backend

– None

– We will rely on Firebase (https://firebase.google.com)

5/7/2017 4AngularJS: Firebase integration with AngularFire

Page 5: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

FIREBASE

Getting started…

5/7/2017 5AngularJS: Firebase integration with AngularFire

Page 6: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Firebase• A powerful platform for mobile or web applications

– https://firebase.google.com

• Overview (video)

– https://youtu.be/ySmWlU9j3j4

• Quickstart for the Web

– https://firebase.google.com/docs/web/setup

5/7/2017 6AngularJS: Firebase integration with AngularFire

Page 7: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Realtime Database

• The Firebase Realtime Database is a cloud-

hosted database

• Data in our Firebase database

– stored as JSON

– synchronized in realtime to every connected client

• Automatically scales with your app

• Works offline

5/7/2017 7AngularJS: Firebase integration with AngularFire

Page 8: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Realtime Database

5/7/2017 8AngularJS: Firebase integration with AngularFire

Page 9: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Realtime Database: Structuring Data

• "Everything is a JSON"

• Avoid nesting data:

– with nested design, iterating through the data becomes

problematic

5/7/2017 9AngularJS: Firebase integration with AngularFire

Page 10: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Realtime Database: Structuring Data

• Prefer flattened data:

– split data into separate paths

5/7/2017 10AngularJS: Firebase integration with AngularFire

Page 11: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Authentication

• Built-in support for user authentication

• Support

– Social Login (Facebook, Twitter, GitHub, Google)

– Anonymous Login

– Login with username and password

– Custom auth system integration

• Handle user login entirely with client-side code

• Integrate authentication with your existing

backend

– if needed

5/7/2017 11AngularJS: Firebase integration with AngularFire

Page 12: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Authentication

5/7/2017 12AngularJS: Firebase integration with AngularFire

Page 13: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Hosting

• Deploy your web app in seconds

– Hosting gives you the infrastructure, features, and

tooling tailored to deploying and managing static

websites

• Hosting gives your project a subdomain on the

firebaseapp.com domain

• All of your content is served over HTTPS

– SSL by default

5/7/2017 13AngularJS: Firebase integration with AngularFire

Page 14: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Hosting

5/7/2017 14AngularJS: Firebase integration with AngularFire

Page 15: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Cloud storage

• store and serve user-generated content

– It is possible to store images, audio, video, or other

user-generated content

• It adds Google security to file uploads and

downloads

• On the server, use Google Cloud Storage to

access the same files

5/7/2017 15AngularJS: Firebase integration with AngularFire

Page 16: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Cloud storage

5/7/2017 16AngularJS: Firebase integration with AngularFire

Page 17: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

HOW TO INTEGRATE

FIREBASE IN ANGULARJS

Getting started with Pizza++ and Firebase

5/7/2017 17AngularJS: Firebase integration with AngularFire

Page 18: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Integrate Firebase in AngularJS

5/7/2017 18

http://lmgtfy.com/?q=angularjs+firebase

AngularJS: Firebase integration with AngularFire

Page 19: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

AngularFire

• Firebase library for AngularJS

– https://github.com/firebase/angularfire

• The officially supported AngularJS binding for

Firebase

• Getting started guide

– https://github.com/firebase/angularfire/blob/master/doc

s/quickstart.md

5/7/2017 19AngularJS: Firebase integration with AngularFire

Page 20: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

(GUIDED) EXERCISE

Getting started with Pizza++ and Firebase

5/7/2017 20AngularJS: Firebase integration with AngularFire

Page 21: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

(Guided) Exercise

• Starting from the knowledge of the previous

lab…

– https://github.com/SoNet-2017/angularjs-lab7/releases

1. integrate AngularFire and Firebase

2. read/write the JSON data from/to Firebase

5/7/2017 21AngularJS: Firebase integration with AngularFire

Page 22: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Step 1: create a Google account

5/7/2017 22AngularJS: Firebase integration with AngularFire

Page 23: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Step 2: create a new project

5/7/2017 23AngularJS: Firebase integration with AngularFire

Page 24: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 24

• Open the file data/pizzas.json

• Modify the structure so that it has a "pizzas" path as

origin of the tree:

Step 3: recreate the pizza++ data structure

AngularJS: Firebase integration with AngularFire

Page 25: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 25

• Import the data in Firebase

Step 3: recreate the pizza++ data structure

AngularJS: Firebase integration with AngularFire

Page 26: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 26

• Import the data in Firebase

Step 3: recreate the pizza++ data structure

AngularJS: Firebase integration with AngularFire

Page 27: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 27

• Default security rules require users to be authenticated

Step 4: Don't forget RULES

AngularJS: Firebase integration with AngularFire

Page 28: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 28

• We want to read data without authentication, so ->

Deactivate this rule by typing the following code (and

pressing PUBLISH):

Step 4: Don't forget RULES

AngularJS: Firebase integration with AngularFire

Page 29: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 29

• https://github.com/firebase/angularfire/blob/master/docs/q

uickstart.md

Step 5: Use the documentation

AngularJS: Firebase integration with AngularFire

Page 30: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 30

Tip: to get config info

AngularJS: Firebase integration with AngularFire

Step 1:

Page 31: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 31

Tip: to get config info

AngularJS: Firebase integration with AngularFire

Step 1:

Step 2: Project Settings

Page 32: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

5/7/2017 32

Tip: to get config info

AngularJS: Firebase integration with AngularFire

Step 1:

Step 2: Project Settings

Step 3: Add Firebase to your web app

Page 33: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

Questions?

Teodoro Montanaro

[email protected]

01QYAPD SOCIAL NETWORKING: TECHNOLOGIES

AND APPLICATIONS

Page 34: Prototyping a Social Network - polito.it...License • This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License

License

• This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License.

• You are free:– to Share - to copy, distribute and transmit the work

– to Remix - to adapt the work

• Under the following conditions:– Attribution - You must attribute the work in the manner specified by the

author or licensor (but not in any way that suggests that they endorse you or your use of the work).

– Noncommercial - You may not use this work for commercial purposes.

– Share Alike - If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

• To view a copy of this license, visit http://creativecommons.org/license/by-nc-sa/3.0/

5/7/2017 34AngularJS: Firebase integration with AngularFire