Skip to content

Commit a59e61a

Browse files
committed
allow to set a personal token even if oauth is possible
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 9086503 commit a59e61a

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

lib/Controller/ConfigController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function setConfig(array $values): DataResponse {
8989
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'user_displayname');
9090
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'token_type');
9191
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'token');
92+
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'redirect_uri');
9293
$result['user_name'] = '';
9394
}
9495
// connect or disconnect: invalidate the user-related cache

src/components/PersonalSettings.vue

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
<GithubIcon class="icon" />
99
{{ t('integration_github', 'GitHub integration') }}
1010
</h2>
11-
<p v-if="!showOAuth && !connected" class="settings-hint">
12-
{{ t('integration_github', 'When you create a personal access token yourself, give it at least "read:user", "user:email" and "notifications" permissions.') }}
13-
<a href="https://github.com/settings/tokens" target="_blank" class="external">
14-
<span class="icon icon-external" />
15-
{{ t('integration_github', 'GitHub personal access tokens') }}
16-
</a>
17-
</p>
1811
<div id="github-content">
1912
<NcCheckboxRadioSwitch
2013
:checked="state.navigation_enabled"
@@ -26,30 +19,50 @@
2619
@update:checked="onCheckboxChanged($event, 'link_preview_enabled')">
2720
{{ t('integration_github', 'Enable GitHub link previews') }}
2821
</NcCheckboxRadioSwitch>
29-
<div v-show="!showOAuth"
30-
class="line">
31-
<label for="github-token">
32-
<KeyIcon :size="20" class="icon" />
33-
{{ t('integration_github', 'Personal access token') }}
34-
</label>
35-
<input id="github-token"
36-
v-model="state.token"
22+
<NcNoteCard v-if="showOAuth && !connected" type="info">
23+
{{ t('integration_github', 'You can manually provide a personal access token or connect via OAuth ') }}
24+
</NcNoteCard>
25+
<NcNoteCard v-if="!connected" type="info">
26+
{{ t('integration_github', 'When you create a personal access token yourself, give it at least "read:user", "user:email" and "notifications" permissions.') }}
27+
<a href="https://github.com/settings/tokens" target="_blank" class="external">
28+
<span class="icon icon-external" />
29+
{{ t('integration_github', 'GitHub personal access tokens') }}
30+
</a>
31+
</NcNoteCard>
32+
<div v-if="!connected" class="line">
33+
<NcTextField
34+
id="github-token"
35+
class="input"
36+
:value.sync="state.token"
3737
type="password"
38-
:disabled="connected === true"
39-
:placeholder="t('integration_github', 'GitHub personal access token')"
40-
@keyup.enter="onConnectClick"
41-
@focus="readonly = false">
38+
:label="t('integration_github', 'Personal access token')"
39+
placeholder="..."
40+
:show-trailing-button="!!state.token"
41+
@keyup.enter="connectWithToken"
42+
@trailing-button-click="state.token = ''">
43+
<KeyIcon />
44+
</NcTextField>
45+
<NcButton v-if="!connected"
46+
:disabled="loading || state.token === ''"
47+
:class="{ loading }"
48+
@click="connectWithToken">
49+
<template #icon>
50+
<OpenInNewIcon :size="20" />
51+
</template>
52+
{{ t('integration_github', 'Connect to GitHub with a personal token') }}
53+
</NcButton>
4254
</div>
43-
<NcButton v-if="!connected"
55+
<NcButton v-if="showOAuth && !connected"
4456
:disabled="loading === true || (!showOAuth && !state.token)"
45-
:class="{ loading }"
46-
@click="onConnectClick">
57+
:class="{ loading, connectButton: true }"
58+
@click="connectWithOauth">
4759
<template #icon>
4860
<OpenInNewIcon :size="20" />
4961
</template>
50-
{{ t('integration_github', 'Connect to GitHub') }}
62+
{{ t('integration_github', 'Connect to GitHub with OAuth') }}
5163
</NcButton>
52-
<div v-if="connected" class="line">
64+
<br>
65+
<div v-if="connected" class="column">
5366
<label>
5467
<CheckIcon :size="20" class="icon" />
5568
{{ t('integration_github', 'Connected as {user}', { user: connectedAs }) }}
@@ -60,7 +73,6 @@
6073
</template>
6174
{{ t('integration_github', 'Disconnect from GitHub') }}
6275
</NcButton>
63-
<span />
6476
</div>
6577
<br>
6678
<div v-if="connected" id="github-search-block">
@@ -95,6 +107,8 @@ import GithubIcon from './icons/GithubIcon.vue'
95107
96108
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
97109
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
110+
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
111+
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
98112
99113
import { loadState } from '@nextcloud/initial-state'
100114
import { generateUrl } from '@nextcloud/router'
@@ -109,6 +123,8 @@ export default {
109123
GithubIcon,
110124
NcCheckboxRadioSwitch,
111125
NcButton,
126+
NcNoteCard,
127+
NcTextField,
112128
KeyIcon,
113129
CheckIcon,
114130
CloseIcon,
@@ -187,13 +203,6 @@ export default {
187203
this.loading = false
188204
})
189205
},
190-
onConnectClick() {
191-
if (this.showOAuth) {
192-
this.connectWithOauth()
193-
} else {
194-
this.connectWithToken()
195-
}
196-
},
197206
connectWithToken() {
198207
this.loading = true
199208
this.saveOptions({
@@ -236,14 +245,32 @@ export default {
236245
}
237246
238247
.line {
248+
display: flex;
249+
align-items: center;
250+
gap: 4px;
239251
> label {
240252
width: 300px;
241253
display: flex;
242254
align-items: center;
243255
}
244-
> input {
256+
> input, > .input {
245257
width: 250px;
258+
margin: 0;
246259
}
247260
}
261+
262+
.column {
263+
display: flex;
264+
flex-direction: column;
265+
gap: 8px;
266+
label {
267+
display: flex;
268+
align-items: center;
269+
}
270+
}
271+
272+
.connectButton {
273+
margin-top: 12px;
274+
}
248275
}
249276
</style>

0 commit comments

Comments
 (0)