Changeset 44

Show
Ignore:
Timestamp:
12/17/05 10:07:41 (3 years ago)
Author:
fabien
Message:

day 17 modifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/schema.xml

    r42 r44  
    4141     <column name="sha1_password" type="varchar" size="40" /> 
    4242     <column name="salt" type="varchar" size="32" /> 
     43     <column name="has_paypal" type="boolean" default="0" /> 
    4344     <column name="created_at" type="timestamp" /> 
    4445   </table> 
  • trunk/data/sql/schema.sql

    r42 r44  
    6464    `sha1_password` VARCHAR(40) ,  
    6565    `salt` VARCHAR(32) ,  
     66    `has_paypal` INTEGER default 0 ,  
    6667    `created_at` DATETIME ,   
    6768    PRIMARY KEY(`id`)) 
  • trunk/frontend/config/routing.yml

    r38 r44  
    3737  url:   /user/:nickname 
    3838  param: { module: user, action: show } 
     39 
     40user_update: 
     41  url:   /update_user 
     42  param: { module: user, action: update } 
    3943 
    4044current_user_profile: 
     
    98102  param: { module: content, action: about } 
    99103 
     104# api 
     105api_question: 
     106  url:   /api/question/:stripped_title 
     107  param: { module: api, action: question } 
     108 
    100109# default rules 
    101110homepage: 
  • trunk/frontend/lib/myLoginValidator.class.php

    r16 r44  
    4747     } 
    4848 
    49      $c = new Criteria(); 
    50      $c->add(UserPeer::NICKNAME, $login); 
    51      $user = UserPeer::doSelectOne($c); 
     49     if ($user = UserPeer::getAuthenticatedUser($login, $password)); 
     50     { 
     51       $this->getContext()->getUser()->signIn($user); 
    5252 
    53      // nickname exists? 
    54      if ($user) 
    55      { 
    56        // password is OK? 
    57        if (sha1($user->getSalt().$password) == $user->getSha1Password()) 
    58        { 
    59          $this->getContext()->getUser()->signIn($user); 
    60  
    61          return true; 
    62        } 
     53       return true; 
    6354     } 
    6455 
  • trunk/frontend/lib/myUser.class.php

    r16 r44  
    2222  public function getSubscriberId() 
    2323  { 
    24     return $this->getAttribute('subscriber_id', '', 'subscriber'); 
     24    if ($this->isAuthenticated()) 
     25    { 
     26      return $this->getAttribute('subscriber_id', '', 'subscriber'); 
     27    } 
     28    else 
     29    { 
     30      return 0; 
     31    } 
    2532  } 
    2633 
    2734  public function getSubscriber() 
    2835  { 
    29     return UserPeer::retrieveByPk($this->getSubscriberId()); 
     36    if ($this->isAuthenticated()) 
     37    { 
     38      return UserPeer::retrieveByPk($this->getSubscriberId()); 
     39    } 
     40    else 
     41    { 
     42      return null; 
     43    } 
    3044  } 
    3145 
    3246  public function getNickname() 
    3347  { 
    34     return $this->getAttribute('nickname', '', 'subscriber'); 
     48    if ($this->isAuthenticated()) 
     49    { 
     50      return $this->getAttribute('nickname', '', 'subscriber'); 
     51    } 
     52    else 
     53    { 
     54      return ''; 
     55    } 
    3556  } 
    3657} 
  • trunk/frontend/modules/user/actions/actions.class.php

    r38 r44  
    5151    else 
    5252    { 
    53       $this->subscriber = UserPeer::retrieveByPk($this->getUser()->getSubscriberId()); 
     53      $this->subscriber = $this->getUser()->getSubscriber(); 
    5454    } 
    5555    $this->forward404Unless($this->subscriber); 
    5656 
    57     $this->interests = $this->subscriber->getInterestsJoinQuestion(); 
    58     $this->answers   = $this->subscriber->getAnswersJoinQuestion(); 
    59     $this->questions = $this->subscriber->getQuestions(); 
    60  
    61     $this->setTitle('askeet! &raquo; '.$this->subscriber->__toString().'\'s profile'); 
     57    $this->setShowVars(); 
     58  } 
     59 
     60  public function executeUpdate() 
     61  { 
     62    if ($this->getRequest()->getMethod() != sfRequest::POST) 
     63    { 
     64      $this->forward404(); 
     65    } 
     66 
     67    $this->subscriber = $this->getUser()->getSubscriber(); 
     68    $this->forward404Unless($this->subscriber); 
     69 
     70    $this->updateUserFromRequest(); 
     71 
     72    // password update 
     73    if ($this->getRequestParameter('password')) 
     74    { 
     75      $this->subscriber->setPassword($this->getRequestParameter('password')); 
     76    } 
     77 
     78    $this->subscriber->save(); 
     79 
     80    $this->redirect('@user_profile?nickname='.$this->subscriber->getNickname()); 
    6281  } 
    6382 
     
    162181    return sfView::SUCCESS; 
    163182  } 
     183 
     184  public function handleErrorUpdate() 
     185  { 
     186    $this->subscriber = $this->getUser()->getSubscriber(); 
     187    $this->forward404Unless($this->subscriber); 
     188 
     189    $this->updateUserFromRequest(); 
     190    $this->setShowVars(); 
     191 
     192    return array('user', 'showSuccess'); 
     193  } 
     194 
     195  private function updateUserFromRequest() 
     196  { 
     197    $this->subscriber->setFirstName($this->getRequestParameter('first_name')); 
     198    $this->subscriber->setLastName($this->getRequestParameter('last_name')); 
     199    $this->subscriber->setEmail($this->getRequestParameter('email')); 
     200    $this->subscriber->setHasPaypal($this->getRequestParameter('has_paypal'), 0); 
     201  } 
     202 
     203  private function setShowVars() 
     204  { 
     205    $this->interests = $this->subscriber->getInterestsJoinQuestion(); 
     206    $this->answers   = $this->subscriber->getAnswersJoinQuestion(); 
     207    $this->questions = $this->subscriber->getQuestions(); 
     208 
     209    $this->setTitle('askeet! &raquo; '.$this->subscriber->__toString().'\'s profile'); 
     210  } 
    164211} 
    165212 
  • trunk/frontend/modules/user/templates/showSuccess.php

    r38 r44  
    1 <?php use_helpers('Date', 'Question', 'Text') ?> 
     1<?php use_helpers('Date', 'Question', 'Text', 'Object') ?> 
    22 
    33<h1><?php echo $subscriber ?>'s profile</h1> 
     4 
     5<?php echo form_tag('user/update', 'class=form') ?> 
     6  <fieldset> 
     7 
     8  <label for="nickname">nickname:</label> 
     9  <strong><?php echo $subscriber->getNickname() ?></strong> 
     10  <br class="clearleft" /> 
     11 
     12  <?php echo form_error('first_name') ?> 
     13  <label for="first_name">first name:</label> 
     14  <?php echo object_input_tag($subscriber, 'getFirstName', 'size=30') ?> 
     15  <br class="clearleft" /> 
     16 
     17  <?php echo form_error('last_name') ?> 
     18  <label for="last_name">last name:</label> 
     19  <?php echo object_input_tag($subscriber, 'getLastName', 'size=30') ?> 
     20  <br class="clearleft" /> 
     21 
     22  <?php echo form_error('email') ?> 
     23  <label for="email">email:</label> 
     24  <?php echo object_input_tag($subscriber, 'getEmail', 'size=30') ?> 
     25  <br class="clearleft" /> 
     26 
     27  <?php echo form_error('has_paypal') ?> 
     28  <label for="has_paypal">paypal account?</label> 
     29  <?php echo object_checkbox_tag($subscriber, 'getHasPaypal') ?> 
     30  <br class="clearleft" /> 
     31 
     32  <?php echo form_error('password') ?> 
     33  <label for="password">password:</label> 
     34  <?php echo input_password_tag('password', '', 'size=30') ?> 
     35  <br class="clearleft" /> 
     36 
     37  <?php echo form_error('password_bis') ?> 
     38  <label for="password_bis">confirm your password:</label> 
     39  <?php echo input_password_tag('password_bis', '', 'size=30') ?> 
     40  <br class="clearleft" /> 
     41 
     42  </fieldset> 
     43 
     44  <div class="right"> 
     45    <?php echo submit_tag('update it') ?> 
     46  </div> 
     47</form> 
     48 
     49<?php if ($subscriber->getHasPaypal()): ?> 
     50  <p>If you appreciated this user's contributions, you can grant him a small donation.</p> 
     51  <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
     52    <input type="hidden" name="cmd" value="_xclick"> 
     53    <input type="hidden" name="business" value="<?php echo $subscriber->getEmail() ?>"> 
     54    <input type="hidden" name="item_name" value="askeet"> 
     55    <input type="hidden" name="return" value="http://www.askeet.com"> 
     56    <input type="hidden" name="no_shipping" value="1"> 
     57    <input type="hidden" name="no_note" value="1"> 
     58    <input type="hidden" name="tax" value="0"> 
     59    <input type="hidden" name="bn" value="PP-DonationsBF"> 
     60    <input type="image" src="http://images.paypal.com/images/x-click-but04.gif" border="0" name="submit" alt="Donate to this user"> 
     61  </form> 
     62<?php endif ?> 
    463 
    564<h3>tags</h3> 
  • trunk/lib/model/UserPeer.php

    r23 r44  
    2828    return self::doSelectOne($c); 
    2929  } 
     30 
     31  public static function getAuthenticatedUser($login, $password) 
     32  { 
     33    $c = new Criteria(); 
     34    $c->add(UserPeer::NICKNAME, $login); 
     35    $user = UserPeer::doSelectOne($c); 
     36 
     37    // nickname exists? 
     38    if ($user) 
     39    { 
     40      // password is OK? 
     41      if (sha1($user->getSalt().$password) == $user->getSha1Password()) 
     42      { 
     43        return $user; 
     44      } 
     45    } 
     46 
     47    return null; 
     48  } 
    3049} 
    3150 
  • trunk/lib/model/map/UserMapBuilder.php

    r16 r44  
    7979        $tMap->addColumn('SALT', 'Salt', 'string', CreoleTypes::VARCHAR, false); 
    8080 
     81        $tMap->addColumn('HAS_PAYPAL', 'HasPaypal', 'boolean', CreoleTypes::BOOLEAN, false); 
     82 
    8183        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
    8284                 
  • trunk/lib/model/om/BaseUser.php

    r31 r44  
    7979 
    8080    /** 
     81     * The value for the has_paypal field. 
     82     * @var boolean 
     83     */ 
     84    protected $has_paypal = false; 
     85 
     86 
     87    /** 
    8188     * The value for the created_at field. 
    8289     * @var int 
     
    233240 
    234241        return $this->salt; 
     242    } 
     243 
     244    /** 
     245     * Get the [has_paypal] column value. 
     246     *  
     247     * @return boolean 
     248     */ 
     249    public function getHasPaypal() 
     250    { 
     251 
     252        return $this->has_paypal; 
    235253    } 
    236254 
     
    379397 
    380398    /** 
     399     * Set the value of [has_paypal] column. 
     400     *  
     401     * @param boolean $v new value 
     402     * @return void 
     403     */ 
     404    public function setHasPaypal($v) 
     405    { 
     406 
     407        if ($this->has_paypal !== $v || $v === false) { 
     408            $this->has_paypal = $v; 
     409            $this->modifiedColumns[] = UserPeer::HAS_PAYPAL; 
     410        } 
     411 
     412    } // setHasPaypal() 
     413 
     414    /** 
    381415     * Set the value of [created_at] column. 
    382416     *  
     
    433467            $this->salt = $rs->getString($startcol + 6); 
    434468 
    435             $this->created_at = $rs->getTimestamp($startcol + 7, null); 
     469            $this->has_paypal = $rs->getBoolean($startcol + 7); 
     470 
     471            $this->created_at = $rs->getTimestamp($startcol + 8, null); 
    436472 
    437473            $this->resetModified(); 
     
    440476 
    441477            // FIXME - using NUM_COLUMNS may be clearer. 
    442             return $startcol + 8; // 8 = UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS). 
     478            return $startcol + 9; // 9 = UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS). 
    443479 
    444480        } catch (Exception $e) { 
     
    731767                break; 
    732768            case 7: 
     769                return $this->getHasPaypal(); 
     770                break; 
     771            case 8: 
    733772                return $this->getCreatedAt(); 
    734773                break; 
     
    760799            $keys[5] => $this->getSha1Password(), 
    761800            $keys[6] => $this->getSalt(), 
    762             $keys[7] => $this->getCreatedAt(), 
     801            $keys[7] => $this->getHasPaypal(), 
     802            $keys[8] => $this->getCreatedAt(), 
    763803        ); 
    764804        return $result; 
     
    815855                break; 
    816856            case 7: 
     857                $this->setHasPaypal($value); 
     858                break; 
     859            case 8: 
    817860                $this->setCreatedAt($value); 
    818861                break; 
     
    847890        if (array_key_exists($keys[5], $arr)) $this->setSha1Password($arr[$keys[5]]); 
    848891        if (array_key_exists($keys[6], $arr)) $this->setSalt($arr[$keys[6]]); 
    849         if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); 
     892        if (array_key_exists($keys[7], $arr)) $this->setHasPaypal($arr[$keys[7]]); 
     893        if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); 
    850894    } 
    851895 
     
    866910        if ($this->isColumnModified(UserPeer::SHA1_PASSWORD)) $criteria->add(UserPeer::SHA1_PASSWORD, $this->sha1_password); 
    867911        if ($this->isColumnModified(UserPeer::SALT)) $criteria->add(UserPeer::SALT, $this->salt); 
     912        if ($this->isColumnModified(UserPeer::HAS_PAYPAL)) $criteria->add(UserPeer::HAS_PAYPAL, $this->has_paypal); 
    868913        if ($this->isColumnModified(UserPeer::CREATED_AT)) $criteria->add(UserPeer::CREATED_AT, $this->created_at); 
    869914 
     
    932977 
    933978        $copyObj->setSalt($this->salt); 
     979 
     980        $copyObj->setHasPaypal($this->has_paypal); 
    934981 
    935982        $copyObj->setCreatedAt($this->created_at); 
  • trunk/lib/model/om/BaseUserPeer.php

    r16 r44  
    2525 
    2626    /** The total number of columns. */ 
    27     const NUM_COLUMNS = 8
     27    const NUM_COLUMNS = 9
    2828 
    2929    /** The number of lazy-loaded columns. */ 
     
    5252    const SALT = 'ask_user.SALT'; 
    5353 
     54    /** the column name for the HAS_PAYPAL field */ 
     55    const HAS_PAYPAL = 'ask_user.HAS_PAYPAL'; 
     56 
    5457    /** the column name for the CREATED_AT field */ 
    5558    const CREATED_AT = 'ask_user.CREATED_AT'; 
     
    6669     */ 
    6770    private static $fieldNames = array ( 
    68         BasePeer::TYPE_PHPNAME => array ('Id', 'Nickname', 'FirstName', 'LastName', 'Email', 'Sha1Password', 'Salt', 'CreatedAt', ), 
    69         BasePeer::TYPE_COLNAME => array (UserPeer::ID, UserPeer::NICKNAME, UserPeer::FIRST_NAME, UserPeer::LAST_NAME, UserPeer::EMAIL, UserPeer::SHA1_PASSWORD, UserPeer::SALT, UserPeer::CREATED_AT, ), 
    70         BasePeer::TYPE_FIELDNAME => array ('id', 'nickname', 'first_name', 'last_name', 'email', 'sha1_password', 'salt', 'created_at', ), 
    71         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7,
     71        BasePeer::TYPE_PHPNAME => array ('Id', 'Nickname', 'FirstName', 'LastName', 'Email', 'Sha1Password', 'Salt', 'HasPaypal', 'CreatedAt', ), 
     72        BasePeer::TYPE_COLNAME => array (UserPeer::ID, UserPeer::NICKNAME, UserPeer::FIRST_NAME, UserPeer::LAST_NAME, UserPeer::EMAIL, UserPeer::SHA1_PASSWORD, UserPeer::SALT, UserPeer::HAS_PAYPAL, UserPeer::CREATED_AT, ), 
     73        BasePeer::TYPE_FIELDNAME => array ('id', 'nickname', 'first_name', 'last_name', 'email', 'sha1_password', 'salt', 'has_paypal', 'created_at', ), 
     74        BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8,
    7275    ); 
    7376 
     
    7982     */ 
    8083    private static $fieldKeys = array ( 
    81         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Nickname' => 1, 'FirstName' => 2, 'LastName' => 3, 'Email' => 4, 'Sha1Password' => 5, 'Salt' => 6, 'CreatedAt' => 7, ), 
    82         BasePeer::TYPE_COLNAME => array (UserPeer::ID => 0, UserPeer::NICKNAME => 1, UserPeer::FIRST_NAME => 2, UserPeer::LAST_NAME => 3, UserPeer::EMAIL => 4, UserPeer::SHA1_PASSWORD => 5, UserPeer::SALT => 6, UserPeer::CREATED_AT => 7, ), 
    83         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'nickname' => 1, 'first_name' => 2, 'last_name' => 3, 'email' => 4, 'sha1_password' => 5, 'salt' => 6, 'created_at' => 7, ), 
    84         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7,
     84        BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Nickname' => 1, 'FirstName' => 2, 'LastName' => 3, 'Email' => 4, 'Sha1Password' => 5, 'Salt' => 6, 'HasPaypal' => 7, 'CreatedAt' => 8, ), 
     85        BasePeer::TYPE_COLNAME => array (UserPeer::ID => 0, UserPeer::NICKNAME => 1, UserPeer::FIRST_NAME => 2, UserPeer::LAST_NAME => 3, UserPeer::EMAIL => 4, UserPeer::SHA1_PASSWORD => 5, UserPeer::SALT => 6, UserPeer::HAS_PAYPAL => 7, UserPeer::CREATED_AT => 8, ), 
     86        BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'nickname' => 1, 'first_name' => 2, 'last_name' => 3, 'email' => 4, 'sha1_password' => 5, 'salt' => 6, 'has_paypal' => 7, 'created_at' => 8, ), 
     87        BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8,
    8588    ); 
    8689 
     
    196199 
    197200        $criteria->addSelectColumn(UserPeer::SALT); 
     201 
     202        $criteria->addSelectColumn(UserPeer::HAS_PAYPAL); 
    198203 
    199204        $criteria->addSelectColumn(UserPeer::CREATED_AT);