Skip to main content

Posts

Showing posts from August, 2017

Sample passport Express dùng strategy Github

Link tut:  https://gist.github.com/jokecamp/65604d50227b8ea8e0d3 Đầu tiên càn tạo Github apps: Vô Setting (profile j đó) > Github Apps (tab bên trái dưới) > new app. điền đúng thông tin redirect URL, callback (ai làm Facebook OAuth, Google 0Auth thì rõ). Code demo: package.json: { "name": "securehelloworld", "version": "1.0.0", "description": "", "main": "server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.13.3", "express-session": "^1.11.3", "passport": "^0.3.0", "passport-github": "^1.0.0" } } 1 var express = require('express'); 2 var app = express(); 3 var passpo...

Note some js date time

// Compute diff datetime // Don't know why fetch from MySQL query become Date JS object without convert.  var last_activity = result_find_usr_by_id[0].updated_at; console.log('last ' + last_activity); var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds var todayDate = new Date(); console.log('today ' + todayDate); var diffDays = 0; if(typeof last_activity !== 'undefined') {     // Split timestamp into [ Y, M, D, h, m, s ]     // var t = last_activity.split(/[- :]/);     // Apply each element to the Date function     // var last_activity = new Date(Date.UTC(t[0], t[1]-1, t[2], t[3], t[4], t[5]));     var diffDays = Math.round(Math.abs((last_activity.getTime() - todayDate.getTime())/(oneDay)));         console.log('diff '+ diffDays);      } /**  * You first need to create a formatting function to pad numbers to two digits…  **/ function twoDigits(d) { ...