code cecilia et thierry

anis
Tmadkaud 6 years ago
parent 2afd8e9e73
commit 02bffcd04a

@ -0,0 +1,17 @@
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
passport.use(new FacebookStrategy({
clientID: "191092458179642",
clientSecret: "964e490d7e49a13ee7a77c9b65419fb3",
callbackURL: "https://localhost:3000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({name: profile.displayName}, {name: profile.displayName,userid: profile.id}, function(err, user) {
if (err) { return done(err); }
done(null, user);
});
}
));
module.exports = passport;

@ -0,0 +1,16 @@
var passport = require('passport');
var GitHubStrategy = require('passport-github').Strategy;
passport.use(new GitHubStrategy({
clientID: "60a0296da9fce6ca3b7e",
clientSecret: "9fb2f52123d9d840c98b98b3b4ffbc5dd77d1de3",
callbackURL: "https://localhost:3000/auth/github/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({userid: profile.id}, {name: profile.displayName,userid: profile.id}, function (err, user) {
return done(err, user);
});
}
));
module.exports = passport;

@ -0,0 +1,16 @@
var passport = require('passport');
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
passport.use(new GoogleStrategy({
clientID: "633754977454-7dcfrsfob7sjq5lim47tc63pdjch6imr.apps.googleusercontent.com",
clientSecret: "D7lHcUgZbCpmWZtooRlICzAH",
callbackURL: "https://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ userid: profile.id }, { name: profile.displayName,userid: profile.id }, function (err, user) {
return done(err, user);
});
}
));
module.exports = passport;

@ -14,7 +14,7 @@ var FileMongoShema = new Schema({
type: String,
unique: false
},
extention: {
type: {
type: String,
unique: false
},

72
package-lock.json generated

@ -11550,6 +11550,11 @@
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
},
"oauth": {
"version": "0.9.15",
"resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz",
"integrity": "sha1-vR/vr2hslrdUda7VGWQS/2DPucE="
},
"oauth-sign": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",
@ -12109,6 +12114,47 @@
"pause": "0.0.1"
}
},
"passport-facebook": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/passport-facebook/-/passport-facebook-2.1.1.tgz",
"integrity": "sha1-w50LUq5NWRYyRaTiGnubYyEwMxE=",
"requires": {
"passport-oauth2": "1.4.0"
}
},
"passport-github": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/passport-github/-/passport-github-1.1.0.tgz",
"integrity": "sha1-jOHj/NYa11eOsd9ZWDnkrqEjVdQ=",
"requires": {
"passport-oauth2": "1.4.0"
}
},
"passport-google-oauth": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/passport-google-oauth/-/passport-google-oauth-1.0.0.tgz",
"integrity": "sha1-ZfUGMxkq0GJ6GLCJYAdxCdhOt20=",
"requires": {
"passport-google-oauth1": "1.0.0",
"passport-google-oauth20": "1.0.0"
}
},
"passport-google-oauth1": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/passport-google-oauth1/-/passport-google-oauth1-1.0.0.tgz",
"integrity": "sha1-r3SoA99R7GRvZqRNgigr5vEI4Mw=",
"requires": {
"passport-oauth1": "1.1.0"
}
},
"passport-google-oauth20": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-1.0.0.tgz",
"integrity": "sha1-O5YOih1w0dvnlGFcgnxoxAOSpdA=",
"requires": {
"passport-oauth2": "1.4.0"
}
},
"passport-jwt": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-3.0.1.tgz",
@ -12132,6 +12178,27 @@
}
}
},
"passport-oauth1": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/passport-oauth1/-/passport-oauth1-1.1.0.tgz",
"integrity": "sha1-p96YiiEfnPRoc3cTDqdN8ycwyRg=",
"requires": {
"oauth": "0.9.15",
"passport-strategy": "1.0.0",
"utils-merge": "1.0.1"
}
},
"passport-oauth2": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.4.0.tgz",
"integrity": "sha1-9i+BWDy+EmCb585vFguTlaJ7hq0=",
"requires": {
"oauth": "0.9.15",
"passport-strategy": "1.0.0",
"uid2": "0.0.3",
"utils-merge": "1.0.1"
}
},
"passport-strategy": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
@ -14665,6 +14732,11 @@
"integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=",
"optional": true
},
"uid2": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz",
"integrity": "sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I="
},
"ultron": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz",

@ -49,6 +49,9 @@
"ng-html-util": "1.0.x",
"ngm-cli": "0.5.x",
"passport": "^0.4.0",
"passport-facebook": "^2.1.1",
"passport-github": "^1.1.0",
"passport-google-oauth": "^1.0.0",
"passport-jwt": "^3.0.1",
"rxjs": "^6.0.0-rc.1",
"rxjs-compat": "^6.0.0-rc.1",

@ -13,6 +13,14 @@ var fs = require('fs');
var multer = require('multer');
var upload = multer({ dest: './public/' });
var passportFacebook = require('../auth/facebook');
var passportGoogle = require('../auth/google');
var passportGitHub = require('../auth/github');
/* creation Token */
getToken = function (headers) {
if (headers && headers.authorization) {
@ -215,4 +223,44 @@ router.get('/getCurrentUser', passport.authenticate('jwt', { session: false}), f
}
});
////////////
/* GET users listing. */
router.get('/', ensureAuthenticated, function(req, res, next) {
res.render('user', { user: req.user });
});
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/login')
}
/* FACEBOOK ROUTER */
router.get('/facebook', passportFacebook.authenticate('facebook'));
router.get('/facebook/callback', passportFacebook.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
/* GOOGLE ROUTER */
router.get('/google', passportGoogle.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));
router.get('/google/callback', passportGoogle.authenticate('google', { failureRedirect: '/login' }), function(req, res) {
res.redirect('/');
});
/* GITHUB ROUTER */
router.get('/github', passportGitHub.authenticate('github', { scope: [ 'user:email' ] }));
router.get('/github/callback', passportGitHub.authenticate('github', { failureRedirect: '/login' }), function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
module.exports = router;

@ -77,30 +77,32 @@
<!--<td>{{ file.name }}</td>-->
<td>{{ file.taille / ( 1024 * 1024 ) | number : '1.2-2'}} Mo</td>
<td>{{ file.extention }}</td>
<td>{{ file.type }}</td>
<td>{{ file.lastDate }}</td>
<div *ngIf="file.extention === ('image/jpeg')">
<div *ngIf="file.type === ('image/jpeg')">
<img src="../../../public/{{ file._id.toString() }}" class="img-fluid flex-center" width="150" height="150">
</div>
<div *ngIf="file.extention === ('image/png')">
<div *ngIf="file.type === ('image/png')">
<img src="../../../public/{{ file._id.toString() }}" class="img-fluid flex-center" width="150" height="150">
</div>
<div *ngIf="file.extention === ('application/pdf')">
<div *ngIf="file.type === ('application/pdf')">
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
</div>
<div *ngIf="file.extention === ('video/mp4')">
<!--<i class="fa fa-file-movie-o" aria-hidden="true"></i>-->
<div *ngIf="file.type === ('video/mp4')">
<!--<i class="fa fa-file-movie-o" aria-hidden="true"></i>
<vg-player style="height: 200px; width: 200px">
<video [vgMedia]="media" #media id="singleVideo" preload="auto" controls>
<source src="../../../public/{{ file._id.toString() }}" type="video/mp4">
</video>
</vg-player>
</vg-player>-->
</div>
<div *ngIf="file.extention === ('text/plain')">
<div *ngIf="file.type === ('text/plain')">
<i class="fa fa-file-text-o" aria-hidden="true"></i>
<!--<div>{{ reader !== 'undifined' ? reader.result : ''}}</div>-->
<!--<div>{{ reader !== 'undifined' ? reader.result : ''}}</div>
<div>{{test}}</div>
<a href = "../../../public/{{file._id}}">show me</a>-->
</div>
<div *ngIf="file.extention === ('audio/mpeg')">
<div *ngIf="file.type === ('audio/mpeg')">
<!--<i class="fa fa-file-audio-o" aria-hidden="true"></i>-->
<vg-player style="height: 50px; width: 400px">
<vg-controls>

@ -8,6 +8,7 @@ import {Http} from "@angular/http";
import {Form} from "@angular/forms";
import * as formData from 'form-data';
import {forEach} from '@angular/router/src/utils/collection';
import {type} from 'os';
@Component({
selector: 'app-book',
@ -25,12 +26,13 @@ export class BookComponent implements OnInit, OnDestroy {
httpOptions: any;
isClickCreateFolder: boolean;
inputCreateFolder: String;
reader: FileReader;
test: String;
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
this.isClickCreateFolder = false;
this.fileChooseName = 'None';
this.filesToUpload = [];
this.test = '';
}
ngOnInit() {
@ -80,24 +82,50 @@ export class BookComponent implements OnInit, OnDestroy {
//var preview = document.querySelector('img');
var meee = this;
this.http.post('/api/getFileList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(files => {
if (files) {
// this.allUserFile = files;
this.allUserFile = files;
/*
for (let f of this.allUserFile) {
console.log('f.extention : ' + f.extention);
if (f.extention === ('text/plain')) {
this.reader = new FileReader();
let contenido;
console.log('ffff : ' + JSON.stringify(f));
this.reader.onload = (e) => {
contenido = this.reader.result;
console.log('contenido : ' + contenido);
};
this.reader.readAsText(f);
}
} */
// for (let f of this.allUserFile) {
//
// console.log('f.type : ' + f.type);
//
//
// /*
// var textFileAsBlob = new Blob([f.blob], {
// type: 'text/plain'
// });*/
//
// if (f.type === ('text/plain')) {
// JSON.stringify(f);
// //f.function( fii => {
// this.reader = new FileReader();
// var ff = new Blob([JSON.stringify(f, null, 2)], {type: 'text/plain'})
// var me = this;
// this.reader.onload = function(e:any) {
// me.test = e.target.result;
// console.log('meee.test : ' + JSON.stringify(e.target.result));
// };
// //ff.type = f.type;
// //ff.size = f.taille;
// //ff.slice(f);
// var gugu = new File(('../../../public/' + f._id)[], f.name);
// this.reader.readAsText('../../../public/' + f._id.toString(), f.name);
//
// //console.log('couilles : ' + meee.reader.readAsText(fii));
//
// //console.log('couilles : ' + JSON.stringify(f));
// //});
//
//
// }
// }
} else {
this.allUserFile = [];
}
@ -164,7 +192,7 @@ export class BookComponent implements OnInit, OnDestroy {
upload() {
if(this.mainFolder !== undefined){
this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), extention: this.filesToUpload[0].type.toString(), taille: this.filesToUpload[0].size.toString(), idUser: this.currentUser._id.toString(), owner: this.currentUser.username.toString(), lastDate: Date.now().toString() }).subscribe(resp => {
this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), type: this.filesToUpload[0].type.toString(), taille: this.filesToUpload[0].size.toString(), idUser: this.currentUser._id.toString(), owner: this.currentUser.username.toString(), lastDate: Date.now().toString(), data: ''}).subscribe(resp => {
this.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => {
this.getfiles();
this.filesToUpload = null;

@ -15,3 +15,9 @@
</p>
</form>
</div>
<button class="btn-facebook" href="/auth/facebook"></button>
<button class="btn-github" href="/auth/github"></button>
<button class="btn-google" href="/auth/google"></button>
Loading…
Cancel
Save