@@ -505,6 +505,14 @@ class="mt-4"
505505 <v-list-item :subtitle="site.home_url">
506506 <v-list-item-title>{{ site.name }} ({{ site.environment }})</v-list-item-title>
507507 <template v-slot:append>
508+ <v-btn
509+ size="small"
510+ variant="tonal"
511+ @click="magicLoginForDeployTarget(site)"
512+ class="mr-2"
513+ >
514+ Login
515+ </v-btn>
508516 <v-btn
509517 size="small"
510518 color="primary"
@@ -9946,6 +9954,40 @@ class="mt-5"
99469954 console.log(error.response)
99479955 });
99489956 },
9957+ magicLoginForDeployTarget(target) {
9958+ let job_id = Math.round((new Date()).getTime());
9959+ let environment = target.environment.toLowerCase();
9960+ let description = `Magic login to ${target.home_url}`;
9961+ let endpoint = `/wp-json/captaincore/v1/sites/${target.id}/${environment}/magiclogin`;
9962+
9963+ this.jobs.push({"job_id": job_id,"description": description, "status": "running", "command":"login"});
9964+
9965+ axios.get( endpoint, {
9966+ headers: {'X-WP-Nonce':this.wp_nonce}
9967+ })
9968+ .then(response => {
9969+ if ( response.data.includes("There has been a critical error on this website") ) {
9970+ this.jobs.filter(job => job.job_id == job_id)[0].status = "error";
9971+ this.snackbar.message = description + " failed due to PHP error. Check server PHP logs.";
9972+ this.snackbar.show = true;
9973+ return
9974+ }
9975+ if ( response.data.includes("http") ) {
9976+ window.open( response.data.trim() );
9977+ this.jobs.filter(job => job.job_id == job_id)[0].status = "done";
9978+ } else {
9979+ this.jobs.filter(job => job.job_id == job_id)[0].status = "error";
9980+ this.snackbar.message = description + " failed.";
9981+ this.snackbar.show = true;
9982+ }
9983+ })
9984+ .catch(error => {
9985+ this.jobs.filter(job => job.job_id == job_id)[0].status = "error";
9986+ this.snackbar.message = description + " failed.";
9987+ this.snackbar.show = true;
9988+ console.log(error.response)
9989+ });
9990+ },
99499991 inputFile (newFile, oldFile) {
99509992
99519993 if (newFile && oldFile) {
0 commit comments