Skip to content

Commit 6c18900

Browse files
Merge pull request #14 from kingscode/implement-laravel-api-starter-2.0
KCI-28 implement-laravel-api-starter-2.0
2 parents ba85587 + b5391c1 commit 6c18900

34 files changed

Lines changed: 592 additions & 583 deletions

generator/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = (api, options) => {
55
api.extendPackage({
66
dependencies: {
77
'axios': '^0.18.0',
8-
'vuex': '^3.1.0',
8+
"dayjs": "^1.8.19",
9+
'vuex': '^3.1.2',
910
'vuex-persistedstate': '^2.5.4',
1011
'lodash.clonedeep': '^4.5.0',
1112
'css-vars-ponyfill': '^2.1.2',
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import API from './../../API.js';
2+
import handleTooManyRequestsError from '../utils/handleTooManyRequestsError.js';
3+
4+
export default async function (email, password) {
5+
const result = await API.post('auth/login', {
6+
email, password,
7+
}).catch((error) => {
8+
return error.response;
9+
});
10+
11+
if (result.status === 200) {
12+
return {
13+
success: true,
14+
token: result.data.data.token,
15+
};
16+
}
17+
18+
if (result.status === 429) {
19+
return handleTooManyRequestsError(result);
20+
}
21+
22+
return {
23+
message: 'De ingevulde gegevens zijn niet juist.',
24+
success: false,
25+
};
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import API from './../../API.js';
2+
3+
export default async function () {
4+
await API.post('auth/logout').catch((error) => {
5+
return error.response;
6+
});
7+
return {
8+
success: true,
9+
};
10+
}
11+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import API from './../../API.js';
2+
import handleTooManyRequestsError from '../utils/handleTooManyRequestsError.js';
3+
4+
export default async function (email, name) {
5+
const result = await API.post('registration', {
6+
email, name,
7+
}).catch((error) => {
8+
return error.response;
9+
});
10+
11+
if (result.status === 201) {
12+
return {
13+
success: true,
14+
message: 'Er is een account aangemaakt, controleer je e-mail om een wachtwoord te kiezen zodat je vervolgens kunt inloggen.',
15+
};
16+
}
17+
18+
if (result.status === 429) {
19+
return handleTooManyRequestsError(result);
20+
}
21+
22+
return {
23+
message: `De ingevulde gegevens kloppen niet.`,
24+
success: false,
25+
};
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import API from './../../API.js';
2+
import handleTooManyRequestsError from '../utils/handleTooManyRequestsError.js';
3+
4+
export default async function (email) {
5+
const result = await API.post('password/forgotten', {
6+
email,
7+
}).catch((error) => {
8+
return error.response;
9+
});
10+
11+
if (result.status === 200) {
12+
return {
13+
success: true,
14+
message: 'Er is een wachtwoord vergeten mail verstuurd mits er een account bestaat met het gegeven email adres.',
15+
};
16+
}
17+
18+
if (result.status === 429) {
19+
return handleTooManyRequestsError(result);
20+
}
21+
22+
return {
23+
message: 'De ingevulde gegevens kloppen niet.',
24+
success: false,
25+
};
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import API from './../../API.js';
2+
import handleTooManyRequestsError from '../utils/handleTooManyRequestsError.js';
3+
4+
export default async function (email, token, password, passwordConfirmation) {
5+
const result = await API.post('registration', {
6+
email,
7+
token,
8+
password,
9+
password_confirmation: passwordConfirmation
10+
}).catch((error) => error.response);
11+
12+
if (result.status === 200) {
13+
return {
14+
success: true,
15+
message: 'Uw wachtwoord is opnieuw ingesteld.',
16+
};
17+
}
18+
19+
if (result.status === 400) {
20+
return {
21+
success: false,
22+
message: 'De ingegeven token is verlopen.',
23+
}
24+
}
25+
26+
if (result.status === 429) {
27+
return handleTooManyRequestsError(result);
28+
}
29+
30+
return {
31+
message: 'De ingevulde gegevens kloppen niet.',
32+
success: false,
33+
};
34+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<template>
2+
<v-card height="100%">
3+
<v-form @submit.prevent="handleLogin()" ref="form" v-model="valid">
4+
<v-card-title class="title">Ik wil inloggen</v-card-title>
5+
<v-card-text>
6+
<v-alert
7+
:value="errorMessage !== null"
8+
class="mb-10"
9+
transition="fade-transition"
10+
type="error"
11+
>
12+
{{errorMessage}}
13+
</v-alert>
14+
<VTextField
15+
:rules="[(v) => !!v || 'E-Mail is verplicht']"
16+
label="E-Mail"
17+
v-model="form.email"
18+
tabindex="1"
19+
/>
20+
<VTextField
21+
:append-icon="showPassword ? 'fa-eye-slash' : 'fa-eye'"
22+
:rules="[(v) => !!v || 'Wachtwoord is verplicht']"
23+
:type="showPassword ? 'text' : 'password'"
24+
@click:append="showPassword = !showPassword"
25+
label="Wachtwoord"
26+
v-model="form.password"
27+
tabindex="2"
28+
/>
29+
</v-card-text>
30+
<v-card-actions>
31+
<VSpacer/>
32+
<v-btn :to="{name: 'password.forgotten'}" tabindex="4" color="primary" text>Wachtwoord vergeten</v-btn>
33+
<v-btn tabindex="3" type="submit" color="primary" :loading="isLoading">Inloggen</v-btn>
34+
</v-card-actions>
35+
</v-form>
36+
37+
<v-overlay v-model="isRedirecting" class="text-center">
38+
<VProgressCircular indeterminate size="64"/>
39+
<div class="mt-5">Je bent ingelogd, we sturen je nu door.</div>
40+
</v-overlay>
41+
</v-card>
42+
</template>
43+
44+
<script>
45+
import loginRequest from './../../api/authorisation/login';
46+
47+
export default {
48+
name: 'LoginCard',
49+
data() {
50+
return {
51+
errorMessage: null,
52+
isLoading: false,
53+
showPassword: false,
54+
valid: null,
55+
form: {
56+
email: '',
57+
password: '',
58+
},
59+
isRedirecting: false,
60+
};
61+
},
62+
methods: {
63+
async handleLogin() {
64+
this.$refs.form.validate();
65+
if (!this.valid) {
66+
return;
67+
}
68+
this.isLoading = true;
69+
const {success, message, token} = await loginRequest(this.form.email, this.form.password);
70+
71+
this.isLoading = false;
72+
73+
if (success) {
74+
this.isRedirecting = true;
75+
return this.redirectToAuthDispense(token);
76+
}
77+
78+
this.errorMessage = message;
79+
},
80+
redirectToAuthDispense(token) {
81+
const form = document.createElement("form");
82+
83+
form.method = 'POST';
84+
form.action = process.env.VUE_APP_ROOT_API + '/auth/dispense';
85+
86+
const redirectUriElement = document.createElement("input");
87+
redirectUriElement.name = 'redirect_uri';
88+
redirectUriElement.value= 'home';
89+
form.appendChild(redirectUriElement);
90+
91+
const emailElement = document.createElement("input");
92+
emailElement.name = 'email';
93+
emailElement.value= this.form.email;
94+
form.appendChild(emailElement);
95+
96+
const tokenElement = document.createElement("input");
97+
tokenElement.name = 'token';
98+
tokenElement.value= token;
99+
form.appendChild(tokenElement);
100+
101+
document.body.appendChild(form);
102+
form.submit();
103+
}
104+
},
105+
};
106+
</script>
107+
108+
<style scoped>
109+
110+
</style>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<template>
2+
<v-card height="100%">
3+
<v-form @submit.prevent="handleRegister()" ref="form" v-model="valid">
4+
<v-card-title class="title">Ik wil een account aanvragen</v-card-title>
5+
<v-card-text>
6+
<v-alert
7+
:value="alertMessage !== null"
8+
class="mb-10"
9+
transition="fade-transition"
10+
:type="alertType"
11+
>
12+
{{alertMessage}}
13+
</v-alert>
14+
<VTextField
15+
:rules="[(v) => !!v || 'E-Mail is verplicht']"
16+
label="E-Mail"
17+
v-model="form.email"
18+
tabindex="11"
19+
/>
20+
</v-card-text>
21+
<v-card-actions>
22+
<VSpacer/>
23+
<v-btn tabindex="12" type="submit" color="primary" :loading="isLoading">Wachtwoord aanvragen</v-btn>
24+
</v-card-actions>
25+
</v-form>
26+
</v-card>
27+
</template>
28+
29+
<script>
30+
import forgottenRequest from '../../api/password/forgotten.js';
31+
32+
export default {
33+
name: 'PasswordForgottenCard',
34+
data() {
35+
return {
36+
alertType: 'info',
37+
alertMessage: null,
38+
isLoading: false,
39+
valid: null,
40+
form: {
41+
email: '',
42+
},
43+
};
44+
},
45+
methods: {
46+
async handleRegister() {
47+
this.$refs.form.validate();
48+
if (!this.valid) {
49+
return;
50+
}
51+
this.isLoading = true;
52+
const {success, message} = await forgottenRequest(this.form.email);
53+
this.alertType = success ? 'success' : 'error';
54+
this.alertMessage = message;
55+
this.isLoading = false;
56+
},
57+
},
58+
};
59+
</script>
60+
61+
<style scoped>
62+
63+
</style>

0 commit comments

Comments
 (0)