feat(fe login): finished login
ToDo: add timezone at login
This commit is contained in:
parent
c84bc8b102
commit
03551436dc
1 changed files with 46 additions and 9 deletions
|
@ -2,28 +2,65 @@
|
|||
import {reactive} from 'vue';
|
||||
import axios from "axios";
|
||||
import {useAuthStore} from "@/stores/auth.store.ts";
|
||||
import {useRouter} from "vue-router";
|
||||
|
||||
const data = reactive({
|
||||
'form': false,
|
||||
'username': null,
|
||||
'password': null,
|
||||
loading: false,
|
||||
'loading': false,
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const onSubmit = () => {
|
||||
if (!data.form) return;
|
||||
if (!data.username || !data.password) return;
|
||||
|
||||
data.loading = true;
|
||||
|
||||
axios.post('/login', {
|
||||
username: data.username,
|
||||
password: data.password,
|
||||
// csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
||||
}).then((response) => {
|
||||
if (response.status === 200) {
|
||||
//const timezone = setTimezone(response.data.user);
|
||||
const auth = useAuthStore();
|
||||
auth.setUserData(response.data.user);
|
||||
const user = {
|
||||
user: response.data.user,
|
||||
password: data.password,
|
||||
//timezone: timezone
|
||||
}
|
||||
auth.setUserData(user);
|
||||
|
||||
//To check data uncomment the timezone const, the timezone line in user object
|
||||
// and the console.log below. Then comment router.push('/')
|
||||
|
||||
// console.log(auth.userData)
|
||||
|
||||
router.push('/');
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log('Error: '+error);
|
||||
});
|
||||
data.loading = true;
|
||||
setTimeout(() => (data.loading = false), 2000);
|
||||
}
|
||||
|
||||
const setTimezone = async (user): string => {
|
||||
return await axios.get("http://localhost:8080/api/v2/preferences", {
|
||||
auth: {
|
||||
username: user.login,
|
||||
password: data.password
|
||||
}
|
||||
}).then(res => {
|
||||
res.data.forEach(item => {
|
||||
if (item.keystr === 'user_timezone' && item.subjid === user.id) {
|
||||
return item.valstr;
|
||||
}
|
||||
return import.meta.env.VITE_APP_TIMEZONE;
|
||||
})
|
||||
}).catch(error => {
|
||||
console.log("Error: "+error);
|
||||
return null;
|
||||
})
|
||||
}
|
||||
|
||||
const required = (v) => {
|
||||
|
@ -57,9 +94,9 @@ const required = (v) => {
|
|||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn
|
||||
:disabled="!data.form"
|
||||
:loading="loading"
|
||||
color="success"
|
||||
:disabled="!data.username || !data.password"
|
||||
:loading="data.loading"
|
||||
color="primary"
|
||||
size="large"
|
||||
type="submit"
|
||||
variant="elevated"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue