1
0
mirror of https://github.com/beestat/app.git synced 2025-05-24 02:14:03 -04:00

Fixed #367 - Cannot unlink Patreon account after linking

This commit is contained in:
Jon Ziebell 2022-09-19 17:33:24 -04:00
parent 8d828030cf
commit 3130905852
4 changed files with 74 additions and 11 deletions

View File

@ -42,17 +42,25 @@ class patreon_token extends cora\crud {
$new_patreon_token = [
'access_token' => $response['access_token'],
'refresh_token' => $response['refresh_token']
'refresh_token' => $response['refresh_token'],
'deleted' => false
];
$existing_patreon_tokens = $this->read();
if(count($existing_patreon_tokens) > 0) {
$new_patreon_token['patreon_token_id'] = $existing_patreon_tokens[0]['patreon_token_id'];
$this->update(
/**
* Look for existing tokens (in case access was revoked and then
* re-granted). Include deleted tokens and revive that row since each user
* is limited to one token row.
*/
$existing_patreon_token = $this->read([
'deleted' => [0, 1]
]);
if (count($existing_patreon_token) > 0) {
$this->update(array_merge(
['patreon_token_id' => $existing_patreon_token[0]['patreon_token_id']],
$new_patreon_token
);
}
else {
));
} else {
$this->create($new_patreon_token);
}

View File

@ -13,7 +13,8 @@ class user extends cora\crud {
'read_id',
'update_setting',
'log_out',
'sync_patreon_status'
'sync_patreon_status',
'unlink_patreon_account',
],
'public' => []
];
@ -345,4 +346,27 @@ class user extends cora\crud {
$this->database->release_lock($lock_name);
}
/**
* Unlink the Patreon account for the current user.
*/
public function unlink_patreon_account() {
$patreon_tokens = $this->api('patreon_token', 'read_id');
foreach($patreon_tokens as $patreon_token) {
$this->api(
'patreon_token',
'delete',
[
'id' => $patreon_token['patreon_token_id']
]
);
}
$this->update(
[
'user_id' => $this->session->get_user_id(),
'patreon_status' => null
]
);
}
}

View File

@ -480,6 +480,7 @@ input[type=range]::-moz-range-thumb {
.icon.label:before { content: "\F0315"; }
.icon.layers:before { content: "\F0328"; }
.icon.layers_plus:before { content: "\F0E4D"; }
.icon.link_off:before { content: "\F0338"; }
.icon.magnify_close:before { content: "\F0980"; }
.icon.magnify_minus_outline:before { content: "\F06EC"; }
.icon.magnify_plus_outline:before { content: "\F06ED"; }

View File

@ -199,7 +199,34 @@ beestat.component.modal.patreon_status.prototype.get_title_ = function() {
*/
beestat.component.modal.patreon_status.prototype.get_buttons_ = function() {
if (beestat.user.patreon_is_connected() === true) {
var refresh = new beestat.component.tile()
const unlink = new beestat.component.tile()
.set_text('Unlink')
.set_icon('link_off')
.set_shadow(false)
.set_background_color('#fff')
.set_text_color(beestat.style.color.gray.base)
.set_text_hover_color(beestat.style.color.red.base)
.addEventListener('click', function() {
this
.removeEventListener('click');
new beestat.api()
.add_call(
'user',
'unlink_patreon_account',
{},
'unlink_patreon_account'
)
.add_call('user', 'read_id', {}, 'user')
.set_callback(function(response) {
// Update the cache.
self.dispose();
beestat.cache.set('user', response.user);
})
.send();
});
const refresh = new beestat.component.tile()
.set_text('Refresh Status')
.set_icon('refresh')
.set_background_color(beestat.style.color.green.base)
@ -226,7 +253,10 @@ beestat.component.modal.patreon_status.prototype.get_buttons_ = function() {
.send();
});
return [refresh];
return [
unlink,
refresh
];
}
return [];