@ -74,6 +74,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
filteredCartePars : any ;
filters = { } ;
secondaryApp : any ;
constructor ( public afAuth : AngularFireAuth , public afDb : AngularFireDatabase ,
private router : Router , private route : ActivatedRoute ,
private authService : AuthService , private opComService : OpCommercialService , private toastrService : ToastrService ) {
@ -95,6 +96,14 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this . parrainDateTimeTest = new Date ( this . parrain . birthday ) ;
this . yearTest = this . parrain . birthday . getFullYear ( ) ;
this . databaseRef = firebase . database ( ) . ref ( ) ;
const config = { apiKey : 'AIzaSyD2O5MxwZ4BRWvVc77FZliBvtj0pmcdzos' ,
authDomain : 'webappparrain.firebaseapp.com' ,
databaseURL : 'https://webappparrain.firebaseio.com' } ;
this . secondaryApp = null ;
this . secondaryApp = firebase . apps . length <= 1 ? firebase . initializeApp ( config , 'Secondary' ) : firebase . app ( 'Secondary' ) ;
this . user . subscribe (
( auth ) = > {
if ( auth ) {
@ -224,10 +233,12 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
regiPar ( ) {
const config = { apiKey : 'AIzaSyD2O5MxwZ4BRWvVc77FZliBvtj0pmcdzos' ,
/ * c o n s t c o n f i g = { a p i K e y : ' A I z a S y D 2 O 5 M x w Z 4 B R W v V c 7 7 F Z l i B v t j 0 p m c d z o s ' ,
authDomain : 'webappparrain.firebaseapp.com' ,
databaseURL : 'https://webappparrain.firebaseio.com' } ;
const secondaryApp = firebase . initializeApp ( config , 'Secondary' ) ;
let secondaryApp = null ;
secondaryApp = firebase . initializeApp ( config , 'Secondary' ) ; * /
let parrainTemp = new Parrain ( ) ;
this . carteEnvoieOK = false ;
this . parrain . status = 'Parrain' ;
@ -236,7 +247,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this . parrain . password = this . getRandomArbitrary ( 111111 , 999999 ) . toString ( ) ;
// this.authService.signUp(this.parrain);
parrainTemp = this . parrain ;
secondaryApp . auth ( ) . createUserWithEmailAndPassword ( parrainTemp . email , parrainTemp . password ) . then ( function ( userCreate ) {
this . secondaryApp . auth ( ) . createUserWithEmailAndPassword ( parrainTemp . email , parrainTemp . password ) . then ( function ( userCreate ) {
console . log ( 'User ' + userCreate . uid + ' created successfully!' ) ;
// I don't know if the next statement is necessary
const imagePath = 'profilImage/' + userCreate . uid + '/userPic.jpg' ;
@ -256,11 +267,11 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
secondaryApp . auth ( ) . sendPasswordResetEmail ( userCreate . email ) ;
this . secondaryApp . auth ( ) . sendPasswordResetEmail ( userCreate . email ) ;
userCreate . sendEmailVerification ( ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
secondaryApp . auth ( ) . signOut ( ) ;
this . secondaryApp . auth ( ) . signOut ( ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
} catch ( e ) {
@ -271,7 +282,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
// this.router.navigate(['/']);
}
//fin
// secondaryApp.auth().signOut();
// this. secondaryApp.auth().signOut();
} ) ;
@ -532,9 +543,10 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
const offsets = document . getElementById ( 'subCard1' ) . getBoundingClientRect ( ) ;
const imgTop = offsets . top ;
const imgLeft = offsets . left ;
//canvas.width = document.getElementById('subCard1').offsetWidth;
//canvas.height = document.getElementById('subCard1').offsetHeight;
img . onload = function ( ) {
context . drawImage ( img , imgLeft , imgTop );
context . drawImage ( img , imgLeft , imgTop , 1920 , 1200 );
} ;
img . crossOrigin = 'Anonymous' ;
canvas . crossOrigin = 'Anonymous' ;
@ -568,6 +580,72 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
} ) ;
}
sectionToImage2 ( maCarteP : CarteParrainage ) {
html2canvas ( document . getElementById ( 'subCard1' ) , {
// allowTaint: true,
useCORS : true ,
logging : true ,
width : 750 ,
height : 1050 ,
onrendered : function ( canvas ) {
const context = canvas . getContext ( '2d' ) ;
context . scale ( 2 , 2 ) ;
const img = new Image ( ) ;
const offsets = document . getElementById ( 'subCard1' ) . getBoundingClientRect ( ) ;
const imgTop = offsets . top ;
const imgLeft = offsets . left ;
const w = offsets . width ;
const h = offsets . height ;
// var w = 1000;
// var h = 1000;
//canvas.width = w * 2;
//canvas.height = h * 2;
// canvas.style.width = offsets.width + 'px';
// canvas.style.height = offsets.height + 'px';
img . onload = function ( ) {
context . drawImage ( img , imgLeft , imgTop ) ;
} ;
img . crossOrigin = 'Anonymous' ;
canvas . crossOrigin = 'Anonymous' ;
canvas . id = 'canvas' ;
var imgg = canvas . toDataURLHD ( 'image/png' , 1 ) ;
window . open ( imgg ) ;
document . body . appendChild ( canvas ) ;
console . log ( 'avant blob' ) ;
/ * c a n v a s . t o B l o b ( b l o b = > {
const nouvelleImg = new Image ( ) ;
const storageRef = firebase . storage ( ) . ref ( ) ;
nouvelleImg . setAttribute ( 'crossOrigin' , 'anonymous' ) ;
nouvelleImg . src = blob ;
console . log ( 'blob : ' + blob ) ;
console . log ( 'maCarteP.uid: ' + maCarteP . uid ) ;
storageRef . child ( 'CarteParrainage/' + maCarteP . uid + '/carteTemplate.jpg' ) . put ( blob ) . then ( ( snapshot ) = > {
const updates = { } ;
maCarteP . carteTemplate . path = 'CarteParrainage/' + maCarteP . uid + '/carteTemplate.jpg' ;
maCarteP . carteTemplate . filename = maCarteP . name ;
maCarteP . carteTemplate . downloadURL = snapshot . downloadURL ;
console . log ( 'maCarteP.carteTemplate.filename : ' + maCarteP . carteTemplate . filename ) ;
console . log ( 'maCarteP.uid: ' + maCarteP . uid ) ;
updates [ 'CarteParrainage/' + maCarteP . uid ] = maCarteP ;
console . log ( 'updates[\'CarteParrainage/\' + maCarteP.uid].name ' + updates [ 'CarteParrainage/' + maCarteP . uid ] . name ) ;
firebase . database ( ) . ref ( ) . update ( updates ) ;
console . log ( 'fin du blob' ) ;
} ) ;
} , 'image/jpeg' , 20 ) ; * /
}
} ) ;
}
goToOpComm() {
this . router . navigate ( [ '/opCommercial' ] ) ;
}