openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 5c2dddf1e39241867b0b9904a23f55b3c9ab340e
parent 98ef5d8618aa5292f7bf9a5ec5c16097ada04ca8
Author: Jan Dankert <devnull@localhost>
Date:   Tue, 31 Oct 2017 02:15:07 +0100

Timezone und Sprache für den Benutzer einstellbar machen.

Diffstat:
action/UserAction.class.php | 14++++++++++++++
auth/InternalAuth.class.php | 4++--
db/DbUpdate.class.php | 2+-
db/DbVersion.class.php | 2+-
db/driver/pdo.class.php | 2+-
model/ModelBase.class.php | 17+++++++++++++++++
model/User.class.php | 147++++++++++++++++++++++++++++++++++++-------------------------------------------
model/include.inc.php | 1+
themes/default/templates/user/edit.tpl.src.xml | 21+++++++++++++++++++++
9 files changed, 124 insertions(+), 86 deletions(-)

diff --git a/action/UserAction.class.php b/action/UserAction.class.php @@ -50,6 +50,8 @@ class UserAction extends Action $this->user->ldap_dn = $this->getRequestVar('ldap_dn' ); $this->user->tel = $this->getRequestVar('tel' ); $this->user->desc = $this->getRequestVar('desc' ); + $this->user->language = $this->getRequestVar('language'); + $this->user->timezone = $this->getRequestVar('timezone'); global $conf; if ( @$conf['security']['user']['show_admin_mail'] ) @@ -207,9 +209,21 @@ class UserAction extends Action */ function editView() { + global $conf; $this->setTemplateVars( $this->user->getProperties() ); $this->setTemplateVar( 'allstyles',$this->user->getAvailableStyles() ); + + $this->setTemplateVar('timezone_list',timezone_identifiers_list() ); + + $languages = explode(',',$conf['i18n']['available']); + foreach($languages as $id=>$name) + { + unset($languages[$id]); + $languages[$name] = $name; + } + $this->setTemplateVar('language_list',$languages); + } diff --git a/auth/InternalAuth.class.php b/auth/InternalAuth.class.php @@ -34,7 +34,7 @@ SQL // Benutzer ist nicht vorhanden return false; // Pruefen ob Kennwort mit Datenbank uebereinstimmt - elseif ( $row_user['password'] == $password ) + elseif ( $row_user['password_hash'] == $password ) { // Kennwort stimmt mit Datenbank �berein, aber nur im Klartext. // Das Kennwort muss ge�ndert werden @@ -43,7 +43,7 @@ SQL // Login nicht erfolgreich return false; } - elseif ( Password::check(User::pepperPassword($password),$row_user['password']) ) + elseif ( Password::check(User::pepperPassword($password),$row_user['password_hash'],$row_user['password_algo']) ) { // Die Kennwort-Pruefsumme stimmt mit dem aus der Datenbank �berein. // Juchuu, Login ist erfolgreich. diff --git a/db/DbUpdate.class.php b/db/DbUpdate.class.php @@ -1,6 +1,6 @@ <?php -define('OR_DB_SUPPORTED_VERSION',3); +define('OR_DB_SUPPORTED_VERSION',7); define('OR_DB_STATUS_UPDATE_PROGRESS', 0); define('OR_DB_STATUS_UPDATE_SUCCESS' , 1); diff --git a/db/DbVersion.class.php b/db/DbVersion.class.php @@ -62,7 +62,7 @@ abstract class DbVersion - private function getTableName( $name ) + protected function getTableName( $name ) { return $this->tablePrefix.$name.$this->tableSuffix; } diff --git a/db/driver/pdo.class.php b/db/driver/pdo.class.php @@ -94,7 +94,7 @@ class DB_pdo if ( $erg === false ) { - throw new RuntimeException( 'Could not execute prepared statement "'.$query->src.'": '.implode('/',$this->stmt->errorInfo()) ); + throw new RuntimeException( 'Could not execute prepared statement "'.$query->query.'": '.implode('/',$this->stmt->errorInfo()) ); } return $this->stmt; diff --git a/model/ModelBase.class.php b/model/ModelBase.class.php @@ -0,0 +1,16 @@ +<?php + +class ModelBase +{ + protected function setDatabaseRow( $row ) + { + + } + + public function getProperties() + { + return get_object_vars( $this ); + } +} + +?>+ \ No newline at end of file diff --git a/model/User.class.php b/model/User.class.php @@ -25,7 +25,7 @@ * @author $Author$ * @package openrat.objects */ -class User +class User extends ModelBase { var $userid = 0; var $error = ''; @@ -144,7 +144,7 @@ class User * * @return Array [Projekt-Id] = Projekt-Name */ - function getReadableProjects() + public function getReadableProjects() { $db = db_connection(); @@ -207,7 +207,7 @@ SQL global $conf; $db = db_connection(); - $sql = $db->sql( 'SELECT id,mail,name,password FROM {{user}}'. + $sql = $db->sql( 'SELECT id,mail,name,password_hash FROM {{user}}'. ' WHERE id={userid}' ); $sql->setInt( 'userid',$this->userid ); $row = $sql->getRow( $sql ); @@ -216,14 +216,14 @@ SQL throw new ObjectNotFoundException(); // Zusammensetzen des Tokens - return sha1( $row['password'].$row['name'].$row['id'].$row['mail'] ); + return sha1( $row['password_hash'].$row['name'].$row['id'].$row['mail'] ); } /** * Lesen Benutzer aus der Datenbank. */ - function load() + public function load() { global $conf; $db = db_connection(); @@ -271,67 +271,43 @@ SQL /** * Stellt fest, ob der Benutzer korrekt geladen ist. */ - function isValid() + public function isValid() { return intval($this->userid) > 0; } - // Lesen Benutzer aus der Datenbank - function setDatabaseRow( $row ) + /** + * Lesen Benutzer aus der Datenbank + */ + protected function setDatabaseRow( $row ) { global $conf; - $this->userid = $row['id' ]; - $this->name = $row['name' ]; - $this->style = $row['style' ]; - $this->isAdmin = ( $row['is_admin'] == '1'); - $this->ldap_dn = $row['ldap_dn' ]; - $this->fullname = $row['fullname']; - $this->tel = $row['tel' ]; - $this->mail = $row['mail' ]; - $this->desc = $row['descr' ]; + $this->userid = $row['id' ]; + $this->name = $row['name' ]; + $this->style = $row['style' ]; + $this->isAdmin = ( $row['is_admin'] == '1'); + $this->ldap_dn = $row['ldap_dn' ]; + $this->fullname = $row['fullname']; + $this->tel = $row['tel' ]; + $this->mail = $row['mail' ]; + $this->desc = $row['descr' ]; + $this->language = $row['language']; + $this->timezone = $row['timezone']; + $this->pwExpires = $row['password_expires']; + $this->lastLogin = $row['last_login']; + $this->otpSecret = $row['otp_secret']; + $this->hotp = $row['hotp']; + $this->hotpCount = $row['hotp_counter']; + $this->totp = $row['totp']; if ( $this->fullname == '' ) $this->fullname = $this->name; if ( $this->style == '' ) $this->style = $conf['interface']['style']['default']; - - /* vorerst unbenutzt: - if ( $row['use_ldap'] == '1' ) - { - // Daten aus LDAP-Verzeichnisdienst lesen - - // Verbindung zum LDAP-Server herstellen - $ldap_conn = @ldap_connect( $conf['ldap']['host'],$conf['ldap']['port'] ); - - if ( !$ldap_conn ) - { - logger( 'INFO','cannot connect to LDAP server '.$conf['ldap']['host'].' '.$conf['ldap']['port'] ); - $this->error = 'cannot connect to LDAP server'; - return false; - } - - // Anonymes LDAP-Login versuchen - $ldap_bind = @ldap_bind( $ldap_conn ); - - if ( $ldap_bind ) - { - // Login erfolgreich - $sr = ldap_read( $ldap_conn,$row['ldap_dn'],'(objectclass=*)' ); - - $daten = ldap_get_entries( $ldap_conn,$sr ); - - $this->fullname = $daten[0]['givenName'][0].' '.$daten[0]['sn'][0]; - $this->tel = $daten[0]['telephoneNumber'][0]; - $this->mail = $daten[0]['mail'][0]; - $this->desc = $daten[0]['description'][0]; - } - - } - */ } @@ -379,16 +355,21 @@ SQL { $db = db_connection(); - $sql = $db->sql( 'UPDATE {{user}}'. - ' SET name={name},'. - ' fullname={fullname},'. - ' ldap_dn ={ldap_dn} ,'. - ' tel ={tel} ,'. - ' descr ={desc} ,'. - ' mail ={mail} ,'. - ' style ={style} ,'. - ' is_admin={isAdmin} '. - ' WHERE id={userid}' ); + $sql = $db->sql( <<<SQL + UPDATE {{user}} + SET name={name}, + fullname={fullname}, + ldap_dn ={ldap_dn} , + tel ={tel} , + descr ={desc} , + mail ={mail} , + style ={style} , + language = {language}, + timezone = {timezone}, + is_admin = {isAdmin} + WHERE id={userid} +SQL + ); $sql->setString ( 'name' ,$this->name ); $sql->setString ( 'fullname',$this->fullname); $sql->setString ( 'ldap_dn' ,$this->ldap_dn ); @@ -396,6 +377,8 @@ SQL $sql->setString ( 'desc' ,$this->desc ); $sql->setString ( 'mail' ,$this->mail ); $sql->setString ( 'style' ,$this->style ); + $sql->setString ( 'language',$this->language); + $sql->setString ( 'timezone',$this->timezone); $sql->setBoolean( 'isAdmin' ,$this->isAdmin ); $sql->setInt ( 'userid' ,$this->userid ); @@ -420,7 +403,7 @@ SQL $this->userid = intval($sql->getOne($sql))+1; $sql = $db->sql('INSERT INTO {{user}}'. - ' (id,name,password,ldap_dn,fullname,tel,mail,descr,style,is_admin)'. + ' (id,name,password_hash,ldap_dn,fullname,tel,mail,descr,style,is_admin)'. " VALUES( {userid},{name},'','','','','','','default',0 )" ); $sql->setInt ('userid',$this->userid); $sql->setString('name' ,$this->name ); @@ -521,25 +504,15 @@ SQL * * @return Array Liste der Eigenschaften als assoziatives Array */ - function getProperties() + public function getProperties() { - return Array( 'userid' => $this->userid, - 'id' => $this->userid, - 'fullname'=> $this->fullname, - 'name' => $this->name, - 'ldap_dn' => $this->ldap_dn, - 'tel' => $this->tel, - 'desc' => $this->desc, - 'mail' => $this->mail, - 'style' => $this->style, - 'is_admin'=> $this->isAdmin, - 'isAdmin' => $this->isAdmin ); + return parent::getProperties() + array('id'=>$this->userid,'is_admin'=> $this->isAdmin); } /** - * Setzt ein neues Kennwort f�r diesen Benutzer. + * Setzt ein neues Kennwort fuer diesen Benutzer. * * @param password Kennwortt * @param always true, wenn Kennwort dauerhaft. @@ -548,17 +521,29 @@ SQL { $db = db_connection(); - $sql = $db->sql( 'UPDATE {{user}} SET password={password} '. + $sql = $db->sql( 'UPDATE {{user}} SET password_hash={password},password_algo={algo},password_expires={expires} '. 'WHERE id={userid}' ); if ( $always ) - // Hashsumme für Kennwort erzeugen und speichern. - // Workaround: Hashsumme auf 50 Zeichen kürzen (da die DB-Spalte nicht länger ist) - $sql->setString('password',substr(Password::hash($this->pepperPassword($password)),0,50) ); + { + $algo = Password::bestAlgoAvailable(); + $expire = null; + } else + { // Klartext-Kennwort, der Benutzer muss das Kennwort beim nä. Login ändern. - $sql->setString('password',$password); - + $algo = OR_PASSWORD_ALGO_PLAIN; + $expire = time(); + } + + // Hashsumme für Kennwort erzeugen + if ( $expire == null ) + $sql->setNull('expires'); + else + $sql->setInt('expires',$expire); + + $sql->setInt ('algo' ,$algo ); + $sql->setString('password',Password::hash($this->pepperPassword($password)),$algo ); $sql->setInt ('userid' ,$this->userid ); $sql->query( $sql ); diff --git a/model/include.inc.php b/model/include.inc.php @@ -1,6 +1,7 @@ <?php // Diese Objekte stehen zeitweise in der Sitzung, daher muessen dieser immer geparst werden. +require_once( OR_OBJECTCLASSES_DIR."ModelBase.class.".PHP_EXT ); require_once( OR_OBJECTCLASSES_DIR."Value.class.".PHP_EXT ); require_once( OR_OBJECTCLASSES_DIR."Acl.class.".PHP_EXT ); require_once( OR_OBJECTCLASSES_DIR."Template.class.".PHP_EXT ); diff --git a/themes/default/templates/user/edit.tpl.src.xml b/themes/default/templates/user/edit.tpl.src.xml @@ -45,6 +45,27 @@ <input name="tel"></input> </part> </part> + <part class="line"> + <part class="label"> + <label for="timezone_offset"> + <text key="timezone" /> + </label> + </part> + <part class="input"> + <selectbox name="timezone" list="timezone_list" + addempty="true"></selectbox> + </part> + </part> + <part class="line"> + <part class="label"> + <label for=""> + <text key="language" /> + </label> + </part> + <part class="input"> + <selectbox name="language" list="language_list" addempty="true"></selectbox> + </part> + </part> </group> <group title="message:options"> <part class="line">