You've already forked isop-mirror
Merge branch 'develop' into feature/83-zobrazenie-uctu-pouzivatela
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Auth;
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Mail\UserAccountActivated;
|
||||||
use App\Mail\UserPasswordReset;
|
use App\Mail\UserPasswordReset;
|
||||||
use App\Mail\UserRegistrationCompleted;
|
use App\Mail\UserRegistrationCompleted;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
@@ -25,6 +26,7 @@ class RegisteredUserController extends Controller
|
|||||||
public function store(Request $request): Response
|
public function store(Request $request): Response
|
||||||
{
|
{
|
||||||
$password = bin2hex(random_bytes(16));
|
$password = bin2hex(random_bytes(16));
|
||||||
|
$activation_token = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
|
||||||
@@ -58,6 +60,7 @@ class RegisteredUserController extends Controller
|
|||||||
'phone' => $request->phone,
|
'phone' => $request->phone,
|
||||||
'role' => $request->role,
|
'role' => $request->role,
|
||||||
'password' => Hash::make($password),
|
'password' => Hash::make($password),
|
||||||
|
'activation_token' => $activation_token
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($user->role === "STUDENT") {
|
if ($user->role === "STUDENT") {
|
||||||
@@ -83,12 +86,33 @@ class RegisteredUserController extends Controller
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mail::to($user)->sendNow(new UserRegistrationCompleted($user->name, $password));
|
Mail::to($user)->sendNow(new UserRegistrationCompleted($user->name, $activation_token));
|
||||||
event(new Registered($user));
|
event(new Registered($user));
|
||||||
|
|
||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function activate(Request $request) {
|
||||||
|
$request->validate([
|
||||||
|
'token' => ['required', 'string', 'exists:users,activation_token'],
|
||||||
|
'password' => ['required', 'string', 'min:8'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::where('activation_token', '=', $request->token)->first();
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Invalid activation token'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->active = true;
|
||||||
|
$user->activation_token = null;
|
||||||
|
$user->password = Hash::make($request->password);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
Mail::to($user)->sendNow(new UserAccountActivated($user->name));
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
|
|
||||||
public function reset_password(Request $request): Response
|
public function reset_password(Request $request): Response
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ class LoginRequest extends FormRequest
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the authenticated user's account is active
|
||||||
|
if (! Auth::user()->active) {
|
||||||
|
Auth::logout();
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => __('auth.inactive_account'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
RateLimiter::clear($this->throttleKey());
|
RateLimiter::clear($this->throttleKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
58
backend/app/Mail/UserAccountActivated.php
Normal file
58
backend/app/Mail/UserAccountActivated.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class UserAccountActivated extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
private string $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*/
|
||||||
|
public function __construct(string $name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*/
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: 'User Account Activated',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'mail.activation.completed',
|
||||||
|
with: [
|
||||||
|
"name" => $this->name,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||||
|
*/
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,15 +14,15 @@ class UserRegistrationCompleted extends Mailable
|
|||||||
use Queueable, SerializesModels;
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
private string $name;
|
private string $name;
|
||||||
private string $password;
|
private string $activation_token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new message instance.
|
* Create a new message instance.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $name, string $password)
|
public function __construct(string $name, string $activation_token)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->password = $password;
|
$this->activation_token = $activation_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +44,7 @@ class UserRegistrationCompleted extends Mailable
|
|||||||
view: 'mail.registration.completed',
|
view: 'mail.registration.completed',
|
||||||
with: [
|
with: [
|
||||||
"name" => $this->name,
|
"name" => $this->name,
|
||||||
"password" => $this->password
|
"activation_token" => $this->activation_token
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ class User extends Authenticatable
|
|||||||
'email',
|
'email',
|
||||||
'role',
|
'role',
|
||||||
'password',
|
'password',
|
||||||
|
'active',
|
||||||
|
'needs_password_change',
|
||||||
|
'activation_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +38,7 @@ class User extends Authenticatable
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
|
'activation_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +51,8 @@ class User extends Authenticatable
|
|||||||
return [
|
return [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
'password' => 'hashed',
|
'password' => 'hashed',
|
||||||
|
'active' => 'boolean',
|
||||||
|
'needs_password_change' => 'boolean'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class UserFactory extends Factory
|
|||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
'password' => static::$password ??= Hash::make('password'),
|
'password' => static::$password ??= Hash::make('password'),
|
||||||
'remember_token' => Str::random(10),
|
'remember_token' => Str::random(10),
|
||||||
|
'active' => true,
|
||||||
|
'needs_password_change' => false,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ return new class extends Migration
|
|||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->timestamp('email_verified_at')->nullable();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
|
$table->boolean('active')->default(false);
|
||||||
|
$table->boolean('needs_password_change')->default(false);
|
||||||
|
$table->string('activation_token')->nullable();
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@include("parts.header")
|
||||||
|
<p>Vážená/ý {{ $name }},</p>
|
||||||
|
<p>úspešne ste aktivovali váš účet!</p>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<p>s pozdravom</p>
|
||||||
|
<p>Systém ISOP UKF</p>
|
||||||
|
@include("parts.footer")
|
||||||
@@ -3,7 +3,12 @@
|
|||||||
<p>vaša registrácia do systému ISOP UKF prebehla úspešne!</p>
|
<p>vaša registrácia do systému ISOP UKF prebehla úspešne!</p>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<p>Vaše heslo je: <em>{{ $password }}</em></p>
|
<p>Aktivujte účet pomocou nasledujúceho linku:</p>
|
||||||
|
<br />
|
||||||
|
<p>
|
||||||
|
<a
|
||||||
|
href="{{ config('app.frontend_url') }}/account/activation/{{ $activation_token }}">{{ config('app.frontend_url') }}/account/activation/{{ $activation_token }}</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ Route::middleware(['auth:sanctum'])->get('/user', function (Request $request) {
|
|||||||
return $user;
|
return $user;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('/account')->group(function () {
|
||||||
|
Route::post("/activate", [RegisteredUserController::class, 'activate']);
|
||||||
|
});
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum'])->prefix('/students')->group(function () {
|
Route::middleware(['auth:sanctum'])->prefix('/students')->group(function () {
|
||||||
Route::get('/', [StudentDataController::class, 'all']);
|
Route::get('/', [StudentDataController::class, 'all']);
|
||||||
Route::get('/{id}', [StudentDataController::class, 'get']);
|
Route::get('/{id}', [StudentDataController::class, 'get']);
|
||||||
|
|||||||
138
frontend/app/pages/account/activation/[token].vue
Normal file
138
frontend/app/pages/account/activation/[token].vue
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FetchError } from 'ofetch';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const client = useSanctumClient();
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
middleware: ['sanctum:guest'],
|
||||||
|
});
|
||||||
|
|
||||||
|
useSeoMeta({
|
||||||
|
title: "Aktivácia účtu | ISOP",
|
||||||
|
ogTitle: "Aktivácia účtu",
|
||||||
|
description: "Aktivácia účtu ISOP",
|
||||||
|
ogDescription: "Aktivácia účtu",
|
||||||
|
});
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
required: (v: string) => (!!v && v.trim().length > 0) || 'Povinné pole',
|
||||||
|
};
|
||||||
|
|
||||||
|
const isValid = ref(false);
|
||||||
|
const showPassword = ref(false);
|
||||||
|
const password = ref('');
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const error = ref(null as null | string);
|
||||||
|
const success = ref(false);
|
||||||
|
|
||||||
|
async function handleLogin() {
|
||||||
|
error.value = null;
|
||||||
|
loading.value = true;
|
||||||
|
success.value = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client('/api/account/activate', {
|
||||||
|
method: 'POST',
|
||||||
|
body: {
|
||||||
|
token: route.params.token,
|
||||||
|
password: password.value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
success.value = true;
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof FetchError && e.response?.status === 422) {
|
||||||
|
error.value = e.response?._data.message;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<v-container fluid class="page-container form-wrap">
|
||||||
|
<v-card id="page-container-card">
|
||||||
|
<h2 class="page-title">Aktivácia účtu</h2>
|
||||||
|
|
||||||
|
<!-- Chybová hláška -->
|
||||||
|
<v-alert v-show="success" density="compact" title="Aktivácia ukončená" type="success" class="mx-auto alert">
|
||||||
|
<p>Váš účet bol úspešne aktivovaný! Prihláste sa <NuxtLink to="/login">tu</NuxtLink>.
|
||||||
|
</p>
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<div v-show="!success">
|
||||||
|
<!-- Chybová hláška -->
|
||||||
|
<v-alert v-if="error !== null" density="compact" :text="error" title="Chyba" type="error"
|
||||||
|
class="mx-auto alert"></v-alert>
|
||||||
|
|
||||||
|
<!-- Čakajúca hláška -->
|
||||||
|
<v-alert v-if="loading" density="compact" text="Prosím čakajte..." title="Spracovávam" type="info"
|
||||||
|
class="mx-auto alert"></v-alert>
|
||||||
|
|
||||||
|
<v-form v-else v-model="isValid" @submit.prevent="handleLogin">
|
||||||
|
<v-text-field v-model="password" :rules="[rules.required]"
|
||||||
|
:type="showPassword ? 'text' : 'password'" label="Heslo:" variant="outlined"
|
||||||
|
density="comfortable"
|
||||||
|
:append-inner-icon="showPassword ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
|
||||||
|
@click:append-inner="showPassword = !showPassword" />
|
||||||
|
|
||||||
|
<v-btn type="submit" color="success" size="large" block :disabled="!isValid">
|
||||||
|
Aktivovať
|
||||||
|
</v-btn>
|
||||||
|
</v-form>
|
||||||
|
</div>
|
||||||
|
</v-card>
|
||||||
|
</v-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.alert {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-container {
|
||||||
|
max-width: 1120px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding-left: 24px;
|
||||||
|
padding-right: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-container-card {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-wrap {
|
||||||
|
max-width: 640px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-title {
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 1.2;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 24px 0 16px;
|
||||||
|
color: #1f1f1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forgot-btn {
|
||||||
|
text-transform: none;
|
||||||
|
font-weight: 600;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mb-1 {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mb-2 {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user