Skip to content

Commit

Permalink
php5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Apr 26, 2015
1 parent cdefdb7 commit 187245c
Show file tree
Hide file tree
Showing 37 changed files with 329 additions and 329 deletions.
46 changes: 23 additions & 23 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public function login() {
if ($this->Common->isPosted()) {
$user = $this->Auth->identify();
if ($user) {
$this->Users->addBehavior('Tools.Passwordable', array('confirm' => false));
$this->Users->addBehavior('Tools.Passwordable', ['confirm' => false]);
$password = $this->request->data['password'];
$dbPassword = $this->Users->field('password', array('id' => $user['id']));
$dbPassword = $this->Users->field('password', ['id' => $user['id']]);

if ($this->Users->needsPasswordRehash($dbPassword)) {
$data = array(
$data = [
'id' => $user['id'],
'pwd' => $password,
'modified' => false
);
];
$updatedUser = $this->Users->newEntity($data, ['markNew' => false]);
if (!$this->Users->save($updatedUser, ['validate' => false])) {
trigger_error(sprintf('Could not store new pwd for user %s.', $user['id']));
Expand Down Expand Up @@ -97,7 +97,7 @@ public function lost_password($key = null) {
} elseif (!empty($key)) {
$uid = $key['user_id'];
$this->request->session()->write('Auth.Tmp.id', $uid);
return $this->redirect(array('action' => 'change_password'));
return $this->redirect(['action' => 'change_password']);
} else {
$this->Flash->message(__('Invalid Key'), 'error');
}
Expand All @@ -110,9 +110,9 @@ public function lost_password($key = null) {

// Validate basic email scheme and captcha input.
if (!$user->errors()) {
$res = $this->Users->find('first', array(
'fields' => array('username', 'id', 'email'),
'conditions' => array('email' => $this->request->data['Form']['login'])));
$res = $this->Users->find('first', [
'fields' => ['username', 'id', 'email'],
'conditions' => ['email' => $this->request->data['Form']['login']]]);

// Valid user found to this email address
if (!empty($res)) {
Expand Down Expand Up @@ -141,7 +141,7 @@ public function lost_password($key = null) {
} else {
$this->Flash->message(__('Confirmation Email could not be sent. Please consult an admin.'), 'error');
}
return $this->redirect(array('action' => 'lost_password'));
return $this->redirect(['action' => 'lost_password']);
}
$this->Flash->message(__('No account has been found for \'{0}\'', $this->request->data['Form']['login']), 'error');
}
Expand All @@ -160,30 +160,30 @@ public function change_password() {
$uid = $this->request->session()->read('Auth.Tmp.id');
if (empty($uid)) {
$this->Flash->message(__('You have to find your account first and click on the link in the email you receive afterwards'), 'error');
return $this->redirect(array('action' => 'lost_password'));
return $this->redirect(['action' => 'lost_password']);
}

if ($this->request->query('abort')) {
if (!empty($uid)) {
$this->request->session()->delete('Auth.Tmp');
}
return $this->redirect(array('action' => 'login'));
return $this->redirect(['action' => 'login']);
}

$user = $this->Users->newEntity();

$this->Users->addBehavior('Tools.Passwordable', array());
$this->Users->addBehavior('Tools.Passwordable', []);
if ($this->Common->isPosted()) {
$user = $this->Users->patchEntity($user, $this->request->data);
$user->id = $uid;
$options = array(
'fieldList' => array('id', 'pwd', 'pwd_repeat')
);
$options = [
'fieldList' => ['id', 'pwd', 'pwd_repeat']
];
if ($this->Users->save($user, $options)) {
$this->Flash->message(__('new pw saved - you may now log in'), 'success');
$this->request->session()->delete('Auth.Tmp');
$username = $this->Users->fieldByConditions('username', array('id' => $uid));
return $this->Common->postRedirect(array('action' => 'login', '?' => array('username' => $username)));
$username = $this->Users->fieldByConditions('username', ['id' => $uid]);
return $this->Common->postRedirect(['action' => 'login', '?' => ['username' => $username]]);
}
$this->Flash->message(__('formContainsErrors'), 'error');

Expand Down Expand Up @@ -212,7 +212,7 @@ public function register() {
$this->Flash->message(__('Account created'), 'success');
// Log in right away
$this->Auth->setUser($user->toArray());
return $this->redirect(array('controller' => 'Overview', 'action' => 'index'));
return $this->redirect(['controller' => 'Overview', 'action' => 'index']);
}
$this->Flash->message(__('formContainsErrors'), 'error');
// pwd should not be passed to the view again for security reasons
Expand All @@ -234,20 +234,20 @@ public function register() {
public function edit() {
$uid = $this->request->session()->read('Auth.User.id');
$user = $this->Users->get($uid);
$this->Users->addBehavior('Tools.Passwordable', array('require' => false));
$this->Users->addBehavior('Tools.Passwordable', ['require' => false]);

if ($this->Common->isPosted()) {
//$user->id = $uid;
$options = array(
$options = [
//'validate' => true,
//'fieldList' => array('id', 'username', 'email', 'irc_nick', 'pwd', 'pwd_repeat')
);
];
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user, $options)) {
// Update session data, as well
$this->Flash->message(__('Account modified'), 'success');
$this->Auth->setUser($user->toArray());
return $this->redirect(array('controller' => 'Overview', 'action' => 'index'));
return $this->redirect(['controller' => 'Overview', 'action' => 'index']);
}
$this->Flash->message(__('formContainsErrors'), 'error');

Expand All @@ -273,7 +273,7 @@ public function delete($id = null) {
throw new InternalErrorException();
}
$this->Flash->message('Account deleted', 'success');
return $this->redirect(array('action' => 'logout'));
return $this->redirect(['action' => 'logout']);
}

}
48 changes: 24 additions & 24 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/
class AppController extends Controller {

public $components = array('Shim.Session', 'RequestHandler', 'Tools.Common', 'Tools.Flash', 'Tools.AuthUser');
public $components = ['Shim.Session', 'RequestHandler', 'Tools.Common', 'Tools.Flash', 'Tools.AuthUser'];

public $helpers = array('Session', 'Html', 'Tools.Form', 'Tools.Common', 'Tools.Flash',
'Tools.Format', 'Tools.Time', 'Tools.Number', 'Tools.AuthUser', 'Tools.Obfuscate', 'Tools.Js');
public $helpers = ['Session', 'Html', 'Tools.Form', 'Tools.Common', 'Tools.Flash',
'Tools.Format', 'Tools.Time', 'Tools.Number', 'Tools.AuthUser', 'Tools.Obfuscate', 'Tools.Js'];

/**
* AppController::constructClasses()
Expand All @@ -27,47 +27,47 @@ class AppController extends Controller {
public function initialize() {
parent::initialize();

$this->loadComponent('Auth', array(
'authenticate' => array(
'FOC/Authenticate.MultiColumn' => array(
'fields' => array(
$this->loadComponent('Auth', [
'authenticate' => [
'FOC/Authenticate.MultiColumn' => [
'fields' => [
'username' => 'login',
'password' => 'password'
),
'columns' => array('username', 'email'),
],
'columns' => ['username', 'email'],
'userModel' => 'Users',
'passwordHasher' => Configure::read('Passwordable.passwordHasher')
//'scope' => array('User.email_confirmed' => 1)
),
),
'authorize' => array(
],
],
'authorize' => [
'TinyAuth.Tiny'
),
'logoutRedirect' => array(
],
'logoutRedirect' => [
'plugin' => false,
'admin' => false,
'controller' => 'Overview',
'action' => 'index'
),
'loginRedirect' => array(
],
'loginRedirect' => [
'plugin' => false,
'admin' => false,
'controller' => 'Overview',
'action' => 'index'
),
'loginAction' => array(
],
'loginAction' => [
'plugin' => false,
'admin' => false,
'controller' => 'Account',
'action' => 'login'
),
'unauthorizedRedirect' => array(
],
'unauthorizedRedirect' => [
'plugin' => false,
'admin' => false,
'controller' => 'Overview',
'action' => 'index'
)
));
]
]);
}

/**
Expand All @@ -79,7 +79,7 @@ public function beforeFilter(Event $event) {
parent::beforeFilter($event);

// Do not allow access to these public actions when already logged in
$allowed = array('Account' => array('login', 'lost_password', 'register'));
$allowed = ['Account' => ['login', 'lost_password', 'register']];
if (!$this->AuthUser->id()) {
return;
}
Expand All @@ -94,7 +94,7 @@ public function beforeFilter(Event $event) {
//preg_match('/([a-z]{2})-([A-Z]{2})/', env('HTTP_ACCEPT_LANGUAGE'), $matches);
//TODO: use request->parseLanguage stuff instead()
$matches = \Tools\Utility\Language::parseLanguageList();
$matches = array();
$matches = [];
if ($matches) {
$locale = array_shift($matches);
$locale = array_shift($locale);
Expand Down
20 changes: 10 additions & 10 deletions src/Controller/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index() {
* @return void
*/
public function add() {
$events = $this->Attendees->Events->find('list', array('conditions' => array('Events.to >=' => date(FORMAT_DB_DATETIME))));
$events = $this->Attendees->Events->find('list', ['conditions' => ['Events.to >=' => date(FORMAT_DB_DATETIME)]]);

$defaults = [
'from' => new Time(),
Expand Down Expand Up @@ -62,7 +62,7 @@ public function add() {
$from = $attendee['from'];
$to = $attendee['to'];
$this->Flash->message(__('Attendance from {0} to {1} saved', $from, $to), 'success');
return $this->Common->postRedirect(array('action' => 'index'));
return $this->Common->postRedirect(['action' => 'index']);
}
$this->Flash->message(__('formContainsErrors'), 'error');
}
Expand All @@ -77,21 +77,21 @@ public function add() {
*/
public function edit($id = null) {
$uid = $this->Session->read('Auth.User.id');
if (empty($id) || !($attendee = $this->Attendees->find('first', array('conditions' => array('Attendees.id' => $id, 'Attendees.user_id' => $uid))))) {
if (empty($id) || !($attendee = $this->Attendees->find('first', ['conditions' => ['Attendees.id' => $id, 'Attendees.user_id' => $uid]]))) {
$this->Flash->message(__('invalidRecord'), 'error');
return $this->Common->autoRedirect(array('action' => 'index'));
return $this->Common->autoRedirect(['action' => 'index']);
}
if ($this->Common->isPosted()) {
$attendee = $this->Attendees->patchEntity($attendee, $this->request->data);
if ($this->Attendees->save($attendee)) {
$from = $attendee['from'];
$to = $attendee['to'];
$this->Flash->message(__('Attendance from {0} to {1} saved', $from, $to), 'success');
return $this->Common->postRedirect(array('action' => 'index'));
return $this->Common->postRedirect(['action' => 'index']);
}
$this->Flash->message(__('formContainsErrors'), 'error');
}
$events = $this->Attendees->Events->find('list', array('conditions' => array('Events.to >=' => date(FORMAT_DB_DATETIME))));
$events = $this->Attendees->Events->find('list', ['conditions' => ['Events.to >=' => date(FORMAT_DB_DATETIME)]]);
$this->set(compact('attendee', 'events'));
$this->render('add');
}
Expand All @@ -106,18 +106,18 @@ public function edit($id = null) {
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$uid = $this->Session->read('Auth.User.id');
if (empty($id) || !($attendee = $this->Attendees->find('first', array('conditions' => array('Attendees.id' => $id, 'Attendees.user_id' => $uid), 'fields' => array('id', 'user_id'))))) {
if (empty($id) || !($attendee = $this->Attendees->find('first', ['conditions' => ['Attendees.id' => $id, 'Attendees.user_id' => $uid], 'fields' => ['id', 'user_id']]))) {
$this->Flash->message(__('invalidRecord'), 'error');
return $this->Common->autoRedirect(array('action' => 'index'));
return $this->Common->autoRedirect(['action' => 'index']);
}
$var = $attendee['user_id'];

if ($this->Attendees->delete($attendee)) {
$this->Flash->message(__('record del {0} done', h($var)), 'success');
return $this->Common->postRedirect(array('action' => 'index'));
return $this->Common->postRedirect(['action' => 'index']);
}
$this->Flash->message(__('record del {0} not done exception', h($var)), 'error');
return $this->Common->autoRedirect(array('action' => 'index'));
return $this->Common->autoRedirect(['action' => 'index']);
}

}

0 comments on commit 187245c

Please sign in to comment.