Skip to content

Commit

Permalink
Helpers Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arya-alireza committed Nov 10, 2021
1 parent 0706cfa commit 6c260ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 3 additions & 5 deletions app/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Core\Controller;
use Core\Request;
use Core\Route;
use Core\View;
use App\Helpers\Hash;
use App\Models\User;

Expand All @@ -26,12 +24,12 @@ public function login()
$hash = $user->password;
if (Hash::verify($pass, $hash)) {
$_SESSION['userLogin'] = $user->id;
Route::redirect('dashboard');
return redirect('dashboard');
} else {
Route::redirect('login', ['error', 'Password is wrong!']);
return redirect('login', ['error', 'Password is wrong!']);
}
} else {
Route::redirect('login', ['error', 'User not found!']);
return redirect('login', ['error', 'User not found!']);
}
}
}
8 changes: 3 additions & 5 deletions app/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

use Core\Controller;
use Core\Request;
use Core\View;
use Core\Route;
use App\Models\User;
use App\Helpers\Hash;
use App\Models\User;

class RegisterController extends Controller
{
public function show()
{
View::render('auth/register');
return view('auth/register');
}

public function register()
Expand All @@ -23,6 +21,6 @@ public function register()
$data['password'] = Hash::make($data['password']);
$userId = User::create($data);
$_SESSION['userLogin'] = $userId;
Route::redirect('dashboard');
return redirect('dashboard');
}
}
13 changes: 13 additions & 0 deletions bootstrap/helpers.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?php

use Core\View;
use Core\Route;

if (! function_exists('view')) {
function view($name, $args = []) {
View::render($name, $args);
}
}

if (! function_exists('route')) {
function route($name, $args = null) {
Route::url($name, $args);
}
}

if (! function_exists('redirect')) {
function redirect($url, $msg = null) {
Route::redirect($url, $msg);
}
}

0 comments on commit 6c260ee

Please sign in to comment.