Skip to content
Permalink
Browse files

Simply flash message setting in auth component.

  • Loading branch information...
ADmad committed Sep 6, 2014
1 parent 4d183f8 commit c3a48581ba3ee62535d024eeceaa5983067c04cf
@@ -105,8 +105,10 @@ class AuthComponent extends Component {
* - `flash` - Settings to use when Auth needs to do a flash message with
* FlashComponent::set(). Available keys are:
*
* - `key` - The message domain to use for flashes generated by this component, defaults to 'auth'.
* - `params` - The array of additional params to use, defaults to []
* - `key` - The message domain to use for flashes generated by this component,
* defaults to 'auth'.
* - `element` - Flash element to use, defaults to 'default'.
* - `params` - The array of additional params to use, defaults to ['class' => 'error']
*
* - `loginAction` - A URL (defined as a string or array) to the controller action
* that handles logins. Defaults to `/users/login`.
@@ -422,7 +424,7 @@ protected function _setDefaults() {
'flash' => [
'element' => 'default',
'key' => 'auth',
'params' => []
'params' => ['class' => 'error']
],
'loginAction' => [
'controller' => 'Users',
@@ -785,26 +787,15 @@ public function getAuthenticate($alias) {
}
/**
* Set a flash message. Uses the Session component, and values from `flash` config.
* Set a flash message. Uses the Flash component with values from `flash` config.
*
* @param string $message The message to set.
* @param string $type Message type. Defaults to 'error'.
* @return void
*/
public function flash($message, $type = 'error') {
if ($message === false) {
return;
}
$flashConfig = $this->_config['flash'];
$key = $flashConfig['key'];
$params = [];
if (isset($flashConfig['params'])) {
$params = $flashConfig['params'];
}
if (empty($params['element'])) {
$params['element'] = 'error';
public function flash($message) {
if ($message !== false) {
$this->Flash->set($message, $this->_config['flash']);
}
$this->Flash->set($message, $params + compact('key'));
}
/**
@@ -1098,22 +1098,33 @@ public function testFlashSettings() {
[],
[$this->Controller->components()]
);
$this->Controller->methods = ['foo'];
$this->Controller->request->params['action'] = 'foo';
$this->Auth->startup(new Event('Controller.startup', $this->Controller));
$this->Auth->Flash->expects($this->at(0))
->method('set')
->with('Auth failure', array('key' => 'auth-key', 'element' => 'custom'));
->with(
'Auth failure',
[
'key' => 'auth-key',
'element' => 'default',
'params' => ['class' => 'error']
]
);
$this->Auth->Flash->expects($this->at(1))
->method('set')
->with('Auth failure', array('element' => 'error', 'key' => 'auth-key'));
->with('Auth failure', ['key' => 'auth-key', 'element' => 'custom']);
$this->Auth->config('flash', [
'params' => array('element' => 'custom'),
'key' => 'auth-key'
]);
$this->Auth->flash('Auth failure');
$this->Auth->config('flash', [
'key' => 'auth-key'
'key' => 'auth-key',
'element' => 'custom'
], false);
$this->Auth->flash('Auth failure');
}

0 comments on commit c3a4858

Please sign in to comment.
You can’t perform that action at this time.