parent
fbba95e1cf
commit
0ea0c130af
@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
export type AuthReqBody = {
|
||||
grant_type: string,
|
||||
redirect_uri?: string,
|
||||
code?: string,
|
||||
refresh_token?: string,
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
import Controller from '../Icontroller';
|
||||
import { Router, Request, Response, NextFunction, RequestHandler } from 'express';
|
||||
import { AuthReqBody } from './request/authReqBody';
|
||||
import HttpException from '../../middleware/exeption/httpExeption';
|
||||
import axios from 'axios';
|
||||
import CryptString from './crypt';
|
||||
import AES from 'crypto-js'
|
||||
import querystring from 'querystring';
|
||||
|
||||
class SpotifyController implements Controller {
|
||||
public path = '/spotify';
|
||||
public router = Router();
|
||||
|
||||
constructor() {
|
||||
console.log("useeeee");
|
||||
|
||||
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.post(`${this.path}/refresh`,this.getRefreshToken);
|
||||
this.router.get(`${this.path}/play/:musicId`, this.getMusic);
|
||||
}
|
||||
|
||||
// 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_URL = "http://localhost:8080/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 login = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<Response | void> => {
|
||||
|
||||
console.log("useeeee");
|
||||
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_URL,
|
||||
// // code: params.code
|
||||
// })
|
||||
res.redirect('https://accounts.spotify.com/authorize?' +
|
||||
querystring.stringify({
|
||||
response_type: 'code',
|
||||
client_id: this.CLIENT_ID,
|
||||
scope: this.SCOPES,
|
||||
redirect_uri: this.CALLBACK_URL,
|
||||
state: this.ENCRYPTION_SECRET.stringCrypt
|
||||
}));
|
||||
// .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'));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
// private getRefreshToken = async (
|
||||
// req: Request,
|
||||
// res: Response,
|
||||
// next: NextFunction
|
||||
// ): Promise<Response | void> => {
|
||||
|
||||
// console.log('UUse2');
|
||||
|
||||
// try {
|
||||
// const params = req.body;
|
||||
// if (!params.refresh_token) {
|
||||
// return res.json({
|
||||
// "error": "Parameter missing"
|
||||
// });
|
||||
// }
|
||||
|
||||
// this.spotifyRequest({
|
||||
// grant_type: "refresh_token",
|
||||
// refresh_token: this.decrypt(params.refresh_token)
|
||||
// })
|
||||
// .then(session => {
|
||||
// return res.send({
|
||||
// "access_token": session.access_token,
|
||||
// "expires_in": session.expires_in
|
||||
// });
|
||||
// })
|
||||
// .catch(response => {
|
||||
// return res.json(response);
|
||||
// });
|
||||
// console.log("errur");
|
||||
// } catch (error) {
|
||||
// next(new HttpException(400, 'Cannot create post'));
|
||||
// console.log("errur");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// };
|
||||
|
||||
public getMusic(){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// private spotifyRequest = (params : AuthReqBody) => {
|
||||
// return new Promise<any>(() => {
|
||||
// console.log("============ on est laaaa sa mer");
|
||||
// var code = req.query.code || null;
|
||||
// var state = req.query.state || null;
|
||||
|
||||
// axios.post(this.API_URL, {
|
||||
// form: params,
|
||||
// headers: {
|
||||
// "Authorization": "Basic " + new Buffer(this.CLIENT_ID + ":" + this.CLIENT_SECRET).toString('base64')
|
||||
// },
|
||||
// json: true
|
||||
// });
|
||||
// }).then(resp => {
|
||||
// if (resp.statusCode != 200) {
|
||||
// return Promise.reject({
|
||||
// statusCode: resp.statusCode,
|
||||
// body: resp.body
|
||||
// });
|
||||
// }
|
||||
// return Promise.resolve(resp.body);
|
||||
// })
|
||||
// .catch(err => {
|
||||
// return Promise.reject({
|
||||
// statusCode: 500,
|
||||
// body: err.stringify({})
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
|
||||
private getAccessToken = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<Response | void> => {
|
||||
|
||||
// console.log("heheh");
|
||||
// try {
|
||||
// var code = req.query.code;
|
||||
// var state = req.query.state;
|
||||
// console.log("================================================================================================================================");
|
||||
// console.log(req);
|
||||
// console.log("================================================================================================================================");
|
||||
|
||||
// if (state === null) {
|
||||
// next(new HttpException(400, 'Cannot create twerk'));
|
||||
// } else {
|
||||
// const resp : any = await axios.post('https://accounts.spotify.com/api/token',{
|
||||
// form: {
|
||||
// code: code,
|
||||
// redirect_uri: this.CALLBACK_URL,
|
||||
// // code_verifier : this.ENCRYPTION_SECRET.stringCrypt,
|
||||
// grant_type: 'authorization_code'
|
||||
// },
|
||||
// headers: {
|
||||
// 'Authorization': 'Basic ' + (new Buffer(this.CLIENT_ID + ':' + this.CLIENT_SECRET).toString('base64')),
|
||||
// },json: true}
|
||||
// );
|
||||
// if (resp.statusCode != 200) {
|
||||
// console.log(resp.statusCode, resp.body);
|
||||
// }
|
||||
// else{
|
||||
// console.log("error");
|
||||
// console.log(resp.statusCode, resp.body);
|
||||
// }
|
||||
|
||||
// }
|
||||
// // });
|
||||
// } catch (error) {
|
||||
// console.log(error);
|
||||
// next(new HttpException(400, 'Cannot create spot'));
|
||||
// }
|
||||
|
||||
var code = req.query.code || null;
|
||||
var state = req.query.state || null;
|
||||
// var storedState = req.cookies ? req.cookies[stateKey] : null;
|
||||
var authOptions = {
|
||||
url: 'https://accounts.spotify.com/api/token',
|
||||
form: {
|
||||
code: code,
|
||||
redirect_uri: this.CALLBACK_URL,
|
||||
grant_type: 'authorization_code'
|
||||
},
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + (new Buffer(this.CLIENT_ID + ':' + this.CLIENT_SECRET).toString('base64'))
|
||||
},
|
||||
json: true
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
private encrypt(text :any){
|
||||
return CryptoJS.AES.encrypt(text, this.ENCRYPTION_SECRET.stringCrypt).toString();
|
||||
};
|
||||
|
||||
private decrypt(text: any) {
|
||||
console.log("errer");
|
||||
var bytes = CryptoJS.AES.decrypt(text, this.ENCRYPTION_SECRET.stringCrypt);
|
||||
return bytes.toString(CryptoJS.enc.Utf8);
|
||||
};
|
||||
|
||||
}
|
||||
export default SpotifyController;
|
@ -0,0 +1,13 @@
|
||||
class HttpException extends Error {
|
||||
public status: number;
|
||||
public message: string;
|
||||
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
// en fontion de l'exeption firebas,etc une bonne exeption
|
||||
|
||||
export default HttpException;
|
@ -1,11 +1,15 @@
|
||||
import App from "./app";
|
||||
import SpotifyController from "./controller/spotify-controller/spotifyCtrl";
|
||||
import PingController from "./controller/TestCtrl";
|
||||
|
||||
const app = new App(
|
||||
[new PingController()],
|
||||
[new PingController(), new SpotifyController()],
|
||||
Number(8080)
|
||||
// Number(process.env.PORT)
|
||||
|
||||
);
|
||||
|
||||
app.listen();
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,111 @@
|
||||
// import { useState } from "react";
|
||||
// import SpotifyService from "../services/spotify/spotify.service";
|
||||
|
||||
// class Manager{
|
||||
|
||||
// // injection de dépences
|
||||
// spotifyService = new SpotifyService();
|
||||
// userService = new userService();
|
||||
|
||||
// private currentUser = useState(null);
|
||||
|
||||
// constructor() {
|
||||
// }
|
||||
|
||||
// // spotify methods
|
||||
// apiAuthorization(url : string) {
|
||||
// spotifyService.apiAuthorization(url);
|
||||
// }
|
||||
|
||||
// getCompleteMusic = async (id : string) :Promise<Music> =>{
|
||||
// // Map info = await spotifyService.getTrackInfo(id);
|
||||
// // return Music(id, info['name'], info['artist'], info['cover']);
|
||||
// }
|
||||
|
||||
// removeFromPlaylist(id : string) {
|
||||
// this.spotifyService.removeFromPlaylist(id);
|
||||
// }
|
||||
|
||||
|
||||
// addToPlaylist(id : string) {
|
||||
// this.spotifyService.addToPlaylist(id);
|
||||
// }
|
||||
|
||||
// playTrack(id : string) {
|
||||
// this.spotifyService.playTrack(id);
|
||||
// }
|
||||
// ////////////////////////////////////////////
|
||||
|
||||
// // private readonly getTaskById: RequestHandler = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
// // const id = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
|
||||
// // const data = await this.Taskservice.getTaskById(id, userId);
|
||||
// // res.status(201).send(data);
|
||||
|
||||
// // }
|
||||
// // catch(error){
|
||||
// // next(new HttpException(400, 'Cannot create post'));
|
||||
// // }
|
||||
|
||||
// // }
|
||||
|
||||
|
||||
// // private delete = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
// // const id = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
// // await this.Taskservice.DeleteTask(id, userId);
|
||||
// // return res.status(200).send({ status: "Success", msg: "Data Removed" });
|
||||
// // } catch (error) {
|
||||
// // next(new HttpException(400, 'Cannot create post'));
|
||||
// // }
|
||||
// // };
|
||||
|
||||
// // private updateTask = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
|
||||
// // const taskId = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
// // const reqBody:CreateTaskReqBody = Object.assign({}, req.body);
|
||||
|
||||
// // const updatedTask = await this.Taskservice.UpdateTask(
|
||||
// // // req.auth!.uid,
|
||||
// // taskId,
|
||||
// // userId,
|
||||
// // // firebase.auth().currentUser.getIdToken()
|
||||
// // reqBody.nom,
|
||||
// // reqBody.description,
|
||||
// // reqBody.logo,
|
||||
// // reqBody.duration,
|
||||
// // reqBody.done,
|
||||
// // // reqBody.tags,
|
||||
// // reqBody.repepat,
|
||||
// // reqBody.deb,
|
||||
// // reqBody.fin
|
||||
// // );
|
||||
// // // res.send('Success add');
|
||||
// // // res.status(201).json({ task });
|
||||
// // res.status(204).send(`Update a new contact: ${updatedTask}`);
|
||||
// // } catch (error) {
|
||||
// // console.log(error);
|
||||
// // next(new HttpException(403, 'Cannot create post'));
|
||||
// // }
|
||||
// // };
|
||||
|
||||
// }
|
||||
|
||||
// export default Manager;
|
@ -0,0 +1,13 @@
|
||||
class Music {
|
||||
private id : string;
|
||||
private name : string;
|
||||
private artist : string;
|
||||
private linkCover : string; // Image.source
|
||||
|
||||
constructor(id : string, name : string, artist : string, linkCover : string){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.artist = artist;
|
||||
this.linkCover = linkCover;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
class Spot {
|
||||
private userId : string;
|
||||
public music : Music;;
|
||||
constructor(userId : string, music : Music){
|
||||
this.userId = userId;
|
||||
this.music = music;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
// import { useState } from "react";
|
||||
// import SpotifyService from "../services/spotify/spotify.service";
|
||||
// import { makeRedirectUri, useAuthRequest } from 'expo-auth-session';
|
||||
|
||||
// class StubManager{
|
||||
|
||||
// // injection de dépences
|
||||
// spotifyService = new SpotifyService();
|
||||
// // userService = new userService();
|
||||
|
||||
// private currentUser = useState(null);
|
||||
// private discovery = {
|
||||
// authorizationEndpoint: 'https://accounts.spotify.com/authorize',
|
||||
// tokenEndpoint: 'https://accounts.spotify.com/api/token',
|
||||
// };
|
||||
// constructor() {
|
||||
// }
|
||||
|
||||
// // spotify methods
|
||||
// apiAuthorization(url : string){
|
||||
// const [, response, promptAsync] = useAuthRequest(
|
||||
// {
|
||||
// clientId: '1f1e34e4b6ba48b388469dba80202b10',
|
||||
// scopes: ['user-read-email', 'playlist-modify-public'],
|
||||
// // In order to follow the "Authorization Code Flow" to fetch token after authorizationEndpoint
|
||||
// // this must be set to false
|
||||
// usePKCE: false,
|
||||
// redirectUri: makeRedirectUri({
|
||||
// scheme: 'flad'
|
||||
// }),
|
||||
// },
|
||||
// this.discovery
|
||||
// );
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// getCompleteMusic = async (id : string) :Promise<Music> =>{
|
||||
// // Map info = await spotifyService.getTrackInfo(id);
|
||||
// // return Music(id, info['name'], info['artist'], info['cover']);
|
||||
// }
|
||||
|
||||
// removeFromPlaylist(id : string) {
|
||||
// this.spotifyService.removeFromPlaylist(id);
|
||||
// }
|
||||
|
||||
|
||||
// addToPlaylist(id : string) {
|
||||
// this.spotifyService.addToPlaylist(id);
|
||||
// }
|
||||
|
||||
// playTrack(id : string) {
|
||||
// this.spotifyService.playTrack(id);
|
||||
// }
|
||||
// ////////////////////////////////////////////
|
||||
|
||||
// // private readonly getTaskById: RequestHandler = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
// // const id = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
|
||||
// // const data = await this.Taskservice.getTaskById(id, userId);
|
||||
// // res.status(201).send(data);
|
||||
|
||||
// // }
|
||||
// // catch(error){
|
||||
// // next(new HttpException(400, 'Cannot create post'));
|
||||
// // }
|
||||
|
||||
// // }
|
||||
|
||||
|
||||
// // private delete = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
// // const id = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
// // await this.Taskservice.DeleteTask(id, userId);
|
||||
// // return res.status(200).send({ status: "Success", msg: "Data Removed" });
|
||||
// // } catch (error) {
|
||||
// // next(new HttpException(400, 'Cannot create post'));
|
||||
// // }
|
||||
// // };
|
||||
|
||||
// // private updateTask = async (
|
||||
// // req: Request,
|
||||
// // res: Response,
|
||||
// // next: NextFunction
|
||||
// // ): Promise<Response | void> => {
|
||||
// // try {
|
||||
|
||||
// // const taskId = req.params.taskId;
|
||||
// // const userId = req.params.userId;
|
||||
// // const reqBody:CreateTaskReqBody = Object.assign({}, req.body);
|
||||
|
||||
// // const updatedTask = await this.Taskservice.UpdateTask(
|
||||
// // // req.auth!.uid,
|
||||
// // taskId,
|
||||
// // userId,
|
||||
// // // firebase.auth().currentUser.getIdToken()
|
||||
// // reqBody.nom,
|
||||
// // reqBody.description,
|
||||
// // reqBody.logo,
|
||||
// // reqBody.duration,
|
||||
// // reqBody.done,
|
||||
// // // reqBody.tags,
|
||||
// // reqBody.repepat,
|
||||
// // reqBody.deb,
|
||||
// // reqBody.fin
|
||||
// // );
|
||||
// // // res.send('Success add');
|
||||
// // // res.status(201).json({ task });
|
||||
// // res.status(204).send(`Update a new contact: ${updatedTask}`);
|
||||
// // } catch (error) {
|
||||
// // console.log(error);
|
||||
// // next(new HttpException(403, 'Cannot create post'));
|
||||
// // }
|
||||
// // };
|
||||
|
||||
// }
|
||||
|
||||
// export default StubManager;
|
@ -0,0 +1,9 @@
|
||||
class User {
|
||||
//attributes from DAFL
|
||||
private idDafl : any;;
|
||||
private idSpotify : any;
|
||||
//constructors
|
||||
constructor(){
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
export const spotifyCredentials = {
|
||||
clientId: 'a5cb39302b6e4c64957de1df50742d71',
|
||||
clientSecret: 'e23db1cd77ee4b589ee99525e282b2e8',
|
||||
redirectUri: 'Your Redirect URI'
|
||||
}
|
After Width: | Height: | Size: 757 B |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 715 B |
After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1,7 @@
|
||||
|
||||
const Icons = {
|
||||
discovery: require('./icon_discovery.png'),
|
||||
// riveLike : require('./light_like.riv'),
|
||||
}
|
||||
|
||||
export default Icons;
|
Binary file not shown.
@ -0,0 +1,49 @@
|
||||
import { View, Text, Image , Dimensions, StyleSheet, Pressable } from 'react-native'
|
||||
import React, { useRef, useState } from 'react'
|
||||
import Animated,{ Extrapolate, interpolate, useAnimatedGestureHandler, useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
|
||||
|
||||
import { PanGestureHandler, PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
|
||||
import * as Haptics from 'expo-haptics';
|
||||
import Icons from '../../assets/icons/icon';
|
||||
import Rive, { Fit, RiveRef } from 'rive-react-native';
|
||||
|
||||
const {width : wWidht} = Dimensions.get("window");
|
||||
const SCREEN_HEIGHT = Dimensions.get('window').height
|
||||
const SCREEN_WIDTH = Dimensions.get('window').width
|
||||
// const width = wWidht *0.75;
|
||||
// const height = wWidht * (465/264);
|
||||
// const borderRadius = 24;
|
||||
interface ButtonProps {
|
||||
name : string;
|
||||
}
|
||||
|
||||
const FladButton = ({name} : ButtonProps) => {
|
||||
const riveRef = React.useRef<RiveRef>(null);
|
||||
|
||||
const handlePlay = () => { riveRef.current?.play() };
|
||||
return (
|
||||
<Pressable onPress={handlePlay}>
|
||||
<Image source={Icons.discovery} style={[styles.image]} />
|
||||
</Pressable>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
button : {
|
||||
justifyContent : 'center',
|
||||
alignItems : 'center',
|
||||
},
|
||||
image : {
|
||||
borderRadius : 24,
|
||||
resizeMode: 'cover',
|
||||
width: 65,
|
||||
height: 65,
|
||||
backgroundColor: 'black',
|
||||
}
|
||||
})
|
||||
|
||||
export default FladButton;
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
import { useState } from 'react';
|
||||
import { View, Text, Image, Animated ,PanResponder, Dimensions, StyleSheet, ImageBackground, Button, Pressable, TextInput } from 'react-native'
|
||||
|
||||
interface InputProps {
|
||||
name : string;
|
||||
placeholder : string;
|
||||
}
|
||||
|
||||
const FladInput = ({name, placeholder} : InputProps) => {
|
||||
const [focused, setFocused] = useState<boolean>(false);
|
||||
|
||||
return (
|
||||
<View>
|
||||
<Text></Text>
|
||||
<TextInput style={[styles.input]}>
|
||||
|
||||
</TextInput>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
input : {
|
||||
justifyContent : 'center',
|
||||
alignItems : 'center',
|
||||
placeholder : "placeholde"
|
||||
},
|
||||
})
|
||||
|
||||
export default FladInput;
|
@ -0,0 +1,136 @@
|
||||
import { View, Text, Image, Animated ,PanResponder, Dimensions, StyleSheet, ImageBackground, Button, Pressable, Touchable, TouchableOpacity, Modal, SafeAreaView, TextInput, Platform } from 'react-native'
|
||||
import React, { useCallback, useEffect, useRef, useState, useTransition } from 'react'
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import * as Haptics from 'expo-haptics';
|
||||
import * as AuthSession from 'expo-auth-session';
|
||||
|
||||
import Card from '../components/Card';
|
||||
import axios from 'axios';
|
||||
import { cards as cardArray } from '../FakeData/data'
|
||||
import FladButton from '../components/button/button';
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import { makeRedirectUri, useAuthRequest } from 'expo-auth-session';
|
||||
|
||||
const SCREEN_WIDTH = Dimensions.get('window').width
|
||||
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
|
||||
interface LoginProps {
|
||||
}
|
||||
interface Params {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
interface Profile {
|
||||
display_name: string;
|
||||
email: string;
|
||||
id: string;
|
||||
}
|
||||
//generate random string
|
||||
const MY_SECURE_AUTH_STATE_KEY = 'MySecureAuthStateKey';
|
||||
|
||||
WebBrowser.maybeCompleteAuthSession();
|
||||
|
||||
// Endpoint
|
||||
const discovery = {
|
||||
authorizationEndpoint: 'https://accounts.spotify.com/authorize',
|
||||
tokenEndpoint: 'https://accounts.spotify.com/api/token',
|
||||
};
|
||||
|
||||
|
||||
async function save(key : string, value : string) {
|
||||
await SecureStore.setItemAsync(key, value);
|
||||
}
|
||||
|
||||
export default function Login() {
|
||||
// const [advice, setAdvice] = useState("dd");
|
||||
const [request, response, promptAsync] = useAuthRequest(
|
||||
{
|
||||
responseType: AuthSession.ResponseType.Token,
|
||||
clientId: '1f1e34e4b6ba48b388469dba80202b10',
|
||||
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'],
|
||||
redirectUri: makeRedirectUri({
|
||||
scheme: 'flad'
|
||||
}),
|
||||
},
|
||||
discovery
|
||||
);
|
||||
|
||||
const getAdvice = async () => { axios.get("http://localhost:8080/api/spotify/exchange")
|
||||
.then(response => {
|
||||
console.log(response.data.message);
|
||||
|
||||
// setAdvice(response.data.message);
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
React.useEffect(() => {
|
||||
if (response && response.type === 'success') {
|
||||
const auth = response.params.access_token;
|
||||
const storageValue = JSON.stringify(auth);
|
||||
|
||||
if (Platform.OS !== 'web') {
|
||||
// Securely store the auth on your device
|
||||
save(MY_SECURE_AUTH_STATE_KEY, storageValue);
|
||||
}
|
||||
}
|
||||
}, [response]);
|
||||
|
||||
return (
|
||||
<View style={styles.centeredView}>
|
||||
<Text style={styles.textStyle}>Hello flad test logIn</Text>
|
||||
<Button disabled={!request} title="Login"
|
||||
onPress={() => {
|
||||
promptAsync();
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
centeredView: {
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
marginTop: 22,
|
||||
},
|
||||
modalView: {
|
||||
margin: 20,
|
||||
backgroundColor: 'white',
|
||||
borderRadius: 20,
|
||||
padding: 35,
|
||||
alignItems: 'center',
|
||||
shadowColor: '#000',
|
||||
shadowOffset: {
|
||||
width: 0,
|
||||
height: 2,
|
||||
},
|
||||
shadowOpacity: 0.25,
|
||||
shadowRadius: 4,
|
||||
},
|
||||
header :{
|
||||
alignItems : 'flex-end',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
button: {
|
||||
borderRadius: 20,
|
||||
padding: 10,
|
||||
elevation: 2,
|
||||
},
|
||||
buttonOpen: {
|
||||
backgroundColor: '#F194FF',
|
||||
},
|
||||
textStyle: {
|
||||
color: 'white',
|
||||
fontWeight: 'bold',
|
||||
textAlign: 'center',
|
||||
},
|
||||
close :{
|
||||
alignSelf : 'flex-end',
|
||||
backgroundColor : 'red',
|
||||
justifyContent : 'center'
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -0,0 +1,33 @@
|
||||
export class AuthentificationService {
|
||||
|
||||
constructor(private auth: Auth, private http: HttpClient) { }
|
||||
name = "toto";
|
||||
|
||||
async register({ email, password }) {
|
||||
try {
|
||||
const user = await createUserWithEmailAndPassword(this.auth, email, password);
|
||||
return user;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async login({ email, password }) {
|
||||
// should for all method use a cloud function to creata user
|
||||
try {
|
||||
const user = await signInWithEmailAndPassword(this.auth, email, password);
|
||||
return user;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
logout() {
|
||||
return signOut(this.auth);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
// export class ApiSpotifyIdentification {
|
||||
|
||||
// private state : string;
|
||||
// private codeVerifier : string;
|
||||
// private codeChallenge : string;
|
||||
// private encodedLogs : string;
|
||||
// constructor(){
|
||||
// // this.state = _generateRandomString(16);
|
||||
// // this.codeVerifier = _generateRandomString(_generateRandomInt(43, 128));
|
||||
// // this.codeChallenge = _generateCodeChallenge();
|
||||
// // this.encodedLogs = base64.encode(utf8.encode("$clientId:$_clientSecret"));
|
||||
// }
|
||||
|
||||
// setCode(url : string){
|
||||
// throw new Error("Not implemented");
|
||||
// }
|
||||
// createToken(url : string){
|
||||
// throw new Error("Not implemented");
|
||||
// }
|
||||
// }
|
@ -1,30 +1,25 @@
|
||||
// import { ApiSpotifyIdentification } from "./ApiSpotifyIdentification";
|
||||
// import { SpotifyRequest } from "./spotifyRequestHandler/spotifyRequest";
|
||||
import axios from "axios";
|
||||
|
||||
|
||||
// export class SpotifyService {
|
||||
export default class SpotifyService {
|
||||
private readonly API_URL = "http://localhost:8080/api/spotify/exchange";
|
||||
|
||||
// private identification : ApiSpotifyIdentification;
|
||||
// public request : SpotifyRequest;
|
||||
constructor() {
|
||||
|
||||
// constructor() {
|
||||
// this.identification= new ApiSpotifyIdentification();
|
||||
// this.request = new SpotifyRequest();
|
||||
// }
|
||||
}
|
||||
// get id(){
|
||||
// return this.identification;
|
||||
// }
|
||||
|
||||
// get id(){
|
||||
// return this.identification;
|
||||
// }
|
||||
// async apiAuth(url : string) {
|
||||
// await this.identification.setCode(url);
|
||||
// // this.request = ApiSpotifyRequests(await this.identification.createToken());
|
||||
// }
|
||||
async getSpotifyCredentials() {
|
||||
const res = await axios.get(this.API_URL)
|
||||
// then verify error
|
||||
const spotifyCredentials = res.data;
|
||||
return spotifyCredentials
|
||||
}
|
||||
|
||||
// async apiAuth(url : string) {
|
||||
// await this.identification.setCode(url);
|
||||
// this.request = ApiSpotifyRequests(await this.identification.createToken());
|
||||
// }
|
||||
|
||||
// async getSpotifyCredentials() {
|
||||
// const res = await axios.get('/api/spotify-credentials')
|
||||
// const spotifyCredentials = res.data
|
||||
// return spotifyCredentials
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
import { AuthentificationService } from "../Auth/authentificationService.service";
|
||||
|
||||
export class UserService {
|
||||
|
||||
constructor(private auth: AuthentificationService) {}
|
||||
|
||||
getUserProfile() {
|
||||
const user = this.auth.currentUser;
|
||||
const userDocRef = doc(this.firestore, `User/${user.uid}`);
|
||||
return docData(userDocRef);
|
||||
}
|
||||
async uploadName(name: string, email : string) {
|
||||
const user = this.auth.currentUser;
|
||||
try {
|
||||
const userDocRef = doc(this.firestore, `User/${user.uid}`);
|
||||
await setDoc(userDocRef, {
|
||||
name,
|
||||
email
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue