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

Login does not work #266

Open
marcellagutie opened this issue May 3, 2017 · 0 comments
Open

Login does not work #266

marcellagutie opened this issue May 3, 2017 · 0 comments

Comments

@marcellagutie
Copy link

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");
	}

}
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant