HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33
System: Linux li317-225.members.linode.com 3.10.0-1062.12.1.el7.x86_64 #1 SMP Tue Feb 4 23:02:59 UTC 2020 x86_64
User: apache (48)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /var/www/farm.kosmicfarms_backup/app/controllers/SessionController.php
<?php

use Phalcon\Mvc\Controller;

class SessionController extends Controller
{
    public function indexAction()
    {
        
        $this->view->pick('session/index');
        
        $this->assets->collection('nucleo')
        ->addCss('assets/css/nucleo-icons.css')
        ->addCss('assets/css/nucleo-svg.css');
        
        
        $this->assets->collection('pagestyle')
        ->addCss('assets/css/material-dashboard.css?v=3.2.0', true, false, ['id' => 'pagestyle']);
        
    }
    
    public function loginAction()
    {
       
        if ($this->request->isPost()) {
            $email = $this->request->getPost('email');
            $password = $this->request->getPost('password');
            
            // Find the user by email/username and check password
            $user = Users::findFirst([
                "(email = :email:) AND active = 'Y'",
                'bind' => ['email' => $email],
            ]);
            
            if ($user && $this->security->checkHash($password, $user->password)) {
                // Store user identity and role in the session
                $this->session->set('auth', [
                    'id'   => $user->id,
                    'name' => $user->name,
                    'role' => $user->role, // Assign the role from the database
                ]);
                
                // Redirect to a protected area, e.g., 'dashboard'
                return $this->response->redirect('dashboard');
            }
            
        }
        $this->flashSession->error('Incorrect credentials. Please try again.');
        // Disable the view and redirect back to the login page
        $this->view->disable();
        return $this->response->redirect('login');
        // Render the login form
    }
    
    public function logoutAction()
    {
        $this->session->destroy();
        $this->flash->success('You have been logged out.');
        return $this->response->redirect('index/index');
    }
}