-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp_controller.php
89 lines (75 loc) · 2.83 KB
/
app_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* This file is part of taolin project (http://taolin.fbk.eu)
* Copyright (C) 2008, 2009 FBK Foundation, (http://www.fbk.eu)
* Authors: SoNet Group (see AUTHORS.txt)
*
* Taolin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation version 3 of the License.
*
* Taolin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Taolin. If not, see <http://www.gnu.org/licenses/>.
*
*/
class AppController extends Controller
{
var $components = array('Acl', 'Conf', 'Email', 'Session');
function checkSession()
{
// If the session info hasn't been set...
if (!$this->Session->check('id'))
{
// Force the user to login
$this->redirect('/login');
exit();
}
if ((array_key_exists('admin', $this->params)) || ($this->params['action'] == 'admin')){
if (!$this->Acl->check(array('model' => 'User', 'foreign_key' => $this->Session->read('id')), 'admin')){
echo 'Not allowed';
exit();
}
};
}
function beforeFilter()
{
$action = $this->action;
$id = $this->Session->read('id');
$this->params['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$log = $action.': '.$id.': '.serialize($this->params);
App::import('Controller','Logs');
$logContr = new LogsController;
$logContr->constructClasses();
$logContr->write($log);
$log = str_replace("\n", " ", $log);
$this->log($log, 'stat');
//set json view as default
$this->view = 'Json';
//workaround to pass variables to the pages_controller
$this->Conf->startup($this);
Configure::write('App.name', $this->Conf->get('Site.name'));
Configure::write('App.contactus', $this->Conf->get('Site.admin'));
}
function _sendMail($from, $to, $subject = null, $text, $cc = null, $bcc = null, $template = null, $sendas = null){
$this->Email->from = $from;
$this->Email->to = $to;
if($subject)
$this->Email->subject = $subject;
else
$this->Email->subject = 'Email notification from '.$this->Conf->get('Site.name');
if($sendas)
$this->Email->sendAs = $sendas;
if($template){
$this->Email->template = $template;
return $this->Email->send();
} else {
return $this->Email->send($text);
}
}
}
?>