Added function to register new user
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Access;
|
||||
use Core\Token;
|
||||
use Core\Session;
|
||||
use Core\Redirect;
|
||||
use Core\Hash;
|
||||
|
||||
class Home
|
||||
{
|
||||
@@ -18,18 +19,52 @@ class Home
|
||||
{
|
||||
$posts = new Posts();
|
||||
$posts->index();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
View::render('Access/login.html', [
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
return true;
|
||||
if (Session::exists('userid')) {
|
||||
Redirect::to('/');
|
||||
} else {
|
||||
View::render('Access/login.html', [
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
View::render('Access/registrasi.html', [
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
public function post($args = [])
|
||||
{
|
||||
$table = 'user';
|
||||
|
||||
$date = new \DateTime();
|
||||
$now = $date->format('Y-m-d');
|
||||
$args['registered_at'] = $now;
|
||||
|
||||
$salt = Hash::salt();
|
||||
$password = Hash::make($args['password'], $salt);
|
||||
$args['salt'] = $salt;
|
||||
$args['password'] = $password;
|
||||
|
||||
$args['full_name'] = htmlspecialchars($args['full_name']);
|
||||
$args['username'] = htmlspecialchars($args['username']);
|
||||
|
||||
$this->access->entry($table, $args);
|
||||
|
||||
// Redirect::to('/');
|
||||
}
|
||||
|
||||
public function put($args = [])
|
||||
{
|
||||
if ($this->access->login($args)) {
|
||||
|
||||
Reference in New Issue
Block a user