piler/webui/controller/user/settings.php

118 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2012-02-08 23:14:28 +01:00
<?php
class ControllerUserSettings extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "user/settings.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$session = Registry::get('session');
2012-02-08 23:14:28 +01:00
$db = Registry::get('db');
$this->load->model('user/auth');
$this->load->model('user/prefs');
2013-01-05 16:42:36 +01:00
$this->load->model('user/user');
$this->load->model('group/group');
2012-02-08 23:14:28 +01:00
require(DIR_BASE . 'system/helper/PHPGangsta_GoogleAuthenticator.php');
$this->data['ga'] = $this->model_user_prefs->get_ga_settings($session->get('username'));
2012-09-06 15:27:20 +02:00
$this->document->title = $this->data['text_settings'];
2013-04-17 11:37:01 +02:00
2013-01-05 16:42:36 +01:00
$d = $r = '';
$auditemails = $auditdomains = $auditgroups = $auditfolders = '';
2013-04-17 11:37:01 +02:00
2013-11-18 19:24:33 +01:00
$auditemails = implode(", ", $session->get("emails"));
$_auditdomains = $session->get("auditdomains");
foreach($_auditdomains as $d) {
$auditdomains .= ', ' . $d;
2013-01-05 16:42:36 +01:00
}
$auditdomains = preg_replace("/^,\s/", "", $auditdomains);
2014-09-09 22:07:32 +02:00
$auditgroups = preg_replace("/\n/", ", ", $this->model_group_group->get_groups_by_email($session->get("emails")));
2013-11-18 19:24:33 +01:00
$folders = $session->get("folders");
2013-04-17 11:37:01 +02:00
2013-11-18 19:24:33 +01:00
foreach ($folders as $r) {
$auditfolders .= ', ' . $r;
2013-01-05 16:42:36 +01:00
}
$auditfolders = preg_replace("/^,\s/", "", $auditfolders);
2013-04-17 11:37:01 +02:00
2013-01-05 16:42:36 +01:00
if($auditemails) { $this->data['emails'] = $auditemails; } else { $this->data['emails'] = $this->data['text_none_found']; }
if($auditdomains) { $this->data['domains'] = $auditdomains; } else { $this->data['domains'] = $this->data['text_none_found']; }
if($auditgroups) { $this->data['groups'] = $auditgroups; } else { $this->data['groups'] = $this->data['text_none_found']; }
if($auditfolders) { $this->data['folders'] = $auditfolders; } else { $this->data['folders'] = $this->data['text_none_found']; }
2012-02-08 23:14:28 +01:00
if(isset($this->request->post['pagelen']) && isset($this->request->post['theme'])) {
2012-02-08 23:14:28 +01:00
$this->model_user_prefs->set_user_preferences(Registry::get('username'), $this->request->post);
AUDIT(ACTION_CHANGE_USER_SETTINGS, '', '', '', 'pagelen:' . $this->request->post['pagelen'] . ', theme:' . $this->request->post['theme'] . ', lang:' . $this->request->post['lang']);
2012-02-08 23:14:28 +01:00
if(isAdminUser() == 1) {
header("Location: " . SITE_URL . "index.php?route=health/health");
return;
}
header("Location: " . SITE_URL . "search.php");
2012-02-08 23:14:28 +01:00
return;
}
if($this->request->server['REQUEST_METHOD'] == 'POST' && PASSWORD_CHANGE_ENABLED == 1 && $this->validate() == true) {
2012-06-22 15:22:02 +02:00
if($this->model_user_auth->change_password(Registry::get('username'), $this->request->post['password']) == 1) {
2012-02-08 23:14:28 +01:00
$this->data['x'] = $this->data['text_password_changed'];
}
else {
$this->data['x'] = $this->data['text_failed_to_change_password'];
}
}
$this->data['page_len'] = get_page_length();
2013-11-18 19:24:33 +01:00
$this->data['theme'] = $session->get("theme");
$this->data['lang'] = $session->get("lang");
2012-02-08 23:14:28 +01:00
$this->render();
}
private function validate() {
if(!isset($this->request->post['password']) || !isset($this->request->post['password2']) ) {
$this->error['password'] = $this->data['text_missing_password'];
}
if(strlen(@$this->request->post['password']) < MIN_PASSWORD_LENGTH || strlen(@$this->request->post['password2']) < MIN_PASSWORD_LENGTH) {
$this->error['password'] = $this->data['text_invalid_password'];
}
if($this->request->post['password'] != $this->request->post['password2']) {
$this->error['password'] = $this->data['text_password_mismatch'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>