Changeset 893 for trunk/Modules/User


Ignore:
Timestamp:
Mar 6, 2023, 1:48:45 AM (21 months ago)
Author:
chronos
Message:
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
Location:
trunk/Modules/User
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/Options.php

    r892 r893  
    55  function UserOptionsFrom()
    66  {
     7    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    78    $Output = '<form action="'.$this->System->Link('/options/?action=save').'" method="post">
    89    <fieldset><legend>'.T('User settings').'</legend>
    910    <table>
    10     <tr><td>'.T('E-mail').':</td><td><input type="text" name="Email" value="'.$this->System->User->Email.'" /></td></tr>
     11    <tr><td>'.T('E-mail').':</td><td><input type="text" name="Email" value="'.$User->Email.'" /></td></tr>
    1112    <tr><td>'.T('Original password').':</td><td><input type="password" name="OldPass" /></td></tr>
    1213    <tr><td>'.T('New password').':</td><td><input type="password" name="NewPass" /></td></tr>
    1314    <tr><td>'.T('New password confirmation').': </td><td><input type="password" name="NewPass2" /></td></tr>
    14     <tr><td>'.T('I will translate normally to').': </td><td>'.WriteLanguages($this->System->User->Language).'</td></tr>
     15    <tr><td>'.T('I will translate normally to').': </td><td>'.WriteLanguages($User->Language).'</td></tr>
    1516    <tr><td>'.T('After save translation redirect to').': </td><td>';
    1617    $Output .= '<select name="redirecting">'.
    1718      '<option value="0">'.T('Nowhere').'</option>'.
    1819      '<option value="1"';
    19     if ($this->System->User->Redirecting == '1') $Output .= ' selected="selected"';
     20    if ($User->Redirecting == '1') $Output .= ' selected="selected"';
    2021    $Output .= '>'.T('To untranslated').'</option>';
    2122    $Output .= '<option value="2"';
    22     if ($this->System->User->Redirecting == '2') $Output .= ' selected="selected"';
     23    if ($User->Redirecting == '2') $Output .= ' selected="selected"';
    2324    $Output .= '>'.T('To next translation').'</option>';
    2425    $Output .= '<option value="3"';
    25     if ($this->System->User->Redirecting == '3') $Output .= ' selected="selected"';
     26    if ($User->Redirecting == '3') $Output .= ' selected="selected"';
    2627    $Output .= '>'.T('To previous translation').'</option>';
    2728    $Output .= '</select>';
    2829
    2930    $Output .= '</td></tr>'.
    30       '<tr><td>'.T('Preferred client version').': </td><td>'.ClientVersionSelection($this->System->User->PreferredVersion).'</td></tr>'.
     31      '<tr><td>'.T('Preferred client version').': </td><td>'.ClientVersionSelection($User->PreferredVersion).'</td></tr>'.
    3132      '<tr><td>'.T('Public profile text').':</td><td>'.
    32       '<textarea name="info" cols="60" rows="10">'.htmlspecialchars($this->System->User->Info).'</textarea></td></tr>';
     33      '<textarea name="info" cols="60" rows="10">'.htmlspecialchars($User->Info).'</textarea></td></tr>';
    3334
    3435    $Output .= '<tr><td>';
     
    4041      $Query = 'SELECT * FROM `UserTag` '.
    4142      //'LEFT JOIN `UserTagType` ON `UserTagType`.`ID` = `UserTag`.`UserTagType` '.
    42       'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     43      'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
    4344      $DbResult2 = $this->Database->query($Query);
    4445      if ($DbResult2->num_rows != 0) $checked = true;
     
    6465    {
    6566      $Output .= '<option value="'.$LineTeam['Id'].'"';
    66       if ($LineTeam['Id'] == $this->System->User->Team) $Output .= ' selected="selected"';
     67      if ($LineTeam['Id'] == $User->Team) $Output .= ' selected="selected"';
    6768      $Output .= '>'.htmlspecialchars($LineTeam['Name']).'</option>';
    6869    }
     
    7778  {
    7879    $Output = '';
     80    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    7981    if (array_key_exists('Email', $_POST))
    8082    {
     
    9496        if ($NewPass == $NewPass2)
    9597        {
    96           $DbResult = $this->System->Database->query('SELECT `Pass`, '.$this->System->User->CryptPasswordSQL('"'.$OldPass.'"', '`Salt`').' AS `Hash` FROM `User` WHERE `ID`= '.$this->System->User->Id);
     98          $DbResult = $this->System->Database->query('SELECT `Pass`, '.$User->CryptPasswordSQL('"'.$OldPass.'"', '`Salt`').' AS `Hash` FROM `User` WHERE `ID`= '.$User->Id);
    9799          $DbRow = $DbResult->fetch_assoc();
    98100          if ($DbRow['Hash'] == $DbRow['Pass'])
    99101          {
    100102            // Update password
    101             $Salt = $this->System->User->GetPasswordSalt();
    102             $this->Database->query('UPDATE `User` SET `Pass` = '.$this->System->User->CryptPasswordSQL('"'.$NewPass.'"', '"'.$Salt.'"').', `Salt`="'.$Salt.'" WHERE `ID` = '.$this->System->User->Id);
     103            $Salt = $User->GetPasswordSalt();
     104            $this->Database->query('UPDATE `User` SET `Pass` = '.$User->CryptPasswordSQL('"'.$NewPass.'"', '"'.$Salt.'"').', `Salt`="'.$Salt.'" WHERE `ID` = '.$User->Id);
    103105            $Output .= ShowMessage('Heslo změněno.');
    104106          } else $Output .= ShowMessage('Staré heslo neodpovídá.', MESSAGE_CRITICAL);
     
    113115        {
    114116          $Query = 'SELECT * FROM `UserTag` '.
    115             'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     117            'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
    116118          $DbResult2 = $this->Database->query($Query);
    117119          if ($DbResult2->num_rows == 0)
    118120          {
    119121            $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
    120               'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
     122              'VALUES (NULL, '.$UserTag['ID'].' , '.($User->Id * 1).')';
    121123            $DbResult2 = $this->Database->query($Query);
    122124          }
     
    124126        {
    125127          $Query = 'DELETE FROM `UserTag` '.
    126             'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     128            'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
    127129          $DbResult2 = $this->Database->query($Query);
    128130        }
    129131      }
    130132
    131       $this->Database->update('User', '`ID` = '.$this->System->User->Id, array('Email' => $Email,
     133      $this->Database->update('User', '`ID` = '.$User->Id, array('Email' => $Email,
    132134        'Language' => $Language, 'Redirecting' => $Redirecting, 'Info' => $Info,
    133135        'PreferredVersion' => $PreferredVersion));
    134       $Output .= ShowMessage('Úprava nastavení proběhla v pořádku, Email: <b>'.$Email.'</b> Uživatel: <b>'.$this->System->User->Name.'</b>');
     136      $Output .= ShowMessage('Úprava nastavení proběhla v pořádku, Email: <b>'.$Email.'</b> Uživatel: <b>'.$User->Name.'</b>');
    135137      $this->System->ModuleManager->Modules['Log']->WriteLog('Úprava nastavení!', LOG_TYPE_USER);
    136       $this->System->User->Load();
     138      $User->Load();
    137139    } else $Output .= ShowMessage('Nezadány údaje.', MESSAGE_CRITICAL);
    138140    return $Output;
     
    143145    $this->Title = T('User settings');
    144146    $Output = '';
    145     if ($this->System->User->Licence(LICENCE_USER))
     147    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     148    if ($User->Licence(LICENCE_USER))
    146149    {
    147150      if (array_key_exists('action', $_GET) and ($_GET['action'] == 'save'))
  • trunk/Modules/User/Profile.php

    r892 r893  
    55  function SendMail()
    66  {
     7    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    78    $Output = '';
    89    if (array_key_exists('text', $_POST))
    9     if ($this->System->User->Licence(LICENCE_ADMIN))
     10    if ($User->Licence(LICENCE_ADMIN))
    1011    {
    1112      $Text = $_POST['text'];
     
    1617        'Text: <strong>'.$Text.'</strong><br />';
    1718
    18       if (@mail($Email, $Subject, $Text, 'From: '.$this->System->Config['Web']['AdminEmail'].
    19         '\nReply-To: '.$this->System->Config['Web']['AdminEmail'].'\nX-Mailer: PHP/'))
     19      if (@mail($Email, $Subject, $Text, 'From: '.Core::Cast($this->System)->Config['Web']['AdminEmail'].
     20        '\nReply-To: '.Core::Cast($this->System)->Config['Web']['AdminEmail'].'\nX-Mailer: PHP/'))
    2021      {
    2122        $Output .= ShowMessage(T('Message was sent'));
     
    2930  {
    3031    $Output = '';
     32    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    3133    $Filter = ' WHERE `Export`.`User` = '.($_GET['user'] * 1);
    3234    $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` '.$Filter);
     
    6163      $Action = '<a href="'.$this->System->Link('/export/?Action=View&amp;ExportId='.$Export['Id'].'&amp;Tab=0').'">'.T('Show').'</a> '.
    6264        '<a href="'.$this->System->Link('/export/?Action=View&amp;ExportId='.$Export['Id'].'&amp;Tab=7').'">'.T('Export').'</a>';
    63       if ($Export['User'] == $this->System->User->Id) $Action .= ' <a href="?Action=Delete&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Really remove item?').'\');">'.T('Remove').'</a>';
    64       if ($this->System->User->Id != null) $Action .= ' <a href="'.$this->System->Link('/export/?Action=Clone&amp;ExportId='.$Export['Id']).'" onclick="return confirmAction(\''.T('Really clone item?').'\');">'.T('Clone').'</a>';
     65      if ($Export['User'] == $User->Id) $Action .= ' <a href="?Action=Delete&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Really remove item?').'\');">'.T('Remove').'</a>';
     66      if ($User->Id != null) $Action .= ' <a href="'.$this->System->Link('/export/?Action=Clone&amp;ExportId='.$Export['Id']).'" onclick="return confirmAction(\''.T('Really clone item?').'\');">'.T('Clone').'</a>';
    6567      $Output .= '<tr><td>'.HumanDate($Export['TimeCreate']).'</td>'.
    6668        '<td>'.htmlspecialchars($Export['Title']).'</td>'.
     
    9597          $DbRow['TablePrefix'].'` AS `T` '.
    9698          'WHERE (`T`.`Complete` = 1) AND '.
    97           '(`T`.`Language` != '.$this->System->Config['OriginalLanguage'].') AND '.
     99          '(`T`.`Language` != '.Core::Cast($this->System)->Config['OriginalLanguage'].') AND '.
    98100          '(`T`.`User` = '.($_GET['user'] * 1).') ORDER BY `T`.`ModifyTime` DESC LIMIT '.
    99101          $Count.') AS `T`';
     
    139141  {
    140142    $Output = '';
     143    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    141144    $Query = 'SELECT `User`.`Name`, `UserTrace`.`LastLogin`, `UserTrace`.`LastIP`, '.
    142145      '`User`.`Email`, `UserTrace`.`UserAgent`, `User`.`PreferredVersion`, '.
     
    190193        '</tr></table>';
    191194      $Output .= '<br />'.$this->ShowLastForum().'<br />';
    192       if ($this->System->User->Licence(LICENCE_MODERATOR))
     195      if ($User->Licence(LICENCE_MODERATOR))
    193196      {
    194197        $Output .= '<fieldset><legend>Moderování</legend>';
     
    239242          '<input type="text" name="email" value="'.$UserLine['Email'].'" /><br/>'.
    240243          'Předmět:'.
    241           '<input type="text" name="subject" value="'.$this->System->Config['Web']['Title'].'" />'.
     244          '<input type="text" name="subject" value="'.Core::Cast($this->System)->Config['Web']['Title'].'" />'.
    242245          '<br />'.
    243246          '<textarea name="text" rows="20" cols="62">'.
    244247          ''."\n".
    245           'S pozdravem '.$this->System->User->Name."\n".
     248          'S pozdravem '.$User->Name."\n".
    246249          '--------------------------------------------------------'."\n".
    247           $this->System->Config['Web']['Title'].' '.$this->System->Config['Web']['Host'].$this->System->Link('/')."\n".
     250          Core::Cast($this->System)->Config['Web']['Title'].' '.Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/')."\n".
    248251          '</textarea><br/>'.
    249252          '<input type="submit" value="Odeslat" />'.
  • trunk/Modules/User/Registration.php

    r888 r893  
    8686  function CheckRegistration()
    8787  {
    88     global $Config;
    89 
    9088    $Output = '';
     89    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    9190    $ShowForm = true;
    9291
     
    114113        if (($UserName != '') and ($Pass != '') and ($Pass2 != ''))
    115114        {
    116           if (!in_array(strtolower($UserName), $Config['ForbiddedUserNames']))
     115          if (!in_array(strtolower($UserName), Core::Cast($this->System)->Config['ForbiddedUserNames']))
    117116          {
    118117            if ($Pass == $Pass2)
     
    121120              $Line = $DbResult->fetch_row();
    122121              if (!$Line)
    123               {
     122              {               
    124123                if ($Team == 0) $Team = 'NULL';
    125                 $this->System->User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
     124                $User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
    126125                $Output .= ShowMessage(T('Registration was successful'));
    127126                $Output .= 'Přečtěte si pozorně <a href="'.$this->System->Link('/info/').'">pokyny pro překladání</a> a můžete pak hned začít překládat.';
    128                 $this->System->User->Login($UserName, $Pass);
     127                $User->Login($UserName, $Pass);
    129128                $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel se zaregistroval: '.$UserName, LOG_TYPE_USER);
    130129                $ShowForm = false;
     
    136135                if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
    137136                  $Query = 'SELECT * FROM `UserTag` '.
    138                   'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     137                  'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
    139138                  $DbResult2 = $this->Database->query($Query);
    140139                  if ($DbResult2->num_rows == 0) {
    141140                    $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
    142                     'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
     141                    'VALUES (NULL, '.$UserTag['ID'].' , '.($User->Id * 1).')';
    143142                    $DbResult2 = $this->Database->query($Query);
    144143                  }
    145144                } else {
    146145                  $Query = 'DELETE FROM `UserTag` '.
    147                   'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     146                  'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
    148147                  $DbResult2 = $this->Database->query($Query);
    149148                }
  • trunk/Modules/User/User.php

    r892 r893  
    11<?php
    22
     3include_once(dirname(__FILE__).'/ModuleUser.php');
    34include_once(dirname(__FILE__).'/UserList.php');
    45include_once(dirname(__FILE__).'/Options.php');
    56include_once(dirname(__FILE__).'/Registration.php');
    67include_once(dirname(__FILE__).'/Profile.php');
    7 
    8 class ModuleUser extends Module
    9 {
    10   function __construct(System $System)
    11   {
    12     parent::__construct($System);
    13     $this->Name = 'User';
    14     $this->Version = '1.1';
    15     $this->Creator = 'Chronos';
    16     $this->License = 'GNU/GPL';
    17     $this->Description = 'User and permission management';
    18     $this->Dependencies = array();
    19   }
    20 
    21   function DoStart(): void
    22   {
    23     $this->System->User = new User($this->System);
    24     $this->System->RegisterPage(['users'], 'PageUserList');
    25     $this->System->RegisterPage(['options'], 'PageUserOptions');
    26     $this->System->RegisterPage(['registration'], 'PageUserRegistration');
    27     $this->System->RegisterPage(['user'], 'PageUserProfile');
    28     $this->System->RegisterPage(['login'], 'PageUserLogin');
    29     Core::Cast($this->System)->RegisterMenuItem(array(
    30       'Title' => T('Translators'),
    31       'Hint' => 'Seznam registrovaných uživatelů',
    32       'Link' => $this->System->Link('/users/'),
    33       'Permission' => LICENCE_ANONYMOUS,
    34       'Icon' => '',
    35     ), 0);
    36     if (array_key_exists('Search', $this->System->ModuleManager->Modules))
    37       $this->System->ModuleManager->Modules['Search']->RegisterSearch('user',
    38       T('Translators'), array('Name'), '`User`', $this->System->Link('/users/?search='));
    39       Core::Cast($this->System)->RegisterPageBarItem('Top', 'User', array($this, 'TopBarCallback'));
    40       Core::Cast($this->System)->RegisterPageBarItem('Left', 'User', array($this, 'ShowOnlineList'));
    41   }
    42 
    43   function ShowOnlineList()
    44   {
    45     $Output = T('Online translators').':<br />';
    46     $DbResult = $this->System->Database->query('SELECT * FROM ('.
    47       'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '.
    48       'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '.
    49       'WHERE (`ActivityTime` >= NOW() - 300) '.
    50       'ORDER BY `ActivityTime` DESC ) AS `T` GROUP BY `Name`');
    51     while ($DbUser = $DbResult->fetch_assoc())
    52     {
    53       $Name = '<a href="'.$this->System->Link('/user/?user='.$DbUser['ID']).'">'.$DbUser['Name'].'</a>';
    54       $Output .= $Name.'<br />';
    55     }
    56     return $Output;
    57   }
    58 
    59   function TopBarCallback()
    60   {
    61     $Output = '';
    62     if ($this->System->User->Licence(LICENCE_USER))
    63     {
    64       //$DbResult =$this->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team);
    65       //$Team = $DbResult->fetch_assoc();
    66       //$Output .= ''<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>';
    67       $Output .= $this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">'.T('Logout').'</a>'.
    68           ' <a href="'.$this->System->Link('/user/?user='.$this->System->User->Id).'">'.T('My page').'</a>'.
    69           ' <a href="'.$this->System->Link('/options/').'">'.T('Options').'</a>'.
    70           ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='.
    71           $this->System->User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">'.T('Translated').'</a>'.
    72           ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='.
    73           $this->System->User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">'.T('Unfinished').'</a>'.
    74           ' <a title="Nikým nepřeložené texty" href="'.
    75           $this->System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">'.T('Untranslated').'</a>';
    76     } else
    77     {
    78       $Output .= '<a href="'.$this->System->Link('/login/').'">'.T('Login').'</a>&nbsp;'.
    79         '<a href="'.$this->System->Link('/registration/').'">'.T('Registration').'</a>';
    80     }
    81     return $Output;
    82   }
    83 }
    848
    859class PageUserLogin extends Page
     
    11741{
    11842  var $Id;
    119   var $Name;
     43  public string $Name;
    12044  var $Team;
    12145  var $Role;
     
    12650  var $OnlineStateTimeout;
    12751  var $PreferredVersion = 0;
     52  public string $PreferredVersionGame;
     53  public string $Email;
     54  public string $Info;
    12855
    12956  function __construct(System $System)
Note: See TracChangeset for help on using the changeset viewer.