mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · javascript –...

16
Javascript 36 JavaScript is always synchronous and single-threaded. If you're executing a JavaScript block of code on a page then no other JavaScript on that page will currently be executed.

Upload: others

Post on 23-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript

36

JavaScript is always synchronous and single-threaded. If you're executing a JavaScript block of code on a pagethen no other JavaScript on that page will currently be executed.

Page 2: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript – Callback and Promise

37

One approach to asynchronous programming is to make functions that perform a slow action take an extra argument, a callback function. The action is started, and when it finishes, the callback function is called with the result.

setTimeout(() => console.log("Tick"), 500);

A promise is an asynchronous action that may complete at some point and produce a value. It is able to notify anyone who is interested when its value is available.

let fifteen = Promise.resolve(15);fifteen.then(value => console.log(`Got ${value}`));

Page 3: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript – Callback and Promise

38

Page 4: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript – Callback and Promise

39

Page 5: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript – Callback and Promise

40

Page 6: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Javascript – Callback and Promise

41

https://www.youtube.com/watch?v=8aGhZQkoFbQ

Page 7: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Web e pattern architetturali

42

Page 8: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Pattern architetturali

43

Multi-Page Application

Single-Page Application

Page 9: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Pattern MVC

44

https://it.wikipedia.org/wiki/Model-view-controller

Vantaggi:

1) Disaccoppiare2) Responsabilità certe3) View multiple

Page 10: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Architettura generica

45

The presentation layer is where the data is formattedand presented to the user.

The service layer is wherethe business logic of the application is implemented.

The persistence layer is where the data is simply savedor retrieve.

Page 11: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

AJAX – L’inizio delle SPA

46

https://embed.plnkr.co/rgh75JGDGuyB4UhBvTYN/

Asynchronous Javascript And XML

Page 12: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Esempio di SPA

47

Page 13: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Il mondo reale è composto da soluzioni ibride

48

Web server

Approcci ibridiMix di soluzioniEvoluzione continua

Trend:- PWA vs Mobile- Low Code- Serverless- Static site generators- MicroService

Frontend Backend

Mastering Chaos - A Netflix Guide to Microserviceshttps://www.youtube.com/watch?v=CZ3wIuvmHeM

Less servers for your Angular apphttps://www.youtube.com/watch?v=WEYtDYBkalI

UI Bakeryhttps://www.youtube.com/watch?v=xbB3MrEi5bo

Page 14: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

SecuritySQL Injection

49

Page 15: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Cosa è:

50

SQL injection è una tecnica di code injection dove si inietta del codice SQL

https://www.acunetix.com/websitesecurity/sql-injection/

Page 16: Mobile 2019didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:triennale:... · Javascript – Callback and Promise 37 One approach to asynchronous programming is to make functions

Come si combatte?

51

Semplicemente usando: prepared statements and parameterized queries

$stmt = $dbConnection‐>prepare('SELECT * FROM employees WHERE name = ?’);$stmt‐>bind_param('s', $name);

$unsafe_variable = $_POST["user‐input"];$safe_variable = mysql_real_escape_string($unsafe_variable);mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')");

Oppure pulendo tutti gli input: