Merge branch 'master' of https://codefirst.iut.uca.fr/git/FLAD_Dev/FLAD
continuous-integration/drone/push Build is failing Details

master
David D'ALMEIDA 2 years ago
commit 1985877ff6

@ -1,17 +1,9 @@
import express, { Application } from 'express';
// import compression from 'compression';
import cors from 'cors';
// import db from './database';
// import morgan from 'morgan';
import Controller from './controller/Icontroller';
// import ErrorMiddleware from './middleware/error.middleware';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
// to secure
// import helmet from 'helmet';
import http from 'http';
import cookieParser from 'cookie-parser';
class App {
@ -30,20 +22,16 @@ class App {
this.initialiseMiddleware();
this.initialiseControllers(controllers);
// this.initialiseErrorHandling();
}
private initialiseMiddleware(): void {
// this.express.use(helmet());
this.express.use(cors());
this.express.use(cookieParser());
// this.express.use(morgan('dev'));
this.express.use(express.json());
this.express.use(express.urlencoded({ extended: false }));
// this.express.use(compression());
// mine
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({
extended: true
@ -60,9 +48,7 @@ class App {
});
}
// private initialiseErrorHandling(): void {
// this.express.use(ErrorMiddleware);
// }
public listen(): void {
const server = this.express.listen(this.port, () => {
@ -71,7 +57,6 @@ class App {
}
private initialiseDatabase(): void {
const { MONGO_USER, MONGO_PASSWORD, MONGO_PATH } = process.env;
const uri = "mongodb+srv://fladDevDb:ZslYlNRWIOUU7i6o@fladcluster.b29tytu.mongodb.net/?retryWrites=true&w=majority"
mongoose.connect(uri)
.then(() => console.log("Connect to MongoDB database successfully"))

@ -1,19 +0,0 @@
export default class CryptString{
stringCrypt: string;
constructor(length : number){
this.stringCrypt = this.generateRandomString(length);
}
generateRandomString (length : number){
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
}

@ -1,13 +1,9 @@
import Controller from '../Icontroller';
import { Router, Request, Response, NextFunction, RequestHandler } from 'express';
import { AuthReqBody } from './request/authReqBody';
import { Router, Request, Response, NextFunction } from 'express';
import HttpException from '../../middleware/exeption/httpExeption';
import axios from 'axios';
import CryptString from './crypt';
import AES from 'crypto-js'
import querystring from 'querystring';
import qs from 'qs';
import cookieParser from 'cookie-parser';
class SpotifyController implements Controller {
public path = '/spotify';
@ -19,7 +15,6 @@ class SpotifyController implements Controller {
this.initialiseRoutes();
}
initialiseRoutes() {
// this.router.post(`${this.path}`,this.createTask);
this.router.get(`${this.path}/exchange`,this.login);
this.router.get(`${this.path}/callback`,this.getAccessToken);
this.router.get(`${this.path}/refresh`,this.getRefreshToken);
@ -27,15 +22,12 @@ class SpotifyController implements Controller {
}
// need to put in ENvironement file
// private readonly CLIENT_CALLBACK_URL = "http://localhost:8080/callback";
private readonly API_URL = "https://accounts.spotify.com/api/token";
private readonly CLIENT_ID = "1f1e34e4b6ba48b388469dba80202b10";
private readonly CLIENT_SECRET = "779371c6d4994a68b8dd6e84b0873c82";
// private readonly CLIENT_CALLBACK_URL = "https://auth.expo.io/@thed47/FLAD//callback";
private readonly CALLBACK_2 = 'https://flad-api-production.up.railway.app/api/spotify/callback';
private readonly SCOPES ='user-read-private user-read-email user-read-playback-state user-read-currently-playing user-read-recently-played playlist-modify-public ugc-image-upload user-modify-playback-state';
private readonly ENCRYPTION_SECRET = new CryptString(16);
private readonly clientRedirect= 'spotify_final_redirect-uri-key';
private login = async (
@ -46,18 +38,7 @@ class SpotifyController implements Controller {
console.log("useeeee== login");
try {
// const params = req.body;
// if (!params.refresh_token) {
// return res.json({
// "error": "Parameter missing"
// });
// }
// this.spotifyRequest({
// grant_type: "authorization_code",
// redirect_uri: this.CLIENT_CALLBACK_2,
// // code: params.code
// })
const redirectResponse = req.query.redirectUrl ? req.query.redirectUrl : req.headers.referer;
res.cookie(this.clientRedirect, redirectResponse);
console.log("aloorrr si c'est niquuuuuuuuuuuueeee" +this.CALLBACK_2+ "gennnnnnnnnrree vraiiiiiiiment ");
@ -67,27 +48,9 @@ class SpotifyController implements Controller {
client_id: this.CLIENT_ID,
scope: this.SCOPES,
redirect_uri: this.CALLBACK_2,
// state: this.ENCRYPTION_SECRET.stringCrypt
}));
// '?response_type=code' +
// '&client_id=' +
// "1f1e34e4b6ba48b388469dba80202b10" +
// (this.SCOPES ? '&scope=' + encodeURIComponent(this.SCOPES) : '') +
// '&redirect_uri=' +
// encodeURIComponent(this.CALLBACK_2)
// );
// .then(session => {
// let result = {
// "access_token": session.access_token,
// "expires_in": session.expires_in,
// "refresh_token": this.encrypt(session.refresh_token)
// };
// return res.send(result);
// })
// .catch(response => {
// return res.json(response);
// });
} catch (error) {
next(new HttpException(400, 'Cannot create spot'));
}
@ -111,7 +74,7 @@ class SpotifyController implements Controller {
"error": "Parameter refresh_token missing"
});
}
var authOptions = {
let authOptions = {
method: 'POST',
url: 'https://accounts.spotify.com/api/token',
data: qs.stringify({
@ -125,14 +88,6 @@ class SpotifyController implements Controller {
json: true
};
// request.post(authOptions, function(error, response, body) {
// if (!error && response.statusCode === 200) {
// var access_token = body.access_token;
// res.send({
// 'access_token': access_token
// });
// }
// });
axios(authOptions)
.then(session => {
if(session.status === 200){
@ -194,11 +149,10 @@ class SpotifyController implements Controller {
): Promise<Response | void> => {
console.log("useeeee== accesToken");
var code = req.query.code;
var state = req.query.state || null;
var storedredirectUri = req.cookies ? req.cookies[this.clientRedirect] : null;
let code = req.query.code;
let state = req.query.state || null;
let storedredirectUri = req.cookies ? req.cookies[this.clientRedirect] : null;
// var storedState = req.cookies ? req.cookies[stateKey] : null;
var authOptions = {
method: 'POST',
url: 'https://accounts.spotify.com/api/token',
@ -217,15 +171,10 @@ class SpotifyController implements Controller {
var resp = await axios(authOptions);
if (resp.status === 200) {
console.log('oon esttt laaa');
var access_token = resp.data.access_token;
var expiration =resp.data.expires_in;
var refresh = resp.data.refresh_token
let access_token = resp.data.access_token;
let expiration =resp.data.expires_in;
let refresh = resp.data.refresh_token
console.log(access_token);
// res.send({
// "access_token": access_token,
// "expires_in": expiration,
// "refresh" : refresh
// });
res.clearCookie(this.clientRedirect);
res.redirect(`${storedredirectUri}?` +

@ -109,7 +109,8 @@ class LocationService {
// give a array of position sorted by distance and return the first
private findNearest(main : Position, list : Position[]){
this.orderByDistance(main, list)[0]
const nearest = this.orderByDistance(main, list)[0]
return nearest;
}
//distanceFn: DistanceFn = getDistance est param sa serrait cool de lui passer un fonction

@ -1643,7 +1643,7 @@ function onMessageArrived(message) {
if ( this._traceBuffer.length == this._MAX_TRACE_ENTRIES ) {
this._traceBuffer.shift();
}
if (i === 0) this._traceBuffer.push(arguments[i]);
if (i == 0) this._traceBuffer.push(arguments[i]);
else if (typeof arguments[i] === "undefined" ) this._traceBuffer.push(arguments[i]);
else this._traceBuffer.push(" "+JSON.stringify(arguments[i]));
}

Loading…
Cancel
Save