Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the different pages to see the users #3

Merged
merged 6 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .php_cs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"7.4.4","version":"2.16.4:v2.16.4#1023c3458137ab052f6ff1e09621a721bfdeca13","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"default":"single_space","operators":{"=>":null}},"blank_line_after_namespace":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"braces":true,"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"class_definition":true,"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"elseif":true,"encoding":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"function_declaration":true,"function_typehint_space":true,"heredoc_to_nowdoc":true,"include":true,"increment_style":{"style":"post"},"indentation_type":true,"linebreak_after_opening_tag":true,"line_ending":true,"lowercase_cast":true,"lowercase_constants":true,"lowercase_keywords":true,"lowercase_static_reference":true,"magic_method_casing":true,"magic_constant_casing":true,"method_argument_space":true,"native_function_casing":true,"no_alias_functions":true,"no_extra_blank_lines":{"tokens":["extra","throw","use","use_trait"]},"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_closing_tag":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"multiline_whitespace_before_semicolons":{"strategy":"no_multi_line"},"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_after_function_name":true,"no_spaces_around_offset":true,"no_spaces_inside_parenthesis":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_unneeded_control_parentheses":true,"no_unreachable_default_argument_value":true,"no_useless_return":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"not_operator_with_successor_space":true,"object_operator_without_whitespace":true,"ordered_imports":{"sortAlgorithm":"alpha"},"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_scalar":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"psr4":true,"self_accessor":true,"short_scalar_cast":true,"single_blank_line_at_eof":true,"single_blank_line_before_namespace":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"visibility_required":{"elements":["method","property"]},"whitespace_after_comma_in_array":true},"hashes":{"app\/Providers\/AppServiceProvider.php":1624137708,"app\/Providers\/AuthServiceProvider.php":2861557380,"app\/Providers\/RouteServiceProvider.php":3857645634,"app\/Providers\/BroadcastServiceProvider.php":3839728412,"app\/Providers\/EventServiceProvider.php":3671020230,"app\/Models\/User.php":2790708936,"app\/Exceptions\/Handler.php":1981912889,"app\/Http\/Middleware\/VerifyCsrfToken.php":515967531,"app\/Http\/Middleware\/RedirectIfAuthenticated.php":1776591639,"app\/Http\/Middleware\/TrimStrings.php":2721048702,"app\/Http\/Middleware\/Authenticate.php":2203061520,"app\/Http\/Middleware\/TrustProxies.php":2293446650,"app\/Http\/Middleware\/CheckForMaintenanceMode.php":2705887647,"app\/Http\/Middleware\/EncryptCookies.php":2317483050,"app\/Http\/Middleware\/TrustHosts.php":4181407162,"app\/Http\/Controllers\/HomeController.php":806536901,"app\/Http\/Controllers\/Controller.php":2377246532,"app\/Http\/Controllers\/Auth\/ForgotPasswordController.php":3125538946,"app\/Http\/Controllers\/Auth\/LoginController.php":1867017063,"app\/Http\/Controllers\/Auth\/ConfirmPasswordController.php":1535440868,"app\/Http\/Controllers\/Auth\/ResetPasswordController.php":4125234289,"app\/Http\/Controllers\/Auth\/RegisterController.php":3494077227,"app\/Http\/Controllers\/Auth\/VerificationController.php":3663150386,"app\/Http\/Kernel.php":237482083,"app\/Console\/Kernel.php":354488776,"config\/hashing.php":1409853592,"config\/auth.php":2062149846,"config\/app.php":21615634,"config\/mail.php":307380346,"config\/services.php":4251272034,"config\/database.php":1792943348,"config\/cache.php":1278800609,"config\/session.php":1959959110,"config\/queue.php":2511970003,"config\/broadcasting.php":3873470898,"config\/view.php":2532436371,"config\/cors.php":3545401110,"config\/logging.php":2489126663,"config\/filesystems.php":3729859303,"database\/migrations\/2014_10_12_100000_create_password_resets_table.php":2423716589,"database\/migrations\/2014_10_12_000000_create_users_table.php":3331038532,"database\/migrations\/2019_08_19_000000_create_failed_jobs_table.php":1472189094,"database\/seeds\/UserSeeder.php":1798988804,"database\/seeds\/DatabaseSeeder.php":252746793,"database\/factories\/UserFactory.php":2598479191,"resources\/lang\/en\/passwords.php":3172527856,"resources\/lang\/en\/auth.php":3307291722,"resources\/lang\/en\/pagination.php":2109704695,"resources\/lang\/en\/validation.php":143020465,"routes\/channels.php":421778596,"routes\/console.php":2755491784,"routes\/web.php":2732286974,"routes\/api.php":552248649,"tests\/Unit\/ExampleTest.php":3281010548,"tests\/CreatesApplication.php":1811814938,"tests\/Feature\/ExampleTest.php":2074667504,"tests\/TestCase.php":1353191102}}
{"php":"7.4.4","version":"2.16.4:v2.16.4#1023c3458137ab052f6ff1e09621a721bfdeca13","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"default":"single_space","operators":{"=>":null}},"blank_line_after_namespace":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"braces":true,"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"class_definition":true,"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"elseif":true,"encoding":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"function_declaration":true,"function_typehint_space":true,"heredoc_to_nowdoc":true,"include":true,"increment_style":{"style":"post"},"indentation_type":true,"linebreak_after_opening_tag":true,"line_ending":true,"lowercase_cast":true,"lowercase_constants":true,"lowercase_keywords":true,"lowercase_static_reference":true,"magic_method_casing":true,"magic_constant_casing":true,"method_argument_space":true,"native_function_casing":true,"no_alias_functions":true,"no_extra_blank_lines":{"tokens":["extra","throw","use","use_trait"]},"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_closing_tag":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"multiline_whitespace_before_semicolons":{"strategy":"no_multi_line"},"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_after_function_name":true,"no_spaces_around_offset":true,"no_spaces_inside_parenthesis":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_unneeded_control_parentheses":true,"no_unreachable_default_argument_value":true,"no_useless_return":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"not_operator_with_successor_space":true,"object_operator_without_whitespace":true,"ordered_imports":{"sortAlgorithm":"alpha"},"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_scalar":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"psr4":true,"self_accessor":true,"short_scalar_cast":true,"single_blank_line_at_eof":true,"single_blank_line_before_namespace":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"visibility_required":{"elements":["method","property"]},"whitespace_after_comma_in_array":true},"hashes":{"app\/Providers\/AppServiceProvider.php":1624137708,"app\/Providers\/AuthServiceProvider.php":2861557380,"app\/Providers\/RouteServiceProvider.php":3857645634,"app\/Providers\/BroadcastServiceProvider.php":3839728412,"app\/Providers\/EventServiceProvider.php":3671020230,"app\/Models\/User.php":2790708936,"app\/Exceptions\/Handler.php":1981912889,"app\/Http\/Middleware\/VerifyCsrfToken.php":515967531,"app\/Http\/Middleware\/RedirectIfAuthenticated.php":1776591639,"app\/Http\/Middleware\/TrimStrings.php":2721048702,"app\/Http\/Middleware\/Authenticate.php":2203061520,"app\/Http\/Middleware\/TrustProxies.php":2293446650,"app\/Http\/Middleware\/CheckForMaintenanceMode.php":2705887647,"app\/Http\/Middleware\/EncryptCookies.php":2317483050,"app\/Http\/Middleware\/TrustHosts.php":4181407162,"app\/Http\/Controllers\/Controller.php":2377246532,"app\/Http\/Controllers\/Auth\/ForgotPasswordController.php":3125538946,"app\/Http\/Controllers\/Auth\/LoginController.php":1867017063,"app\/Http\/Controllers\/Auth\/ConfirmPasswordController.php":1535440868,"app\/Http\/Controllers\/Auth\/ResetPasswordController.php":4125234289,"app\/Http\/Controllers\/Auth\/VerificationController.php":3663150386,"app\/Http\/Kernel.php":237482083,"app\/Console\/Kernel.php":354488776,"config\/hashing.php":1409853592,"config\/auth.php":2062149846,"config\/app.php":21615634,"config\/mail.php":307380346,"config\/services.php":4251272034,"config\/database.php":1792943348,"config\/cache.php":1278800609,"config\/session.php":1959959110,"config\/queue.php":2511970003,"config\/broadcasting.php":3873470898,"config\/view.php":2532436371,"config\/cors.php":3545401110,"config\/logging.php":2489126663,"config\/filesystems.php":3729859303,"database\/migrations\/2014_10_12_100000_create_password_resets_table.php":2423716589,"database\/migrations\/2014_10_12_000000_create_users_table.php":3331038532,"database\/migrations\/2019_08_19_000000_create_failed_jobs_table.php":1472189094,"database\/seeds\/UserSeeder.php":1798988804,"database\/seeds\/DatabaseSeeder.php":252746793,"resources\/lang\/en\/passwords.php":3172527856,"resources\/lang\/en\/auth.php":3307291722,"resources\/lang\/en\/pagination.php":2109704695,"resources\/lang\/en\/validation.php":143020465,"routes\/channels.php":421778596,"routes\/console.php":2755491784,"routes\/api.php":552248649,"tests\/Unit\/ExampleTest.php":3281010548,"tests\/CreatesApplication.php":1811814938,"tests\/Feature\/ExampleTest.php":2074667504,"tests\/TestCase.php":1353191102,"app\/Http\/Controllers\/AdminController.php":263559083,"app\/Http\/Controllers\/ApprovedUserController.php":1272107950,"app\/Http\/Controllers\/UnapprovedUserController.php":2018624032,"app\/Users\/UserRepository.php":1014114328,"database\/migrations\/2020_07_09_135811_add-authorization-to-users.php":1447570763,"tests\/Feature\/UnapprovedUsersTest.php":3718883694,"tests\/Feature\/ApprovedUsersTest.php":2817047112,"tests\/Feature\/HomePageTest.php":2364958767,"app\/Http\/Controllers\/HomeController.php":1697361586,"app\/Http\/Controllers\/Auth\/RegisterController.php":1018985797,"database\/factories\/UserFactory.php":201219654,"routes\/web.php":761708357}}
26 changes: 26 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Users\UserRepository;
use Illuminate\View\View;

final class AdminController extends Controller
{
private $userRepository;

public function __construct(UserRepository $userRepository)
{
$this->middleware('auth');
$this->userRepository = $userRepository;
}

public function index(): View
{
$users = $this->userRepository->getAllUsers();

return view('admin', ['users' => $users]);
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/ApprovedUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Users\UserRepository;
use Illuminate\View\View;

final class ApprovedUserController extends Controller
{
private $userRepository;

public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}

public function index(): View
{
$users = $this->userRepository->getAllApprovedUsers();

return view('users_list', ['users' => $users]);
}
}
18 changes: 5 additions & 13 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\View\View;

class HomeController extends Controller
final class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
public function index(): View
{
return view('home');
}
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Controllers/UnapprovedUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Users\UserRepository;
use Illuminate\View\View;

final class UnapprovedUserController extends Controller
{
private $userRepository;

public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}

public function index(): View
{
$users = $this->userRepository->getAllUnapprovedUsers();

return view('users_list', ['users' => $users]);
}
}
26 changes: 26 additions & 0 deletions app/Users/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Users;

use App\Models\User;
use Illuminate\Database\Eloquent\Collection;

final class UserRepository
{
public function getAllUsers(): Collection
{
return User::all()->sortBy('name');
}

public function getAllApprovedUsers(): Collection
{
return User::all()->whereNotNull('approved_at')->sortBy('name');
}

public function getAllUnapprovedUsers(): Collection
{
return User::all()->whereNull('approved_at')->sortBy('name');
}
}
10 changes: 9 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
/** @var Factory $factory */

use App\Models\User;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Str;

/*
Expand All @@ -18,11 +19,18 @@
*/

$factory->define(User::class, function (Faker $faker) {
$authorized = null;

if ($faker->boolean) {
$authorized = $faker->dateTimeBetween('-1year', 'now');
}

return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'approved_at' => $authorized,
];
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddAuthorizationToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->dateTime('approved_at')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('approved_at');
});
}
}
55 changes: 55 additions & 0 deletions resources/views/admin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@extends('layouts.app')

@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Dashboard') }}</div>

<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<nav>
<a class="btn btn-link" href="{{ route('admin') }}">
{{ __('Admin Page') }}
</a>
<a class="btn btn-link" href="{{ route('unapproved') }}">
{{ __('Unapproved page') }}
</a>
<a class="btn btn-link" href="{{ route('approved') }}">
{{ __('Approved page') }}
</a>
</nav>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">email </th>
<th scope="col">Authorize</th></tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td> {{$user->name}} </td>
<td> {{$user->email}} </td>
@if ($user->approved_at !== null)
<td> <button type="button" class="btn btn-danger">Unauthorize</button> </td>
@else
<td> <button type="button" class="btn btn-success">Authorize</button> </td>
@endif
</tr>
@endforeach
</tbody>
</table>

</div>
</div>
</div>
</div>
</div>
@endsection
Loading