I have Main Layout for an application which is called HomeComponent.vue
<template>
<v-app id="inspire" dark>
<v-navigation-drawer
v-model="drawer"
clipped
fixed
app
>
<v-list dense>
<v-list-tile>
<v-list-tile-action>
<v-icon>mdi-login</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<router-link to="/login">
<v-list-tile-title>Login</v-list-tile-title>
</router-link>
</v-list-tile-content>
</v-list-tile>
<v-list-tile>
<v-list-tile-action>
<v-icon>mdi-account-plus</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<router-link to="/register">
<v-list-tile-title>Register</v-list-tile-title>
</router-link>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-navigation-drawer>
<v-toolbar app fixed clipped-left>
<v-toolbar-side-icon @click.stop="drawer = !drawer"></v-toolbar-side-icon>
<v-toolbar-title>Logo</v-toolbar-title>
</v-toolbar>
<v-container fill-height>
<v-layout justify-center align-center>
<router-view></router-view>
</v-layout>
</v-container>
<v-footer app fixed class="justify-content-center">
<span>Logo © 2018.</span>
</v-footer>
</v-app>
</template>
<script>
export default {
mounted() {
console.log('Component mounted.')
},
data: () => ({
drawer: true
}),
props: {
source: String
}
}
</script>
In that layout I use router to change between Login and Register components.
This is the LoginComponent.vue
<template>
<v-content>
<v-container fluid fill-height>
<v-layout align-center justify-center>
<v-flex xs12 sm8 md6>
<v-alert
v-model="successAlert"
type="success"
>
This is a success alert.
</v-alert>
<v-card class="elevation-12">
<v-toolbar dark color="primary">
<v-toolbar-title>Login</v-toolbar-title>
</v-toolbar>
<v-card-text>
<v-form>
<v-text-field
prepend-icon="person"
v-model="username"
:rules="usernameRules"
label="Username"
type="text"></v-text-field>
<v-text-field
prepend-icon="lock"
v-model="password"
:rules="passwordRules"
label="Password"
type="password"></v-text-field>
</v-form>
</v-card-text>
<v-card-actions>
<router-link to="/forgot-password">
<a style="color: white;">Forgot your password?</a>
</router-link>
<v-spacer></v-spacer>
<v-btn color="primary">Login</v-btn>
</v-card-actions>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-content>
</template>
<script>
export default {
mounted: function () {
this.$session.start();
if (this.$session.exists('verified')){
console.log('Yes it exists');
this.$session.destroy();
this.showSuccessAlert();
}
},
data: () => ({
drawer: null,
successAlert: 0,
username: '',
usernameRules: [
v => !!v || 'Username is required'
],
password: '',
passwordRules: [
v => !!v || 'Password is required'
]
}),
props: {
source: String,
},
methods: {
showSuccessAlert() {
this.successAlert = 1;
}
}
}
</script>
In this Login Component I have alert which should be shown when there is 'verified' session which comes from UserController
This is the function from UserController
public function activateAccount($email, $token) {
$user = User::where('email', $email)->firstOrFail();
if($user->confirmation_token === $token) {
$user->mail_confirmed = 1;
$user->save();
return redirect('/login')->with('verified', 'Account successfully verified. You can log in now.');
}
}
And I have route in web.php for all of that.
Route::get('/activate/{email}/{token}', 'UserController@activateAccount');
I'm using Vuetify, material component framework.