Skip to content

Commit 3e9bfaa

Browse files
committed
F2a update
1 parent 771cf1f commit 3e9bfaa

File tree

4 files changed

+60
-55
lines changed

4 files changed

+60
-55
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/atomjoy/auth/stores/auth.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ export const useAuthStore = defineStore('auth', () => {
8484
}
8585
}
8686

87+
async function enableF2a(data) {
88+
try {
89+
let res = await axios.post('/web/api/f2a/enable', data)
90+
setMessage(res)
91+
user.value.f2a = 1
92+
} catch (err) {
93+
setError(err)
94+
logError(err)
95+
}
96+
}
97+
98+
async function disableF2a(data) {
99+
try {
100+
let res = await axios.post('/web/api/f2a/disable', data)
101+
setMessage(res)
102+
user.value.f2a = 0
103+
} catch (err) {
104+
setError(err)
105+
logError(err)
106+
}
107+
}
108+
87109
async function logoutUser() {
88110
try {
89111
await axios.get('/web/api/logout')
@@ -272,5 +294,7 @@ export const useAuthStore = defineStore('auth', () => {
272294
getMessage,
273295
getError,
274296
getUser,
297+
enableF2a,
298+
disableF2a,
275299
}
276300
})

resources/js/atomjoy/panel/client/css/page-scoped.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,22 @@ form {
55
padding-bottom: 30px;
66
border-bottom: 1px dashed var(--divider-primary);
77
}
8+
9+
.f2a-enabled {
10+
float: left;
11+
width: 100%;
12+
color: #5c5;
13+
border: 1px solid #5c5;
14+
font-weight: 900;
15+
padding: 15px 20px;
16+
border-radius: 10px;
17+
}
18+
.f2a-disabled {
19+
float: left;
20+
width: 100%;
21+
color: #f23;
22+
border: 1px solid #f23;
23+
font-weight: 900;
24+
padding: 15px 20px;
25+
border-radius: 10px;
26+
}
Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
11
<script setup>
22
import Input from '@/components/input/Input.vue'
33
import Button from '@/components/input/Button.vue'
4+
import Password from '@/components/input/Password.vue'
45
import TitleH1 from '@/atomjoy/panel/client/components/Titles/TitleH1.vue'
56
import TitleH2 from '@/atomjoy/panel/client/components/Titles/TitleH2.vue'
67
import ErrorMessage from '@/atomjoy/panel/client/components/Error/ErrorMessage.vue'
78
import { useAuthStore } from '@/atomjoy/auth/stores/auth.js'
8-
import { onBeforeMount } from 'vue'
9-
import axios from 'axios'
9+
import { onBeforeMount, ref } from 'vue'
1010
1111
const auth = useAuthStore()
12-
const user = auth.getUser
12+
let user = auth.getUser
13+
let password_current = ref('')
1314
1415
onBeforeMount(() => {
1516
auth.clearError()
1617
})
1718
18-
async function enable() {
19-
const { data } = await axios.get('/web/api/f2a/enable')
20-
return data
21-
}
22-
23-
async function disable() {
24-
const { data } = await axios.get('/web/api/f2a/disable')
25-
return data
26-
}
27-
2819
function onSubmitEmail(e) {
2920
auth.scrollTop()
3021
auth.changeUserEmail(new FormData(e.target))
3122
}
3223
3324
function onSubmitF2a(e) {
34-
try {
35-
console.log(user.value.f2a)
25+
auth.scrollTop()
3626
37-
if (user.value.f2a == 1) {
38-
// Disable
39-
disable().then((res) => {
40-
user.value.f2a == 0
41-
document.location.reload()
42-
})
43-
} else {
44-
// Enable
45-
enable().then((res) => {
46-
user.value.f2a == 1
47-
document.location.reload()
48-
})
49-
}
50-
} catch (e) {
51-
console.log(e)
27+
if (user.value.f2a == 1) {
28+
auth.disableF2a(new FormData(e.target))
29+
} else {
30+
auth.enableF2a(new FormData(e.target))
5231
}
5332
}
5433
</script>
@@ -68,7 +47,8 @@ function onSubmitF2a(e) {
6847
<TitleH2 :title="$t('Two factor authentication')" />
6948
<div v-if="user.f2a == 1" class="f2a-enabled">{{ $t('Enabled') }}</div>
7049
<div v-if="user.f2a == 0" class="f2a-disabled">{{ $t('Disabled') }}</div>
71-
<Button :text="$t('Change')" />
50+
<Password name="password_current" :label="$t('Current password')" v-model="password_current" />
51+
<Button :text="$t('Update')" />
7252
</form>
7353
</template>
7454

@@ -78,22 +58,4 @@ function onSubmitF2a(e) {
7858

7959
<style scoped>
8060
@import url('../../css/page-scoped.css');
81-
.f2a-enabled {
82-
float: left;
83-
width: 100%;
84-
color: #fff;
85-
background: #55cc55;
86-
font-weight: 900;
87-
padding: 15px 20px;
88-
border-radius: 10px;
89-
}
90-
.f2a-disabled {
91-
float: left;
92-
width: 100%;
93-
color: #fff;
94-
background: #ff2200;
95-
font-weight: 900;
96-
padding: 15px 20px;
97-
border-radius: 10px;
98-
}
9961
</style>

0 commit comments

Comments
 (0)