Changeset 189 for trunk/user.php


Ignore:
Timestamp:
Apr 12, 2009, 5:40:08 PM (15 years ago)
Author:
george
Message:
  • Upraveno: Údaje uživatele jméno a příjmení bylo sloušeno do údaje Zobrazované jméno. Upraveny patřičné sloupce a odkazy ze skriptů.
  • Opraveno: Registrace nových uživatelů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user.php

    r187 r189  
    11<?php
    22
    3 define('NICK_USED', 'Přihlašovací jméno již použito.');
     3define('LOGIN_USED', 'Přihlašovací jméno již použito.');
     4define('NAME_USED', 'Jméno uživatele již použito');
    45define('EMAIL_USED', 'Email je již použitý. Použijte jiný email nebo si můžete nechat zaslat nové heslo na email.');
    56define('USER_REGISTRATED', 'Uživatel registrován. Na zadanou emailovou adresu byl poslán mail s odkazem pro aktivování účtu.');
     
    5152    if($Row['User'] != $this->AnonymousUserId)
    5253    {
    53       $Query = $this->Database->select('User', '*', "Id=".$Row['User']."");
     54      $Query = $this->Database->select('User', '*', 'Id='.$Row['User']);
    5455      $this->User = $Query->fetch_assoc();
    5556      $Result = USER_LOGGED;
    5657    } else
    5758    {
    58       $Query = $this->Database->select('User', '*', "Id=".$this->AnonymousUserId);
     59      $Query = $this->Database->select('User', '*', 'Id='.$this->AnonymousUserId);
    5960      $this->User = $Query->fetch_assoc();
    6061      $Result = USER_NOT_LOGGED;
     
    7475  }
    7576
    76   function Register($Nick, $Password, $Password2, $Email, $FirstName, $SecondName)
     77  function Register($Login, $Password, $Password2, $Email, $Name, $PhoneNumber, $ICQ)
    7778  {
    7879    global $Options, $Config;
    7980
    80     if(($Email == '') || ($Nick == '') || ($Password == '') || ($Password2 == '')) $Result = DATA_MISSING;
     81    if(($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '')  || ($Name == '')) $Result = DATA_MISSING;
    8182    else if($Password != $Password2) $Result = PASSWORDS_UNMATCHED;
    8283    else
    8384    {
    8485      // Je uživatel registrován?
    85       $Query = $this->Database->select('User', '*', 'Name = "'.$Nick.'"');
    86       if($Query->num_rows > 0) $Result = NICK_USED;
     86      $Query = $this->Database->select('User', '*', 'Login = "'.$Login.'"');
     87      if($Query->num_rows > 0) $Result = LOGIN_USED;
    8788      else
    8889      {
    89         $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"');
    90         if($Query->num_rows > 0) $Result = EMAIL_USED;
     90        $Query = $this->Database->select('User', '*', 'Name = "'.$Name.'"');
     91        if($Query->num_rows > 0) $Result = NAME_USED;
    9192        else
    92         {
    93           $this->Database->insert('User', array('Name' => $Nick, 'FirstName' => $FirstName, 'SecondName' => $SecondName, 'Password' => sha1($Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()', 'Locked' => 1));
    94           $UserId = $this->Database->insert_id;
    95                   $this->Database->insert('PermissionUserAssignment', array('User' => $UserId, 'GroupOrOperation' => 1, 'Type' => 'Group'));
     93        {
     94          $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"');
     95          if($Query->num_rows > 0) $Result = EMAIL_USED;
     96          else
     97          {
     98            $this->Database->insert('User', array('Name' => $Name, 'Login' => $Login, 'Password' => sha1($Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()', 'Locked' => 1, 'PhoneNumber' => $PhoneNumber, 'ICQ' => $ICQ));
     99            $UserId = $this->Database->insert_id;
     100                        $this->Database->insert('PermissionUserAssignment', array('User' => $UserId, 'GroupOrOperation' => 2, 'Type' => 'Group'));
    96101         
    97           $Subject = FromUTF8('Registrace nového účtu', 'iso2');
    98           $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Nick."\n<br>Pro dokončení registrace klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.sha1($Password).'">tento odkaz</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte.";
    99           $AdditionalHeaders = "To: ".$Nick." <".$Email.">\n"."From: ".FromUTF8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    100           mail($Email, $Subject, $Message, $AdditionalHeaders);
    101           $Result = USER_REGISTRATED;
    102           $this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Nick);
     102            $Subject = FromUTF8('Registrace nového účtu', 'iso2');
     103            $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Login."\n<br>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.sha1($Password).'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.sha1($Password).'</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte.";
     104            $AdditionalHeaders = "To: ".$Name." <".$Email.">\n"."From: ".FromUTF8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
     105            mail($Email, $Subject, $Message, $AdditionalHeaders);
     106            $Result = USER_REGISTRATED;
     107            $this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);
     108          }
    103109        }
    104110      }
     
    109115  function RegisterConfirm($Id, $Hash)
    110116  {
    111     $DbResult = $this->Database->select('User', 'Id, Name, Password', 'Id = '.$Id);
     117    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
    112118    if($DbResult->num_rows > 0)
    113119    {
     
    117123        $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0));
    118124        $Output = USER_REGISTRATION_CONFIRMED;
    119         $this->System->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Username='.$Row['Name']);
     125        $this->System->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Login='.$Row['Login'].', Id='.$Row['Id']);
    120126      } else $Output = PASSWORDS_UNMATCHED;
    121127    } else $Output = USER_NOT_FOUND;
     
    123129  }
    124130
    125   function Login($Nick, $Password)
     131  function Login($Login, $Password)
    126132  {
    127133    $SID = session_id();
    128     $Query = $this->Database->select('User', '*', 'Name="'.$Nick.'"');
     134    $Query = $this->Database->select('User', '*', 'Login="'.$Login.'"');
    129135    if($Query->num_rows > 0)
    130136    {
     
    138144        // načtení stavu stromu
    139145        $Result = USER_LOGGED_IN;
    140         $this->System->Modules['Log']->NewRecord('User', 'Login', 'Nick='.$Nick.',Host='.gethostbyaddr(GetRemoteAddress()));
     146        $this->System->Modules['Log']->NewRecord('User', 'Login', 'Login='.$Login.',Host='.gethostbyaddr(GetRemoteAddress()));
    141147      }
    142148    } else $Result = USER_NOT_REGISTRED;
     
    149155    $SID = session_id();
    150156    $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $this->AnonymousUserId));
    151     $this->System->Modules['Log']->NewRecord('User', 'Logout', $this->User['Name']);
     157    $this->System->Modules['Log']->NewRecord('User', 'Logout', $this->User['Login']);
    152158    $this->Check();
    153159    return(USER_LOGGED_OUT);
     
    222228  }
    223229
    224   function PasswordRecoveryRequest($Name, $Email)
     230  function PasswordRecoveryRequest($Login, $Email)
    225231  {
    226232    global $Config;
    227233
    228     $DbResult = $this->Database->select('User', 'Name, Id, Email, Password', '`Name`="'.$Name.'" AND `Email`="'.$Email.'"');
     234    $DbResult = $this->Database->select('User', 'Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"');
    229235    if($DbResult->num_rows > 0)
    230236    {
    231237      $Row = $DbResult->fetch_array();
    232       $NewPassword = substr(sha1(strtoupper($Row['Name'])), 0, 7);
     238      $NewPassword = substr(sha1(strtoupper($Row['Login'])), 0, 7);
    233239
    234240      $Subject = 'Obnova hesla';
    235       $Message = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Name']." je: ".$NewPassword."\n<br>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.";
     241      $Message = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Login']." je: ".$NewPassword."\n<br>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.";
    236242      $AdditionalHeaders = "To: ".$Row['Name']." <".$Row['Email'].">\n"."From: ".FromUTF8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    237243      mail($Row['Email'], $Subject, $Message, $AdditionalHeaders);
    238244      $Output = USER_PASSWORD_RECOVERY_SUCCESS;
    239       $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Username='.$Name.',Email='.$Email);
     245      $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email);
    240246    } else $Output = USER_PASSWORD_RECOVERY_FAIL;
    241247    return($Output);
     
    244250  function PasswordRecoveryConfirm($Id, $Hash, $NewPassword)
    245251  {
    246     $DbResult = $this->Database->select('User', 'Id, Name, Password', 'Id = '.$Id);
     252    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
    247253    if($DbResult->num_rows > 0)
    248254    {
    249255      $Row = $DbResult->fetch_array();
    250       $NewPassword2 = substr(sha1(strtoupper($Row['Name'])), 0, 7);
     256      $NewPassword2 = substr(sha1(strtoupper($Row['Login'])), 0, 7);
    251257      if(($NewPassword == $NewPassword2) and ($Hash == $Row['Password']))
    252258      {
    253259        $this->Database->update('User', 'Id='.$Row['Id'], array('Password' => sha1($NewPassword), 'Locked' => 0));
    254260        $Output = USER_PASSWORD_RECOVERY_CONFIRMED;
    255         $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Username='.$Row['Name']);
     261        $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Login='.$Row['Login']);
    256262      } else $Output = PASSWORDS_UNMATCHED;
    257263    } else $Output = USER_NOT_FOUND;
Note: See TracChangeset for help on using the changeset viewer.