Skip to content

Commit

Permalink
Merge pull request cakephp#944 from Ayb3x/fix-code-line-overflows-tut…
Browse files Browse the repository at this point in the history
…orials-and-examples

Fix code overflows in the Tutorials and Examples section
  • Loading branch information
markstory committed Dec 19, 2013
2 parents 333e9d7 + d9dfbcb commit 5d9213c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
36 changes: 28 additions & 8 deletions en/tutorials-and-examples/blog-auth-example/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ with CakePHP::
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
$this->Session->setFlash(
__('The user could not be saved. Please, try again.')
);
}
}

Expand All @@ -100,7 +102,9 @@ with CakePHP::
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
$this->Session->setFlash(
__('The user could not be saved. Please, try again.')
);
} else {
$this->request->data = $this->User->read(null, $id);
unset($this->request->data['User']['password']);
Expand Down Expand Up @@ -163,8 +167,15 @@ file and add the following lines::
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
'loginRedirect' => array(
'controller' => 'posts',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
)
)
);

Expand Down Expand Up @@ -222,7 +233,9 @@ and add the following::
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
Expand All @@ -238,7 +251,9 @@ We're just missing a template view file for the login function:
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend><?php echo __('Please enter your username and password'); ?></legend>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
?>
Expand Down Expand Up @@ -283,7 +298,8 @@ logged in user as a reference for the created post::
// app/Controller/PostsController.php
public function add() {
if ($this->request->is('post')) {
$this->request->data['Post']['user_id'] = $this->Auth->user('id'); //Added this line
//Added this line
$this->request->data['Post']['user_id'] = $this->Auth->user('id');
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
Expand All @@ -307,7 +323,11 @@ config::
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
),
'authorize' => array('Controller') // Added this line
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ so already:
<h2>Login</h2>
<?php
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'login')));
echo $this->Form->create('User', array(
'url' => array(
'controller' => 'users',
'action' => 'login'
)
));
echo $this->Form->input('User.username');
echo $this->Form->input('User.password');
echo $this->Form->end('Login');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ AuthComponent will expect that your passwords are hashed. In
// other code.

public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
$this->data['User']['password'] = AuthComponent::password(
$this->data['User']['password']
);
return true;
}
}
Expand All @@ -182,9 +184,18 @@ site controlled with Auth and Acl, we will set them up in

public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->loginRedirect = array(
'controller' => 'posts',
'action' => 'add'
);
}
}

Expand Down

0 comments on commit 5d9213c

Please sign in to comment.