Changeset 16

Show
Ignore:
Timestamp:
12/06/05 09:28:05 (3 years ago)
Author:
fabien
Message:

day 6 modifications

Files:

Legend:

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

    r12 r16  
    3636     <column name="first_name" type="varchar" size="100" /> 
    3737     <column name="last_name" type="varchar" size="100" /> 
     38     <column name="email" type="varchar" size="100" /> 
     39     <column name="sha1_password" type="varchar" size="40" /> 
     40     <column name="salt" type="varchar" size="32" /> 
    3841     <column name="created_at" type="timestamp" /> 
    3942   </table> 
  • trunk/data/fixtures/test_data.yml

    r14 r16  
    99    first_name: Fabien 
    1010    last_name:  Potencier 
     11    password:   symfony 
     12    email:      fp@example.com 
    1113 
    1214  francois: 
     
    1416    first_name: François 
    1517    last_name:  Zaninotto 
     18    password:   adventcal 
     19    email:      fz@example.com 
    1620 
    1721Question: 
  • trunk/data/sql/schema.sql

    r12 r16  
    5959    `first_name` VARCHAR(100) ,  
    6060    `last_name` VARCHAR(100) ,  
     61    `email` VARCHAR(100) ,  
     62    `sha1_password` VARCHAR(40) ,  
     63    `salt` VARCHAR(32) ,  
    6164    `created_at` DATETIME ,   
    6265    PRIMARY KEY(`id`)) 
  • trunk/frontend/lib/myUser.class.php

    r2 r16  
    33class myUser extends sfBasicSecurityUser 
    44{ 
     5  public function signIn($user) 
     6  { 
     7    $this->setAttribute('subscriber_id', $user->getId(), 'subscriber'); 
     8    $this->setAuthenticated(true); 
     9 
     10    $this->addCredential('subscriber'); 
     11    $this->setAttribute('nickname', $user->getNickname(), 'subscriber'); 
     12  } 
     13 
     14  public function signOut() 
     15  { 
     16    $this->getAttributeHolder()->removeNamespace('subscriber'); 
     17 
     18    $this->setAuthenticated(false); 
     19    $this->clearCredentials(); 
     20  } 
     21 
     22  public function getSubscriberId() 
     23  { 
     24    return $this->getAttribute('subscriber_id', '', 'subscriber'); 
     25  } 
     26 
     27  public function getSubscriber() 
     28  { 
     29    return UserPeer::retrieveByPk($this->getSubscriberId()); 
     30  } 
     31 
     32  public function getNickname() 
     33  { 
     34    return $this->getAttribute('nickname', '', 'subscriber'); 
     35  } 
    536} 
    637 
  • trunk/frontend/modules/user/actions/actions.class.php

    r14 r16  
    2020    { 
    2121      // display the form 
    22       $this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer()); 
     22      $this->getRequest()->getParameterHolder()->set('referer', $this->getRequest()->getReferer()); 
     23      return sfView::SUCCESS; 
    2324    } 
    2425    else 
    2526    { 
    2627      // handle the form submission 
    27       $nickname = $this->getRequestParameter('nickname'); 
    28  
    29       $c = new Criteria(); 
    30       $c->add(UserPeer::NICKNAME, $nickname); 
    31       $user = UserPeer::doSelectOne($c); 
    32  
    33       // nickname exists? 
    34       if ($user) 
    35       { 
    36         // password is OK? 
    37         if (true) 
    38         { 
    39           // $this->getUser()->setAuthenticated(true); 
    40           // $this->getUser()->addCredential('subscriber'); 
    41  
    42           $this->getUser()->setAttribute('subscriber_id', $user->getId(), 'subscriber'); 
    43           $this->getUser()->setAttribute('nickname', $user->getNickname(), 'subscriber'); 
    44  
    45           // redirect to last page 
    46           return $this->redirect($this->getRequestParameter('referer', 'question/list')); 
    47         } 
    48       } 
     28      // redirect to last page 
     29      return $this->redirect($this->getRequestParameter('referer', '@homepage')); 
    4930    } 
    5031  } 
     
    5233  public function executeLogout() 
    5334  { 
    54     // $this->getUser()->setAuthenticated(false); 
    55     // $this->getUser()->clearCredentials(); 
     35    $this->getUser()->signOut(); 
    5636 
    57     $this->getUser()->getAttributeHolder()->removeNamespace('subscriber'); 
     37    $this->redirect('@homepage'); 
     38  } 
    5839 
    59     $this->redirect('question/list'); 
     40  public function handleErrorLogin() 
     41  { 
     42    return sfView::SUCCESS; 
    6043  } 
    6144} 
  • trunk/frontend/modules/user/templates/loginSuccess.php

    r14 r16  
     1<?php use_helper('Validation') ?> 
    12<?php echo form_tag('user/login') ?> 
    23  
     
    45 
    56  <div class="form-row"> 
     7    <?php echo form_error('nickname') ?> 
    68    <label for="nickname">nickname:</label> 
    79    <?php echo input_tag('nickname', $params->get('nickname')) ?> 
    810  </div> 
    9  
     11   
    1012  <div class="form-row"> 
     13    <?php echo form_error('password') ?> 
    1114    <label for="password">password:</label> 
    1215    <?php echo input_password_tag('password') ?> 
  • trunk/lib/model/User.php

    r12 r16  
    2121    return $this->getFirstName().' '.$this->getLastName(); 
    2222  } 
     23 
     24  public function setPassword($password) 
     25  { 
     26    $salt = md5(rand(100000, 999999).$this->getNickname().$this->getEmail()); 
     27    $this->setSalt($salt); 
     28    $this->setSha1Password(sha1($salt.$password)); 
     29  } 
    2330} 
    2431 
  • trunk/lib/model/map/UserMapBuilder.php

    r4 r16  
    7373        $tMap->addColumn('LAST_NAME', 'LastName', 'string', CreoleTypes::VARCHAR, false); 
    7474 
     75        $tMap->addColumn('EMAIL', 'Email', 'string', CreoleTypes::VARCHAR, false); 
     76 
     77        $tMap->addColumn('SHA1_PASSWORD', 'Sha1Password', 'string', CreoleTypes::VARCHAR, false); 
     78 
     79        $tMap->addColumn('SALT', 'Salt', 'string', CreoleTypes::VARCHAR, false); 
     80 
    7581        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
    7682                 
  • trunk/lib/model/om/BaseAnswer.php

    r12 r16  
    44 
    55require_once 'propel/om/Persistent.php'; 
     6 
     7 
     8include_once 'propel/util/Criteria.php'; 
     9 
     10include_once 'model/AnswerPeer.php'; 
    611 
    712/** 
  • trunk/lib/model/om/BaseAnswerPeer.php

    r12 r16  
    22 
    33require_once 'propel/util/BasePeer.php'; 
     4// The object class -- needed for instanceof checks in this class. 
     5// actual class may be a subclass -- as returned by AnswerPeer::getOMClass() 
     6include_once 'model/Answer.php'; 
    47 
    58/** 
  • trunk/lib/model/om/BaseInterest.php

    r12 r16  
    44 
    55require_once 'propel/om/Persistent.php'; 
     6 
     7 
     8include_once 'propel/util/Criteria.php'; 
     9 
     10include_once 'model/InterestPeer.php'; 
    611 
    712/** 
  • trunk/lib/model/om/BaseInterestPeer.php

    r12 r16  
    22 
    33require_once 'propel/util/BasePeer.php'; 
     4// The object class -- needed for instanceof checks in this class. 
     5// actual class may be a subclass -- as returned by InterestPeer::getOMClass() 
     6include_once 'model/Interest.php'; 
    47 
    58/** 
  • trunk/lib/model/om/BaseQuestion.php

    r12 r16  
    44 
    55require_once 'propel/om/Persistent.php'; 
     6 
     7 
     8include_once 'propel/util/Criteria.php'; 
     9 
     10include_once 'model/QuestionPeer.php'; 
    611 
    712/** 
  • trunk/lib/model/om/BaseQuestionPeer.php

    r12 r16  
    22 
    33require_once 'propel/util/BasePeer.php'; 
     4// The object class -- needed for instanceof checks in this class. 
     5// actual class may be a subclass -- as returned by QuestionPeer::getOMClass() 
     6include_once 'model/Question.php'; 
    47 
    58/** 
  • trunk/lib/model/om/BaseRelevancy.php

    r12 r16  
    44 
    55require_once 'propel/om/Persistent.php'; 
     6 
     7 
     8include_once 'propel/util/Criteria.php'; 
     9 
     10include_once 'model/RelevancyPeer.php'; 
    611 
    712/** 
  • trunk/lib/model/om/BaseRelevancyPeer.php

    r12 r16  
    22 
    33require_once 'propel/util/BasePeer.php'; 
     4// The object class -- needed for instanceof checks in this class. 
     5// actual class may be a subclass -- as returned by RelevancyPeer::getOMClass() 
     6include_once 'model/Relevancy.php'; 
    47 
    58/** 
  • trunk/lib/model/om/BaseUser.php

    r12 r16  
    44 
    55require_once 'propel/om/Persistent.php'; 
     6 
     7 
     8include_once 'propel/util/Criteria.php'; 
     9 
     10include_once 'model/UserPeer.php'; 
    611 
    712/** 
     
    5358 
    5459    /** 
     60     * The value for the email field. 
     61     * @var string 
     62     */ 
     63    protected $email; 
     64 
     65 
     66    /** 
     67     * The value for the sha1_password field. 
     68     * @var string 
     69     */ 
     70    protected $sha1_password; 
     71 
     72 
     73    /** 
     74     * The value for the salt field. 
     75     * @var string 
     76     */ 
     77    protected $salt; 
     78 
     79 
     80    /** 
    5581     * The value for the created_at field. 
    5682     * @var int 
     
    162188 
    163189        return $this->last_name; 
     190    } 
     191 
     192    /** 
     193     * Get the [email] column value. 
     194     *  
     195     * @return string 
     196     */ 
     197    public function getEmail() 
     198    { 
     199 
     200        return $this->email; 
     201    } 
     202 
     203    /** 
     204     * Get the [sha1_password] column value. 
     205     *  
     206     * @return string 
     207     */ 
     208    public function getSha1Password() 
     209    { 
     210 
     211        return $this->sha1_password; 
     212    } 
     213 
     214    /** 
     215     * Get the [salt] column value. 
     216     *  
     217     * @return string 
     218     */ 
     219    public function getSalt() 
     220    { 
     221 
     222        return $this->salt; 
    164223    } 
    165224 
     
    260319 
    261320    /** 
     321     * Set the value of [email] column. 
     322     *  
     323     * @param string $v new value 
     324     * @return void 
     325     */ 
     326    public function setEmail($v) 
     327    { 
     328 
     329        if ($this->email !== $v) { 
     330            $this->email = $v; 
     331            $this->modifiedColumns[] = UserPeer::EMAIL; 
     332        } 
     333 
     334    } // setEmail() 
     335 
     336    /** 
     337     * Set the value of [sha1_password] column. 
     338     *  
     339     * @param string $v new value 
     340     * @return void 
     341     */ 
     342    public function setSha1Password($v) 
     343    { 
     344 
     345        if ($this->sha1_password !== $v) { 
     346            $this->sha1_password = $v; 
     347            $this->modifiedColumns[] = UserPeer::SHA1_PASSWORD; 
     348        } 
     349 
     350    } // setSha1Password() 
     351 
     352    /** 
     353     * Set the value of [salt] column. 
     354     *  
     355     * @param string $v new value 
     356     * @return void 
     357     */ 
     358    public function setSalt($v) 
     359    { 
     360 
     361        if ($this->salt !== $v) { 
     362            $this->salt = $v; 
     363            $this->modifiedColumns[] = UserPeer::SALT; 
     364        } 
     365 
     366    } // setSalt() 
     367 
     368    /** 
    262369     * Set the value of [created_at] column. 
    263370     *  
     
    308415            $this->last_name = $rs->getString($startcol + 3); 
    309416 
    310             $this->created_at = $rs->getTimestamp($startcol + 4, null); 
     417            $this->email = $rs->getString($startcol + 4); 
     418 
     419            $this->sha1_password = $rs->getString($startcol + 5); 
     420 
     421            $this->salt = $rs->getString($startcol + 6); 
     422 
     423            $this->created_at = $rs->getTimestamp($startcol + 7, null); 
    311424 
    312425            $this->resetModified(); 
     
    315428 
    316429            // FIXME - using NUM_COLUMNS may be clearer. 
    317             return $startcol + 5; // 5 = UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS). 
     430            return $startcol + 8; // 8 = UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS). 
    318431 
    319432        } catch (Exception $e) { 
     
    581694                break; 
    582695            case 4: 
     696                return $this->getEmail(); 
     697                break; 
     698            case 5: 
     699                return $this->getSha1Password(); 
     700                break; 
     701            case 6: 
     702                return $this->getSalt(); 
     703                break; 
     704            case 7: 
    583705                return $this->getCreatedAt(); 
    584706                break; 
     
    607729            $keys[2] => $this->getFirstName(), 
    608730            $keys[3] => $this->getLastName(), 
    609             $keys[4] => $this->getCreatedAt(), 
     731            $keys[4] => $this->getEmail(), 
     732            $keys[5] => $this->getSha1Password(), 
     733            $keys[6] => $this->getSalt(), 
     734            $keys[7] => $this->getCreatedAt(), 
    610735        ); 
    611736        return $result; 
     
    653778                break; 
    654779            case 4: 
     780                $this->setEmail($value); 
     781                break; 
     782            case 5: 
     783                $this->setSha1Password($value); 
     784                break; 
     785            case 6: 
     786                $this->setSalt($value); 
     787                break; 
     788            case 7: 
    655789                $this->setCreatedAt($value); 
    656790                break; 
     
    682816        if (array_key_exists($keys[2], $arr)) $this->setFirstName($arr[$keys[2]]); 
    683817        if (array_key_exists($keys[3], $arr)) $this->setLastName($arr[$keys[3]]); 
    684         if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); 
     818        if (array_key_exists($keys[4], $arr)) $this->setEmail($arr[$keys[4]]); 
     819        if (array_key_exists($keys[5], $arr)) $this->setSha1Password($arr[$keys[5]]); 
     820        if (array_key_exists($keys[6], $arr)) $this->setSalt($arr[$keys[6]]); 
     821        if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); 
    685822    } 
    686823 
     
    698835        if ($this->isColumnModified(UserPeer::FIRST_NAME)) $criteria->add(UserPeer::FIRST_NAME, $this->first_name); 
    699836        if ($this->isColumnModified(UserPeer::LAST_NAME)) $criteria->add(UserPeer::LAST_NAME, $this->last_name); 
     837        if ($this->isColumnModified(UserPeer::EMAIL)) $criteria->add(UserPeer::EMAIL, $this->email); 
     838        if ($this->isColumnModified(UserPeer::SHA1_PASSWORD)) $criteria->add(UserPeer::SHA1_PASSWORD, $this->sha1_password); 
     839        if ($this->isColumnModified(UserPeer::SALT)) $criteria->add(UserPeer::SALT, $this->salt); 
    700840        if ($this->isColumnModified(UserPeer::CREATED_AT)) $criteria->add(UserPeer::CREATED_AT, $this->created_at); 
    701841 
     
    758898 
    759899        $copyObj->setLastName($this->last_name); 
     900 
     901        $copyObj->setEmail($this->email); 
     902 
     903        $copyObj->setSha1Password($this->sha1_password); 
     904 
     905        $copyObj->setSalt($this->salt); 
    760906 
    761907        $copyObj->setCreatedAt($this->created_at); 
  • trunk/lib/model/om/BaseUserPeer.php

    r12 r16  
    22 
    33require_once 'propel/util/BasePeer.php'; 
     4// The object class -- needed for instanceof checks in this class. 
     5// actual class may be a subclass -- as returned by UserPeer::getOMClass() 
     6include_once 'model/User.php'; 
    47 
    58/** 
     
    2225 
    2326    /** The total number of columns. */ 
    24     const NUM_COLUMNS = 5
     27    const NUM_COLUMNS = 8
    2528 
    2629    /** The number of lazy-loaded columns. */ 
     
    4043    const LAST_NAME = 'ask_user.LAST_NAME'; 
    4144 
     45    /** the column name for the EMAIL field */ 
     46    const EMAIL = 'ask_user.EMAIL'; 
     47 
     48    /** the column name for the SHA1_PASSWORD field */ 
     49    const SHA1_PASSWORD = 'ask_user.SHA1_PASSWORD'; 
     50 
     51    /** the column name for the SALT field */ 
     52    const SALT = 'ask_user.SALT'; 
     53 
    4254    /** the column name for the CREATED_AT field */ 
    4355    const CREATED_AT = 'ask_user.CREATED_AT'; 
     
    5466     */ 
    5567    private static $fieldNames = array ( 
    56         BasePeer::TYPE_PHPNAME => array ('Id', 'Nickname', 'FirstName', 'LastName', 'CreatedAt', ), 
    57         BasePeer::TYPE_COLNAME => array (UserPeer::ID, UserPeer::NICKNAME, UserPeer::FIRST_NAME, UserPeer::LAST_NAME, UserPeer::CREATED_AT, ), 
    58         BasePeer::TYPE_FIELDNAME => array ('id', 'nickname', 'first_name', 'last_name', 'created_at', ), 
    59         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4,
     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,
    6072    ); 
    6173 
     
    6779     */ 
    6880    private static $fieldKeys = array ( 
    69         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Nickname' => 1, 'FirstName' => 2, 'LastName' => 3, 'CreatedAt' => 4, ), 
    70         BasePeer::TYPE_COLNAME => array (UserPeer::ID => 0, UserPeer::NICKNAME => 1, UserPeer::FIRST_NAME => 2, UserPeer::LAST_NAME => 3, UserPeer::CREATED_AT => 4, ), 
    71         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'nickname' => 1, 'first_name' => 2, 'last_name' => 3, 'created_at' => 4, ), 
    72         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4,
     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,
    7385    ); 
    7486 
     
    178190 
    179191        $criteria->addSelectColumn(UserPeer::LAST_NAME); 
     192 
     193        $criteria->addSelectColumn(UserPeer::EMAIL); 
     194 
     195        $criteria->addSelectColumn(UserPeer::SHA1_PASSWORD); 
     196 
     197        $criteria->addSelectColumn(UserPeer::SALT); 
    180198 
    181199        $criteria->addSelectColumn(UserPeer::CREATED_AT); 
  • trunk/web/css/main.css

    r8 r16  
    142142  background-color: #bbb; 
    143143} 
     144 
     145.form_error 
     146{ 
     147  color: #f00; 
     148}