Skip to content

Commit 3a04898

Browse files
committed
📦 NEW: Login to main
1 parent aee2c3d commit 3a04898

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

‎app/Run.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ public function clone_existing( $request ) {
170170

171171
public function auto_login( $request ) {
172172
$params = $request->get_json_params();
173-
$site_id = (int) $params['site_id'];
173+
174+
// Allow 'main' or an integer ID
175+
$site_id = isset( $params['site_id'] ) ? $params['site_id'] : '';
176+
if ( $site_id !== 'main' ) {
177+
$site_id = (int) $site_id;
178+
}
174179

175180
// Delegate to Site Model
176181
$login_url = Site::login( $site_id );

‎assets/js/admin-app.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ new Vue({
1818
data: {
1919
configurations: wpFreighterSettings.configurations || {},
2020
stacked_sites: wpFreighterSettings.stacked_sites || [],
21+
current_site_id: wpFreighterSettings.current_site_id || "",
2122
response: "",
2223
snackbar: false,
2324
snackbarText: "",
@@ -286,6 +287,24 @@ new Vue({
286287
console.log( error );
287288
});
288289
},
290+
loginToMain() {
291+
this.loading = true;
292+
axios.post( wpFreighterSettings.root + 'sites/autologin', {
293+
'site_id': 'main'
294+
})
295+
.then( response => {
296+
this.loading = false;
297+
if ( response.data.url ) {
298+
window.location.href = response.data.url;
299+
}
300+
})
301+
.catch( error => {
302+
this.loading = false;
303+
this.snackbarText = "Login failed: " + (error.response?.data?.message || error.message);
304+
this.snackbar = true;
305+
console.log( error );
306+
});
307+
},
289308
newSite() {
290309
this.$refs.form.validate()
291310
if ( ! this.new_site.valid ) {

‎templates/admin-wp-freighter.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<v-toolbar-title>WP Freighter</v-toolbar-title>
4141
<v-spacer></v-spacer>
4242
<v-toolbar-items>
43+
<v-btn v-if="configurations.domain_mapping == 'on' && configurations.current_site_id != ''" small text @click="loginToMain()">
44+
<v-icon>mdi-login-variant</v-icon> Login to main site
45+
</v-btn>
4346
<v-btn small text @click="openCloneMainDialog()"><v-icon>mdi-content-copy</v-icon> Clone main site</v-btn>
4447
<v-dialog v-model="new_site.show" persistent max-width="600px">
4548
<template v-slot:activator="{ on, attrs }">

0 commit comments

Comments
 (0)