Просмотр исходного кода

Fetch user information from the server

tags/v0.1.0
Immanuel Onyeka 3 лет назад
Родитель
Сommit
046daa0b60
5 измененных файлов: 51 добавлений и 8 удалений
  1. +4
    -0
      app/Http/Controllers/UserController.php
  2. +9
    -0
      database/seeders/DatabaseSeeder.php
  3. +29
    -0
      resources/js/main.js
  4. +4
    -7
      resources/js/panel/panel.vue
  5. +5
    -1
      routes/web.php

+ 4
- 0
app/Http/Controllers/UserController.php Просмотреть файл

@@ -79,4 +79,8 @@ class UserController extends Controller
return redirect('/');
}

public function getOrders(Request $request) {

}

}

+ 9
- 0
database/seeders/DatabaseSeeder.php Просмотреть файл

@@ -26,9 +26,18 @@ class DatabaseSeeder extends Seeder
'name' => 'test_user_verified',
'email' => 'verified@example.com',
'email_verified_at' => now(),
'credits' => 250,
'role' => 'client',
'active' => true,
'password' => Hash::make("test123")
]);
User::create([
'name' => 'test_admin_verified',
'email' => 'admin_verified@example.com',
'email_verified_at' => now(),
'role' => 'admin',
'active' => true,
'password' => Hash::make("test123")
]);
}
}

+ 29
- 0
resources/js/main.js Просмотреть файл

@@ -50,6 +50,34 @@ function login(event) {
event.stopPropogation()
}

function getUser(app) {
fetch("/panel/user", {
method: 'GET',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': token},
}).then(response => {
return response.json()
}).then(data => {
app.user = data
})
/* return this.user.name */
}

function getOrders(app) {
fetch("/panel/orders", {
method: 'GET',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': token},
}).then(response => {
return response.json()
}).then(data => {
app.orders = data
})
/* return this.user.name */
}

//Attempt to resend the verification link
function resendLink(event) {
fetch("/resend-verification", {
@@ -113,5 +141,6 @@ if (window.location.pathname == '/') {
if (!token) {getToken(app)}
const app = createApp(Panel).mount('#panel')
window.onhashchange = ()=>{app.active = location.hash}
getUser(app)
}


+ 4
- 7
resources/js/panel/panel.vue Просмотреть файл

@@ -2,8 +2,8 @@
<sidebar :active="active"></sidebar>
<transition name="fade" mode="out-in">
<div v-if="active === ''" id="main">
<section class="welcome-pane"><h3>Welcome, user!</h3></section>
<section class="credits-pane"><img src="../../images/wallet2.svg" alt="wallet" class="icon"/><p>Credits: ${{credits}}</p></section>
<section class="welcome-pane"><h3>Welcome, {{user.name}}!</h3></section>
<section class="credits-pane"><img src="../../images/wallet2.svg" alt="wallet" class="icon"/><p>Credits: ${{user.credits}}</p></section>
<section class="alerts-pane"><h4>News and Announcements</h4>
<p>We've just launched. Thanks for joining us.</p>
</section>
@@ -21,15 +21,12 @@
<script>
import Sidebar from './sidebar.vue'

/* let token = RegExp('XSRF-TOKEN=([^;]+)').exec(document.cookie) */
/* console.log(token) */

export default {
components: {
Sidebar,
},
data() {
return {active: window.location.hash, credits: 0, }
},
return {active: window.location.hash, user: '',
token: ''}},
}
</script>

+ 5
- 1
routes/web.php Просмотреть файл

@@ -57,4 +57,8 @@ Route::post('/login', [UserController::class,

Route::get('/panel/user', function (Request $request) {
return $request->user();
});
})->middleware('auth');

Route::post('/panel/orders', [UserController::class,
'getOrders'])->middleware('auth');


Загрузка…
Отмена
Сохранить