Skip to content

Commit

Permalink
UJ: Merged from template.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwieds committed Dec 1, 2023
2 parents 9d504fc + 9ddaeae commit 78cd84d
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 47 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ jobs:
sed "s/%GHP_TIMESTAMP%/$timestamp/g" $build_log_path > "$build_log_path"-temp && mv "$build_log_path"-temp $build_log_path
sed -n '1h;1!H;${;g;s/GEN>>>.*<<<GEN/<REDACTED FOR LIVE PUBLISH>/g;p;}' .gitignore > .gitignore
- name: Delete gh-pages branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ secrets.GH_TOKEN }}
branches: gh-pages
# - name: Delete gh-pages branch
# uses: dawidd6/action-delete-branch@v3
# with:
# github_token: ${{ secrets.GH_TOKEN }}
# branches: gh-pages
# soft_fail: true
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion _layouts/master/authentication/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ <h1 class="text-primary">$264 USD</h1>

<div class="col-md-auto">
<div class="d-grid d-sm-flex gap-3">
<a class="btn btn-white auth-billing-update-btn" href="javascript:;" target="_blank" rel="nofollow" hidden>Manage plan</a>
<a class="btn btn-soft-primary auth-billing-update-btn" href="javascript:;" target="_blank" rel="nofollow" hidden>Manage plan</a>
<a class="btn btn-success auth-billing-subscribe-btn" href="{{ site.url }}/pricing" target="_blank" hidden><i class="bi-star-fill me-1"></i> Subscribe</a>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"preinstall": "bundle update && bundle install",
"start": "npm run _start -- --skipImageMin='true' --skipESLint='true' --skipJSMin='true'",
"_start": "bundle exec gulp clean:jekyll && bundle exec gulp",
"dist": "git add . && git commit -m 'Published pages' && git push origin master",
"prototype": "npm start",
"prototype:public": "npm start -- --ngrokOpen='true'",
"prototype:https": "npm start -- --https='true'",
Expand Down
146 changes: 105 additions & 41 deletions special/master/pages/admin/users/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<th>Email</th>
<th>Active</th>
<th>Roles</th>
<th>Edit</th>
<th>Manage</th>
</tr>
</thead>

Expand Down Expand Up @@ -172,6 +172,23 @@ <h5 class="modal-title">Modal title</h5>
</div>
</div>

<div id="signin-as-modal" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Signin As</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form onsubmit="return false;">
<div class="modal-body" style="max-height: 80vh; overflow: scroll;">
<p>
You have signed in as this user. You can now navigate to the <a id="signin-as-modal-url" href="#" class="text-primary" target="_blank">account page</a> to view this user's account.
</p>
</form>
</div>
</div>
</div>

<script type="text/javascript">
var dataTemplate = `
<tr>
Expand Down Expand Up @@ -200,7 +217,7 @@ <h5 class="modal-title">Modal title</h5>
<td>
<div class="dropdown">
<a class="btn btn-white btn-sm dropdown-toggle dropdown-toggle-empty" href="#" role="button" id="dropdownMenuLink-{userUid}" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi-pencil me-2"></i> Edit
<i class="bi-pencil me-2"></i> Manage
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink-{userUid}">
Expand All @@ -209,6 +226,8 @@ <h5 class="modal-title">Modal title</h5>
<div class="dropdown-divider"></div>
<a class="dropdown-item user-premium-btn" href="javascript:;" data-uid="{userUid}"><i class="bi-star-fill me-2 pointer-none"></i>Give premium</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item user-signin-as-btn text-primary" href="javascript:;" data-uid="{userUid}"><i class="bi-key-fill me-2 pointer-none"></i>Sign in as</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item user-signout-btn text-danger" href="javascript:;" data-uid="{userUid}"><i class="bi-door-open-fill me-2 pointer-none"></i>Sign out all sessions</a>
</li>
</ul>
Expand All @@ -231,58 +250,43 @@ <h5 class="modal-title">Modal title</h5>

var $expandModal = document.getElementById('expand-modal');
var $premiumModal = document.getElementById('premium-modal');
var $signinAsModal = document.getElementById('signin-as-modal');
var expandModal = new bootstrap.Modal($expandModal, {});
var premiumModal = new bootstrap.Modal($premiumModal, {});
var signinAsModal = new bootstrap.Modal($signinAsModal, {});

// var serverDev = 'http://localhost:5001/' + Manager.properties.options.libraries.firebase_app.config.projectId + '/us-central1/bm_api';
var serverProd = 'https://us-central1-' + Manager.properties.options.libraries.firebase_app.config.projectId + '.cloudfunctions.net/bm_api';

table = Admin().initializeTable();

firebase.firestore().collection('apps')
.get()
.then(function(snapshot) {

snapshot
.forEach(function (val, i) {
var data = val.data();
appMap[data.id] = {
name: data.name,
brandmark: data.images.brandmark,
};
});

document.addEventListener('submit', function (event) {
if (event.target.matches('#datatable-search-form')) {
handleSearch(searchInput.value || '')
} else if (event.target.matches('#datatable-premium-form')) {
handlePremiumForm(event)
}
})

document.addEventListener('click', function (event) {
handleClick(event)
})

if (qsQuery) {
searchInput.value = qsQuery;
handleSearch(qsQuery)
} else {
Admin().display('ready');
}
document.addEventListener('submit', function (event) {
if (event.target.matches('#datatable-search-form')) {
handleSearch(searchInput.value || '')
} else if (event.target.matches('#datatable-premium-form')) {
handlePremiumForm(event)
}
})

if (Manager.properties.meta.environment === 'development') {
// handleSearch('100')
}
document.addEventListener('click', function (event) {
handleClick(event)
})

})
.catch(function(e) {
if (qsQuery) {
searchInput.value = qsQuery;
handleSearch(qsQuery)
} else {
Admin().display('ready');
}

})
if (Manager.properties.meta.environment === 'development') {
// handleSearch('100')
}

// HERE
function handleSearch(input) {
console.log('---search...', input);
console.log('Search...', input);

Admin().display('loading');

if (input.length < 3) {
Expand Down Expand Up @@ -366,7 +370,7 @@ <h5 class="modal-title">Modal title</h5>
.catch(function (e) {
Admin().display(e);
})
}
}

function handlePremiumForm(event) {
var uid = event.target.querySelector('input[name="uid"]').value;
Expand Down Expand Up @@ -426,6 +430,10 @@ <h5 class="modal-title">Modal title</h5>
var uid = event.target.dataset.uid;

handleSignOutAllSessions(uid);
} else if (event.target.matches('.user-signin-as-btn')) {
var uid = event.target.dataset.uid;

handleSignInAs(uid);
}
}

Expand Down Expand Up @@ -462,6 +470,62 @@ <h5 class="modal-title">Modal title</h5>
});
}

function handleSignInAs(uid) {
return new Promise(function (resolve, reject) {
var user = firebase.auth().currentUser;

console.log('handleSignInAs():', uid);

user.getIdToken(true)
.then(function (token) {
WonderfulFetch(serverProd, {
method: 'POST',
tries: 2,
timeout: 30000,
response: 'json',
body: {
authenticationToken: token,
command: 'user:create-custom-token',
payload: {
uid: uid,
}
},
})
.then(function (json) {
var url = new URL(window.location.href);
var destination = new URL(window.location.href);

// Set up the signout URL
url.pathname = '/signin';
url.searchParams.set('signout', true);
url.searchParams.set('token', json.token);

// Create a new URL object for the destination
destination.pathname = '/account';

// Set the destination parameter to the destination URL
url.searchParams.set('destination', destination.toString());

console.log('handleSignInAs(): Successfully created custom token for ' + uid, json);

signinAsModal.show();

document.getElementById('signin-as-modal-url').href = url.toString();

// Open the new URL in a new tab
window.open(url.toString(), '_blank');

return resolve(json);
})
.catch(function (e) {
console.error('handleSignInAs(): Error creating custom token for ' + uid, e);

return reject(e);
})
})
});
}

function runQuery(input) {
return new Promise(function(resolve, reject) {
var user = firebase.auth().currentUser;
Expand Down

0 comments on commit 78cd84d

Please sign in to comment.