2012-03-15 15:06:45 +01:00
|
|
|
<?php
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
/**
|
|
|
|
* Users Controller
|
|
|
|
*
|
|
|
|
* @property User $User
|
|
|
|
*/
|
|
|
|
class UsersController extends AppController {
|
|
|
|
|
2012-07-10 15:38:10 +02:00
|
|
|
public $newkey;
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-06-28 17:24:12 +02:00
|
|
|
public $components = array('Acl','Security'); // TODO ACL, components
|
2012-03-27 09:31:41 +02:00
|
|
|
public $paginate = array(
|
|
|
|
'limit' => 60,
|
|
|
|
'order' => array(
|
|
|
|
'User.org' => 'ASC'
|
|
|
|
)
|
|
|
|
);
|
2012-03-15 15:06:45 +01:00
|
|
|
|
|
|
|
function beforeFilter() {
|
|
|
|
parent::beforeFilter();
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-20 14:57:52 +01:00
|
|
|
// what pages are allowed for non-logged-in users
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->Auth->allow('login', 'logout');
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-20 14:57:52 +01:00
|
|
|
public function isAuthorized($user) {
|
|
|
|
// Admins can access everything
|
|
|
|
if (parent::isAuthorized($user)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Do not allow admin routing
|
|
|
|
if (isset($this->request->params['admin']) && true == $this->request->params['admin'])
|
|
|
|
return false;
|
|
|
|
// Only on own user for these actions
|
2012-04-04 18:32:44 +02:00
|
|
|
if (in_array($this->action, array('view', 'edit', 'delete', 'resetauthkey'))) {
|
2012-03-20 14:57:52 +01:00
|
|
|
$userid = $this->request->params['pass'][0];
|
|
|
|
if ("me" == $userid ) return true;
|
|
|
|
return ($userid === $this->Auth->user('id'));
|
|
|
|
}
|
|
|
|
// the other pages are allowed by logged in users
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function view($id = null) {
|
|
|
|
if ("me" == $id) $id = $this->Auth->user('id');
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
2012-04-04 18:32:44 +02:00
|
|
|
// Only own profile verified by isAuthorized
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->set('user', $this->User->read(null, $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* edit method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function edit($id = null) {
|
|
|
|
if ("me" == $id) $id = $this->Auth->user('id');
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
2012-03-27 14:49:31 +02:00
|
|
|
// Only own profile verified by isAuthorized
|
2012-03-15 15:06:45 +01:00
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
// What fields should be saved (allowed to be saved)
|
2012-06-28 17:24:12 +02:00
|
|
|
$fieldList=array('email', 'autoalert', 'gpgkey', 'nids_sid'); // TODO ACL, check, My Profile not edit group_id.
|
2012-03-22 10:06:33 +01:00
|
|
|
if ("" != $this->request->data['User']['password'])
|
2012-03-15 15:06:45 +01:00
|
|
|
$fieldList[] = 'password';
|
|
|
|
// Save the data
|
|
|
|
if ($this->User->save($this->request->data, true ,$fieldList)) {
|
|
|
|
$this->Session->setFlash(__('The profile has been updated'));
|
2012-04-02 23:00:41 +02:00
|
|
|
$this->_refreshAuth();
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->redirect(array('action' => 'view', $id));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The profile could not be updated. Please, try again.'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->User->recursive=0;
|
|
|
|
$this->User->read(null, $id);
|
|
|
|
$this->User->set('password', '');
|
|
|
|
$this->request->data = $this->User->data;
|
|
|
|
}
|
|
|
|
$this->request->data['User']['org']=$this->Auth->user('org');
|
2012-06-28 17:24:12 +02:00
|
|
|
// XXX ACL groups
|
|
|
|
$groups = $this->User->Group->find('list');
|
|
|
|
$this->set(compact('groups'));
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function delete($id = null) {
|
|
|
|
if ("me" == $id) $id = $this->Auth->user('id');
|
|
|
|
if (!$this->request->is('post')) {
|
|
|
|
throw new MethodNotAllowedException();
|
|
|
|
}
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
2012-03-20 14:57:52 +01:00
|
|
|
// Replaced by isAuthorized
|
|
|
|
// // Only own profile
|
|
|
|
// if ($this->Auth->user('id') != $id) {
|
|
|
|
// throw new ForbiddenException('You are not authorized to delete this profile.');
|
|
|
|
// }
|
2012-03-15 15:06:45 +01:00
|
|
|
if ($this->User->delete()) {
|
|
|
|
$this->Session->setFlash(__('User deleted'));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
$this->Session->setFlash(__('User was not deleted'));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* admin_index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function admin_index() {
|
|
|
|
$this->User->recursive = 0;
|
|
|
|
$this->set('users', $this->paginate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* admin_view method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function admin_view($id = null) {
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
|
|
|
$this->set('user', $this->User->read(null, $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* admin_add method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function admin_add() {
|
|
|
|
if ($this->request->is('post')) {
|
|
|
|
$this->User->create();
|
|
|
|
if ($this->User->save($this->request->data)) {
|
|
|
|
$this->Session->setFlash(__('The user has been saved'));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
2012-07-10 15:38:10 +02:00
|
|
|
// reset auth key for a new user
|
|
|
|
$this->set('authkey', $this->newkey);
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
|
|
|
|
}
|
2012-04-02 23:00:41 +02:00
|
|
|
} else {
|
|
|
|
// generate auth key for a new user
|
2012-07-10 15:38:10 +02:00
|
|
|
$this->newkey = $this->User->generateAuthKey();
|
|
|
|
$this->set('authkey', $this->newkey);
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
2012-06-28 17:24:12 +02:00
|
|
|
// XXX ACL groups
|
|
|
|
$groups = $this->User->Group->find('list');
|
|
|
|
$this->set(compact('groups'));
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* admin_edit method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function admin_edit($id = null) {
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
2012-04-02 17:21:17 +02:00
|
|
|
$fields = array();
|
2012-06-13 14:42:42 +02:00
|
|
|
foreach (array_keys($this->request->data['User']) as $field) {
|
2012-04-02 17:21:17 +02:00
|
|
|
if($field != 'password') array_push($fields, $field);
|
|
|
|
}
|
2012-06-28 17:24:12 +02:00
|
|
|
// TODO Audit, extraLog, fields get orig
|
|
|
|
$fields_oldValues = array();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
if($field != 'confirm_password') array_push($fields_oldValues, $this->User->field($field));
|
|
|
|
else array_push($fields_oldValues, $this->User->field('password'));
|
|
|
|
}
|
|
|
|
// TODO Audit, extraLog, fields get orig END
|
2012-04-02 17:21:17 +02:00
|
|
|
if ("" != $this->request->data['User']['password'])
|
2012-04-04 18:32:44 +02:00
|
|
|
$fields[] = 'password';
|
2012-04-02 17:21:17 +02:00
|
|
|
if ($this->User->save($this->request->data, true, $fields)) {
|
2012-06-28 17:24:12 +02:00
|
|
|
// TODO Audit, extraLog, fields compare
|
|
|
|
// newValues to array
|
|
|
|
$fields_newValues = array();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
if($field != 'confirm_password') {
|
|
|
|
$newValue = $this->data['User'][$field];
|
|
|
|
if (gettype($newValue) == 'array') {
|
|
|
|
$newValueStr = '';
|
|
|
|
$c_p = 0;
|
|
|
|
foreach ($newValue as $newValuePart) {
|
|
|
|
if ($c_p < 2) $newValueStr .= '-' . $newValuePart;
|
|
|
|
else $newValueStr = $newValuePart.$newValueStr;
|
|
|
|
$c_p++;
|
|
|
|
}
|
|
|
|
array_push($fields_newValues, $newValueStr);
|
|
|
|
}
|
|
|
|
else array_push($fields_newValues, $newValue);
|
|
|
|
}
|
|
|
|
else array_push($fields_newValues, $this->data['User']['password']);
|
|
|
|
}
|
|
|
|
// compare
|
|
|
|
$fields_result_str = '';
|
|
|
|
$c = 0;
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
if ($fields_oldValues[$c] != $fields_newValues[$c]) {
|
|
|
|
if($field != 'confirm_password') $fields_result_str = $fields_result_str. ', '.$field.' ('.$fields_oldValues[$c]. ') => ('.$fields_newValues[$c].')';
|
|
|
|
}
|
|
|
|
$c++;
|
|
|
|
}
|
|
|
|
$fields_result_str = substr($fields_result_str, 2);
|
2012-08-23 10:25:14 +02:00
|
|
|
$this->extraLog("edit", "user", $fields_result_str); // TODO Audit, check: modify User
|
2012-06-28 17:24:12 +02:00
|
|
|
// TODO Audit, extraLog, fields compare END
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->Session->setFlash(__('The user has been saved'));
|
2012-04-02 23:00:41 +02:00
|
|
|
$this->_refreshAuth(); // in case we modify ourselves
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
|
|
|
|
}
|
|
|
|
} else {
|
2012-04-02 17:21:17 +02:00
|
|
|
$this->User->recursive=0;
|
|
|
|
$this->User->read(null, $id);
|
|
|
|
$this->User->set('password', '');
|
|
|
|
$this->request->data = $this->User->data;
|
2012-04-04 18:32:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
2012-06-28 17:24:12 +02:00
|
|
|
// TODO ACL CLEANUP combobox for orgs
|
|
|
|
$org_ids = array('ADMIN', 'NCIRC','Other MOD');
|
|
|
|
$org_ids = $this->_arrayToValuesIndexArray($org_ids);
|
|
|
|
$this->set('org_ids',compact('org_ids'));
|
|
|
|
// XXX ACL, Groups in Users
|
|
|
|
$groups = $this->User->Group->find('list');
|
|
|
|
$this->set(compact('groups'));
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* admin_delete method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function admin_delete($id = null) {
|
|
|
|
if (!$this->request->is('post')) {
|
|
|
|
throw new MethodNotAllowedException();
|
|
|
|
}
|
|
|
|
$this->User->id = $id;
|
|
|
|
if (!$this->User->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid user'));
|
|
|
|
}
|
|
|
|
if ($this->User->delete()) {
|
|
|
|
$this->Session->setFlash(__('User deleted'));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
$this->Session->setFlash(__('User was not deleted'));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function login() {
|
|
|
|
if ($this->Auth->login()) {
|
2012-06-28 17:24:12 +02:00
|
|
|
$this->extraLog("login"); // TODO Audit, extraLog, check: customLog i.s.o. extraLog, no auth user?: $this->User->customLog('login', $this->Auth->user('id'), array('title' => '','user_id' => $this->Auth->user('id'),'email' => $this->Auth->user('email'),'org' => 'IN2'));
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->redirect($this->Auth->redirect());
|
|
|
|
} else {
|
2012-07-11 10:19:57 +02:00
|
|
|
// don't display authError before first login attempt
|
|
|
|
if (str_replace("//","/",$this->webroot.$this->Session->read('Auth.redirect')) == $this->webroot && $this->Session->read('Message.auth.message') == $this->Auth->authError) {
|
|
|
|
$this->Session->delete('Message.auth');
|
|
|
|
}
|
|
|
|
// don't display "invalid user" before first login attempt
|
2012-04-02 11:37:32 +02:00
|
|
|
if($this->request->is('post')) $this->Session->setFlash(__('Invalid username or password, try again'));
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function routeafterlogin() {
|
|
|
|
// Terms and Conditions Page
|
|
|
|
if (!$this->Auth->user('termsaccepted')) {
|
|
|
|
$this->redirect(array('action' => 'terms'));
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
// News page
|
2012-06-28 17:24:12 +02:00
|
|
|
$new_newsdate = new DateTime("2012-03-27"); // TODO general, fixed odd date??
|
2012-03-15 15:06:45 +01:00
|
|
|
$newsdate = new DateTime($this->Auth->user('newsread'));
|
|
|
|
if ($new_newsdate > $newsdate) {
|
|
|
|
$this->redirect(array('action' => 'news'));
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
// Events list
|
|
|
|
$this->redirect(array('controller' => 'events', 'action' => 'index'));
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function logout() {
|
2012-06-28 17:24:12 +02:00
|
|
|
$this->extraLog("logout"); // TODO Audit, extraLog, check: customLog i.s.o. extraLog, $this->User->customLog('logout', $this->Auth->user('id'), array());
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->Session->setFlash('Good-Bye');
|
|
|
|
$this->redirect($this->Auth->logout());
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function resetauthkey($id = null) {
|
|
|
|
if (!$id) {
|
|
|
|
$this->Session->setFlash(__('Invalid id for user', true), 'default', array(), 'error');
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
}
|
|
|
|
if ('me' == $id ) $id = $this->Auth->user('id');
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-20 14:57:52 +01:00
|
|
|
// Replaced by isAuthorized
|
|
|
|
// // only allow reset key for own account, except for admins
|
|
|
|
// if (!$this->_isAdmin() && $id != $this->Auth->user('id')) {
|
|
|
|
// throw new ForbiddenException('Not authorized to reset the key for this user');
|
|
|
|
// }
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
// reset the key
|
|
|
|
$this->User->id = $id;
|
|
|
|
$newkey = $this->User->generateAuthKey();
|
|
|
|
$this->User->saveField('authkey', $newkey);
|
|
|
|
$this->Session->setFlash(__('New authkey generated.', true));
|
2012-03-20 15:44:39 +01:00
|
|
|
$this->_refreshAuth();
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->redirect($this->referer());
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function memberslist() {
|
2012-03-26 19:56:44 +02:00
|
|
|
$this->loadModel('Attribute');
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->loadModel('Event');
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
// Orglist
|
|
|
|
$fields = array('User.org', 'count(User.id) as `num_members`');
|
|
|
|
$params = array('recursive' => 0,
|
|
|
|
'fields' => $fields,
|
|
|
|
'group' => array('User.org'),
|
|
|
|
'order' => array('User.org'),
|
|
|
|
);
|
|
|
|
$orgs = $this->User->find('all', $params);
|
|
|
|
$this->set('orgs', $orgs);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
// What org posted what type of attribute
|
|
|
|
$this->loadModel('Attribute');
|
|
|
|
$fields = array('Event.org', 'Attribute.type', 'count(Attribute.type) as `num_types`');
|
2012-03-15 15:06:45 +01:00
|
|
|
$params = array('recursive' => 0,
|
|
|
|
'fields' => $fields,
|
2012-03-26 19:56:44 +02:00
|
|
|
'group' => array('Attribute.type', 'Event.org'),
|
2012-03-15 15:06:45 +01:00
|
|
|
'order' => array('Event.org', 'num_types DESC'),
|
|
|
|
);
|
2012-03-26 19:56:44 +02:00
|
|
|
$types_histogram = $this->Attribute->find('all', $params);
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->set('types_histogram', $types_histogram);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-21 10:34:22 +01:00
|
|
|
// Nice graphical histogram
|
2012-03-26 19:56:44 +02:00
|
|
|
$this->loadModel('Attribute');
|
2012-05-31 17:12:26 +02:00
|
|
|
$sig_types = array_keys($this->Attribute->type_definitions);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-21 10:34:22 +01:00
|
|
|
$graph_fields = '';
|
2012-06-11 11:40:31 +02:00
|
|
|
foreach ($sig_types as &$sig_type) {
|
2012-03-21 10:34:22 +01:00
|
|
|
if ($graph_fields != "") $graph_fields .= ", ";
|
|
|
|
$graph_fields .= "'".$sig_type."'";
|
|
|
|
}
|
|
|
|
$this->set('graph_fields', $graph_fields);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-21 10:34:22 +01:00
|
|
|
$replace = array('-', '|');
|
|
|
|
$graph_data=array();
|
|
|
|
$prev_row_org = "";
|
|
|
|
$i = -1;
|
2012-06-11 11:40:31 +02:00
|
|
|
foreach ($types_histogram as &$row) {
|
2012-03-21 10:34:22 +01:00
|
|
|
if ($prev_row_org != $row['Event']['org']) {
|
|
|
|
$i++; $graph_data[] = "";
|
2012-03-26 19:56:44 +02:00
|
|
|
$prev_row_org = $row['Event']['org'];
|
2012-03-21 10:34:22 +01:00
|
|
|
$graph_data[$i] .= "org: '".$row['Event']['org']."'";
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
$graph_data[$i] .= ', '.str_replace($replace, "_", $row['Attribute']['type']).': '.$row[0]['num_types'];
|
2012-03-21 10:34:22 +01:00
|
|
|
}
|
|
|
|
$this->set('graph_data', $graph_data);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function terms() {
|
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
$this->User->id = $this->Auth->user('id');
|
|
|
|
$this->User->saveField('termsaccepted', true);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
$this->_refreshAuth(); // refresh auth info
|
|
|
|
$this->Session->setFlash(__('You accepted the Terms and Conditions.'));
|
|
|
|
$this->redirect(array('action' => 'routeafterlogin'));
|
|
|
|
}
|
|
|
|
$this->set('termsaccepted', $this->Auth->user('termsaccepted'));
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function news() {
|
|
|
|
$this->User->id = $this->Auth->user('id');
|
|
|
|
$this->User->saveField('newsread', date("Y-m-d"));
|
|
|
|
$this->_refreshAuth(); // refresh auth info
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-06-28 17:24:12 +02:00
|
|
|
public function extraLog($action = null, $description = null, $fields_result = null) { // TODO move audit to AuditsController?
|
|
|
|
// new data
|
|
|
|
$user_id = $this->Auth->user('id');
|
|
|
|
$model = 'User';
|
|
|
|
$model_id = $this->Auth->user('id');
|
2012-08-23 10:25:14 +02:00
|
|
|
if ($action == 'login') {
|
|
|
|
$description = "User (". $this->Auth->user('id')."): " .$this->data['User']['email'];
|
|
|
|
} elseif ($action == 'logout') {
|
|
|
|
$description = "User (". $this->Auth->user('id')."): " .$this->Auth->user('email');
|
|
|
|
} else { // edit
|
|
|
|
$description = "User (". $this->User->id."): " .$this->data['User']['email'];
|
|
|
|
}
|
2012-06-28 17:24:12 +02:00
|
|
|
|
2012-08-23 10:25:14 +02:00
|
|
|
// query
|
|
|
|
$this->Log = ClassRegistry::init('Log');
|
|
|
|
$this->Log->create();
|
|
|
|
$this->Log->save(array(
|
|
|
|
'org' => $this->Auth->user('org'),
|
|
|
|
'email' => $this->Auth->user('email'),
|
|
|
|
'action' => $action,
|
|
|
|
'title' => $description,
|
|
|
|
'change' => $fields_result));
|
|
|
|
|
2012-06-28 17:24:12 +02:00
|
|
|
// write to syslogd as well
|
2012-08-22 14:05:39 +02:00
|
|
|
App::import('Lib', 'SysLog.SysLog');
|
2012-06-28 17:24:12 +02:00
|
|
|
$syslog = new SysLog();
|
|
|
|
if ($fields_result) $syslog->write('notice', $description.' -- '.$action.' -- '.$fields_result);
|
|
|
|
else $syslog->write('notice', $description.' -- '.$action);
|
|
|
|
}
|
|
|
|
|
|
|
|
// used for fields_before and fields for audit
|
|
|
|
public function arrayCopy( array $array ) {
|
|
|
|
$result = array();
|
|
|
|
foreach( $array as $key => $val ) {
|
|
|
|
if( is_array( $val ) ) {
|
|
|
|
$result[$key] = arrayCopy( $val );
|
|
|
|
} elseif ( is_object( $val ) ) {
|
|
|
|
$result[$key] = clone $val;
|
|
|
|
} else {
|
|
|
|
$result[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setgroupid($fk = '2') {
|
|
|
|
$params = array(
|
|
|
|
'conditions' => array('User.group_id' => ''),
|
|
|
|
'recursive' => 0,
|
|
|
|
'fields' => array('User.id'),
|
|
|
|
);
|
|
|
|
$users = $this->User->find('all', $params);
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$this->User->id = $user['User']['id'];
|
|
|
|
$this->User->saveField('group_id', $fk);
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|