Skip to content

Commit e8a94af

Browse files
committed
Port password settings to vue
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent d7deeb4 commit e8a94af

15 files changed

Lines changed: 187 additions & 73 deletions

apps/settings/lib/Controller/ChangePasswordController.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,16 @@
4949
use OCP\IUserSession;
5050

5151
class ChangePasswordController extends Controller {
52-
53-
/** @var string */
54-
private $userId;
55-
56-
/** @var IUserManager */
57-
private $userManager;
58-
59-
/** @var IL10N */
60-
private $l;
61-
62-
/** @var GroupManager */
63-
private $groupManager;
64-
65-
/** @var Session */
66-
private $userSession;
67-
68-
/** @var IAppManager */
69-
private $appManager;
52+
private ?string $userId;
53+
private IUserManager $userManager;
54+
private IL10N $l;
55+
private GroupManager $groupManager;
56+
private Session $userSession;
57+
private IAppManager $appManager;
7058

7159
public function __construct(string $appName,
7260
IRequest $request,
73-
string $userId,
61+
?string $userId,
7462
IUserManager $userManager,
7563
IUserSession $userSession,
7664
IGroupManager $groupManager,
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!--
2+
- @copyright 2022 Carl Schwan <carl@carlschwan.eu>
3+
-
4+
- @license GNU AGPL version 3 or any later version
5+
-
6+
- This program is free software: you can redistribute it and/or modify
7+
- it under the terms of the GNU Affero General Public License as
8+
- published by the Free Software Foundation, either version 3 of the
9+
- License, or (at your option) any later version.
10+
-
11+
- This program is distributed in the hope that it will be useful,
12+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
- GNU Affero General Public License for more details.
15+
-
16+
- You should have received a copy of the GNU Affero General Public License
17+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
-->
19+
<template>
20+
<NcSettingsSection :title="t('settings', 'Password')">
21+
<form id="passwordform" method="POST" @submit.prevent="changePassword">
22+
<NcPasswordField id="old-pass"
23+
:label="t('settings', 'Current password')"
24+
:label-visible="true"
25+
name="oldpassword"
26+
:value.sync="oldPass"
27+
autocomplete="current-password"
28+
autocapitalize="none"
29+
autocorrect="off" />
30+
31+
<NcPasswordField id="new-pass"
32+
:label="t('settings', 'New password')"
33+
:label-visible="true"
34+
:value.sync="newPass"
35+
:maxlength="469"
36+
autocomplete="new-password"
37+
:check-password-strength="true"
38+
autocapitalize="none"
39+
autocorrect="off"
40+
:check-password-strength="true" />
41+
42+
<NcButton type="primary"
43+
native-type="submit"
44+
:disabled="newPass.length === 0 || oldPass.length === 0">
45+
{{ t('settings', 'Change password') }}
46+
</NcButton>
47+
</form>
48+
</NcSettingsSection>
49+
</template>
50+
51+
<script>
52+
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
53+
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
54+
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
55+
import axios from '@nextcloud/axios'
56+
import { generateUrl } from '@nextcloud/router'
57+
import { showSuccess, showError } from '@nextcloud/dialogs'
58+
59+
export default {
60+
name: 'PasswordSection',
61+
components: {
62+
NcSettingsSection,
63+
NcButton,
64+
NcPasswordField,
65+
},
66+
data() {
67+
return {
68+
oldPass: '',
69+
newPass: '',
70+
}
71+
},
72+
methods: {
73+
changePassword() {
74+
axios.post(generateUrl('/settings/personal/changepassword'), {
75+
oldpassword: this.oldPass,
76+
newpassword: this.newPass,
77+
})
78+
.then(res => res.data)
79+
.then(data => {
80+
if (data.status === 'error') {
81+
this.errorMessage = data.data.message
82+
showError(data.data.message)
83+
} else {
84+
showSuccess(data.data.message)
85+
}
86+
})
87+
},
88+
},
89+
}
90+
</script>
91+
92+
<style>
93+
#passwordform {
94+
display: flex;
95+
flex-direction: column;
96+
gap: 1rem;
97+
max-width: 400px;
98+
}
99+
</style>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @copyright 2022 Carl Schwan <carl@carlschwan.eu>
3+
*
4+
* @license AGPL-3.0-or-later
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
*/
20+
21+
import Vue from 'vue'
22+
23+
import PasswordSection from './components/PasswordSection.vue'
24+
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
25+
26+
// eslint-disable-next-line camelcase
27+
__webpack_nonce__ = btoa(OC.requestToken)
28+
29+
Vue.prototype.t = t
30+
Vue.prototype.n = n
31+
32+
export default new Vue({
33+
el: '#security-password',
34+
name: 'main-personal-password',
35+
render: h => h(PasswordSection),
36+
})

0 commit comments

Comments
 (0)