-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logout, change profile information, change password, unique usernames
- Loading branch information
Showing
6 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Models\Track; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UserController extends Controller | ||
{ | ||
public function me(){ | ||
if (!Auth::check()){ | ||
abort(403); | ||
} | ||
return Auth::user(); | ||
} | ||
|
||
public function update(User $user, Request $request){ | ||
if (!Auth::check()){ | ||
abort(403); | ||
} | ||
if(Auth::user()->username != $user->username){ | ||
abort(403); | ||
} | ||
$user->username = $request->username; | ||
$user->email = $request->email; | ||
$user->save(); | ||
return $user; | ||
} | ||
public function updatePassword(User $user, Request $request){ | ||
if (!Auth::check()){ | ||
abort(403); | ||
} | ||
if(Auth::user()->username != $user->username){ | ||
abort(403); | ||
} | ||
$user->makeVisible(['password']); | ||
if (Hash::check($request->oldPassword, $user->password)) { | ||
$user->password = Hash::make($request->newPassword); | ||
$user->save(); | ||
return $user; | ||
} else { | ||
abort(406); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,100 @@ | ||
<script setup> | ||
import { generateKeypair } from "../../lib/crypto" | ||
import { ref } from "vue"; | ||
import { client, user, setLogin } from "../../lib/api"; | ||
import Button from "primevue/button"; | ||
const onGenerateKeypair = async () => { | ||
console.log(await generateKeypair()) | ||
import InputText from "primevue/inputtext"; | ||
const me = ref([]) | ||
const loading = ref(false); | ||
const email = ref("") | ||
const username = ref("") | ||
const oldPassword = ref("") | ||
const newPassword = ref("") | ||
const loadUser = async () => { | ||
try { | ||
const response = await client.get('user') | ||
me.value = response.data | ||
email.value = me.value.email | ||
username.value = me.value.username | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
const onSubmitProfileData = async () => { | ||
loading.value = true; | ||
try { | ||
const response = await client.post(`user/${me.value.id}`, { | ||
email: email.value, | ||
username: username.value | ||
}) | ||
if (response.status === 200) { | ||
me.value = response.data | ||
setLogin(me.value) | ||
alert('Speichern war erfolgreich') | ||
} else { | ||
alert('Speichern war nicht erfolgreich') | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} finally { | ||
loading.value = false; | ||
} | ||
} | ||
const onSubmitChangePassword = async () => { | ||
loading.value = true; | ||
try { | ||
const response = await client.post(`user/${me.value.id}/password`, { | ||
oldPassword: oldPassword.value, | ||
newPassword: newPassword.value | ||
}) | ||
if (response.status === 200) { | ||
alert('Passwort wurde geändert') | ||
} else { | ||
alert('Passwort konnte nicht geändert werden') | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} finally { | ||
loading.value = false; | ||
} | ||
} | ||
loadUser() | ||
</script> | ||
<template> | ||
<h1>Profil Verwalten</h1> | ||
<form @submit.prevent="onSubmitProfileData"> | ||
<div class="field"> | ||
<label>E-Mail-Adresse</label> | ||
<InputText class="w-full" v-model="email" type="email" required /> | ||
</div> | ||
<div class="field"> | ||
<label>Benutzer (andere Benutzer aus dem selben Track können diesen sehen)</label> | ||
<InputText class="w-full" v-model="username" type="text" required /> | ||
</div> | ||
<Button :disabled="loading" type="submit" label="Speichern" /> | ||
</form> | ||
|
||
<h2>Passwort Ändern</h2> | ||
|
||
<form @submit.prevent="onSubmitChangePassword"> | ||
<div class="field"> | ||
<label>Altes Passwort</label> | ||
<InputText class="w-full" v-model="oldPassword" type="password" required /> | ||
</div> | ||
<div class="field"> | ||
<label>Neues Passwort</label> | ||
<InputText class="w-full" v-model="newPassword" type="password" required /> | ||
</div> | ||
<Button :disabled="loading" type="submit" label="Speichern" /> | ||
</form> | ||
<hr /> | ||
<h3>RSA Keypair generieren</h3> | ||
<Button @click="onGenerateKeypair" label="Generieren (ausgabe in der Konsole)" /> | ||
<h3>Profildaten Server</h3> | ||
<pre>{{ me }}</pre> | ||
<h3>Profildaten Browser Session</h3> | ||
<pre>{{ user }}</pre> | ||
</template> |