Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vicholp committed Feb 24, 2023
1 parent 2e842a7 commit a0af5ca
Show file tree
Hide file tree
Showing 67 changed files with 2,842 additions and 873 deletions.
40 changes: 40 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\CreatesNewUsers;

class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;

/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
])->validate();

return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
}
18 changes: 18 additions & 0 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Actions\Fortify;

use Laravel\Fortify\Rules\Password;

trait PasswordValidationRules
{
/**
* Get the validation rules used to validate passwords.
*
* @return array<int, \Illuminate\Contracts\Validation\Rule|array|string>
*/
protected function passwordRules(): array
{
return ['required', 'string', new Password(), 'confirmed'];
}
}
29 changes: 29 additions & 0 deletions app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\ResetsUserPasswords;

class ResetUserPassword implements ResetsUserPasswords
{
use PasswordValidationRules;

/**
* Validate and reset the user's forgotten password.
*
* @param array<string, string> $input
*/
public function reset(User $user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();

$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}
32 changes: 32 additions & 0 deletions app/Actions/Fortify/UpdateUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;

class UpdateUserPassword implements UpdatesUserPasswords
{
use PasswordValidationRules;

/**
* Validate and update the user's password.
*
* @param array<string, string> $input
*/
public function update(User $user, array $input): void
{
Validator::make($input, [
'current_password' => ['required', 'string', 'current_password:web'],
'password' => $this->passwordRules(),
], [
'current_password.current_password' => __('The provided password does not match your current password.'),
])->validateWithBag('updatePassword');

$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}
58 changes: 58 additions & 0 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param array<string, string> $input
*/
public function update(User $user, array $input): void
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],

'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique('users')->ignore($user->id),
],
])->validateWithBag('updateProfileInformation');

if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
])->save();
}
}

/**
* Update the given verified user's profile information.
*
* @param array<string, string> $input
*/
protected function updateVerifiedUser(User $user, array $input): void
{
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'email_verified_at' => null,
])->save();

$user->sendEmailVerificationNotification();
}
}
4 changes: 2 additions & 2 deletions app/Console/Commands/CreateBackupDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function handle()
$info = $this->argument('info') ? $this->argument('info') : '';
$appName = config('app.name') ? config('app.name') : 'app';

$filename = $appName . '_' . $env . '_' . $info . '_' . date('Y-m-d-H:m:s') . '.sql'; // @phpstan-ignore-line
$file = config('filesystems.backup_database_path') . '/' . $filename;
$filename = $appName.'_'.$env.'_'.$info.'_'.date('Y-m-d-H:m:s').'.sql'; // @phpstan-ignore-line
$file = config('filesystems.backup_database_path').'/'.$filename;

$process = Process::fromShellCommandline(
"mysqldump --quick --single-transaction --add-drop-database --add-drop-table --lock-tables --extended-insert --host={$host} --user={$username} --password={$password} {$database} > $file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Http\Controllers\Teacher\QuestionBank;

use App\Http\Controllers\Controller;
use App\Models\QuestionPrototype;
use App\Models\QuestionnairePrototype;
use App\Models\QuestionPrototype;
use App\Models\Subject;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function create()
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
Expand All @@ -42,7 +41,6 @@ public function store(Request $request)
/**
* Display the specified resource.
*
* @param \App\Models\StatementPrototype $statementPrototype
* @return \Illuminate\Http\Response
*/
public function show(StatementPrototype $statementPrototype)
Expand All @@ -55,7 +53,6 @@ public function show(StatementPrototype $statementPrototype)
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\StatementPrototype $statementPrototype
* @return \Illuminate\Http\Response
*/
public function edit(StatementPrototype $statementPrototype)
Expand All @@ -68,8 +65,6 @@ public function edit(StatementPrototype $statementPrototype)
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\StatementPrototype $statementPrototype
* @return \Illuminate\Http\Response
*/
public function update(Request $request, StatementPrototype $statementPrototype)
Expand All @@ -82,7 +77,6 @@ public function update(Request $request, StatementPrototype $statementPrototype)
/**
* Remove the specified resource from storage.
*
* @param \App\Models\StatementPrototype $statementPrototype
* @return \Illuminate\Http\Response
*/
public function destroy(StatementPrototype $statementPrototype)
Expand Down
12 changes: 7 additions & 5 deletions app/Models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* App\Models\Admin
* App\Models\Admin.
*
* @property int $id
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $user_id
* @property-read string $name
* @property-read \App\Models\User $user
* @property int $user_id
* @property string $name
* @property \App\Models\User $user
*
* @method static \Illuminate\Database\Eloquent\Builder|Admin newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Admin newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Admin query()
* @method static \Illuminate\Database\Eloquent\Builder|Admin whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Admin whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Admin whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Admin whereUserId($value)
*
* @mixin \Eloquent
*/
class Admin extends Model
Expand Down
28 changes: 15 additions & 13 deletions app/Models/Alternative.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
* App\Models\Alternative
* App\Models\Alternative.
*
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $question_id
* @property int $position
* @property string $name
* @property string|null $data
* @property int $correct
* @property-read \App\Models\Question $question
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Student[] $students
* @property-read int|null $students_count
* @method static \Database\Factories\AlternativeFactory factory(...$parameters)
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $question_id
* @property int $position
* @property string $name
* @property string|null $data
* @property int $correct
* @property \App\Models\Question $question
* @property \Illuminate\Database\Eloquent\Collection|\App\Models\Student[] $students
* @property int|null $students_count
*
* @method static \Database\Factories\AlternativeFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|Alternative newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Alternative newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Alternative query()
Expand All @@ -33,6 +34,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Alternative wherePosition($value)
* @method static \Illuminate\Database\Eloquent\Builder|Alternative whereQuestionId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Alternative whereUpdatedAt($value)
*
* @mixin \Eloquent
*/
class Alternative extends Model
Expand Down
14 changes: 8 additions & 6 deletions app/Models/AlternativeStudent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use Illuminate\Database\Eloquent\Relations\Pivot;

/**
* App\Models\AlternativeStudent
* App\Models\AlternativeStudent.
*
* @property int $id
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $student_id
* @property int $alternative_id
* @property int|null $question_id
* @property int|null $questionnaire_id
* @property int $student_id
* @property int $alternative_id
* @property int|null $question_id
* @property int|null $questionnaire_id
*
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent query()
Expand All @@ -24,6 +25,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent whereQuestionnaireId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent whereStudentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AlternativeStudent whereUpdatedAt($value)
*
* @mixin \Eloquent
*/
class AlternativeStudent extends Pivot
Expand Down
10 changes: 6 additions & 4 deletions app/Models/Collaborator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use Illuminate\Database\Eloquent\Model;

/**
* App\Models\Collaborator
* App\Models\Collaborator.
*
* @property int $id
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $subject_id
* @property int $user_id
* @property int $subject_id
* @property int $user_id
*
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator query()
Expand All @@ -20,6 +21,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator whereSubjectId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Collaborator whereUserId($value)
*
* @mixin \Eloquent
*/
class Collaborator extends Model
Expand Down
Loading

0 comments on commit a0af5ca

Please sign in to comment.