jasonhinkle / phreeze

Phreeze Framework for PHP
http://phreeze.com/
GNU Lesser General Public License v2.1
377 stars 207 forks source link

Login does not work #266

Open marcellagutie opened 7 years ago

marcellagutie commented 7 years ago

Hey, I'm new using phreeze and I'm testing on a project. Everything works perfectly, except the login. I need to connect the view login to my user table from the database. I already removed the static array in the exampleuser, put the data in the model user.php, but I can not get it to work. Please help me! I think the problem is somewhere in the secureteExample. But i can't find.... That is SecureExampleController:

<?php
/** @package SecureExample::Controller */

/** import supporting libraries */
require_once("AppBaseController.php");
require_once("Model/User.php");

/**
 * SecureExampleController is a sample controller to demonstrate
 * one approach to authentication in a Phreeze app
 *
 * @package Cargo::Controller
 * @author ClassBuilder
 * @version 1.0
 */
class SecureExampleController extends AppBaseController
{

    /**
     * Override here for any controller-specific functionality
     */
    protected function Init()
    {
        parent::Init();

        // TODO: add controller-wide bootstrap code
    }

    /**
     * This page requires ExampleUser::$PERMISSION_USER to view
     */
    public function UserPage()
    {
        $this->RequirePermission(User::$PERMISSION_READ,
                'SecureExample.LoginForm',
                'Login is required to access the secure user page',
                'You do not have permission to access the secure user page');

        $this->Assign("currentUser", $this->GetCurrentUser());

        $this->Assign('page','userpage');
        $this->Render("SecureExample");
    }

    /**
     * This page requires ExampleUser::$PERMISSION_ADMIN to view
     */
    public function AdminPage()
    {
        $this->RequirePermission(User::$PERMISSION_ADMIN,
                'SecureExample.LoginForm',
                'Login is required to access the admin page',
                'Admin permission is required to access the admin page');

        $this->Assign("currentUser", $this->GetCurrentUser());

        $this->Assign('page','adminpage');
        $this->Render("SecureExample");
    }

    /**
     * Display the login form
     */
    public function LoginForm()
    {
        $this->Assign("currentUser", $this->GetCurrentUser());

        $this->Assign('page','login');
        $this->Render("SecureExample");
    }

    /**
     * Process the login, create the user session and then redirect to
     * the appropriate page
     */
    public function Login()
    {
        $user = new User($this->Phreezer);

        if ($user->Login(RequestUtil::Get('username'), RequestUtil::Get('password')))
        {
            // login success
            $this->SetCurrentUser($user);
            $this->Redirect('SecureExample.UserPage');
        }
        else
        {
            // login failed
            $this->Redirect('SecureExample.LoginForm','Unknown username/password combination');
        }
    }

    /**
     * Clear the user session and redirect to the login page
     */
    public function Logout()
    {
        $this->ClearCurrentUser();
        $this->Redirect("SecureExample.LoginForm","You are now logged out");
    }

}
?>