Changeset 16
- Timestamp:
- 12/06/05 09:28:05 (3 years ago)
- Files:
-
- trunk/config/schema.xml (modified) (1 diff)
- trunk/data/fixtures/test_data.yml (modified) (2 diffs)
- trunk/data/sql/schema.sql (modified) (1 diff)
- trunk/frontend/lib/myLoginValidator.class.php (added)
- trunk/frontend/lib/myUser.class.php (modified) (1 diff)
- trunk/frontend/modules/question/config (added)
- trunk/frontend/modules/question/config/security.yml (added)
- trunk/frontend/modules/user/actions/actions.class.php (modified) (2 diffs)
- trunk/frontend/modules/user/templates/loginSuccess.php (modified) (2 diffs)
- trunk/frontend/modules/user/validate/login.yml (added)
- trunk/lib/model/User.php (modified) (1 diff)
- trunk/lib/model/map/UserMapBuilder.php (modified) (1 diff)
- trunk/lib/model/om/BaseAnswer.php (modified) (1 diff)
- trunk/lib/model/om/BaseAnswerPeer.php (modified) (1 diff)
- trunk/lib/model/om/BaseInterest.php (modified) (1 diff)
- trunk/lib/model/om/BaseInterestPeer.php (modified) (1 diff)
- trunk/lib/model/om/BaseQuestion.php (modified) (1 diff)
- trunk/lib/model/om/BaseQuestionPeer.php (modified) (1 diff)
- trunk/lib/model/om/BaseRelevancy.php (modified) (1 diff)
- trunk/lib/model/om/BaseRelevancyPeer.php (modified) (1 diff)
- trunk/lib/model/om/BaseUser.php (modified) (12 diffs)
- trunk/lib/model/om/BaseUserPeer.php (modified) (6 diffs)
- trunk/web/css/main.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/schema.xml
r12 r16 36 36 <column name="first_name" type="varchar" size="100" /> 37 37 <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" /> 38 41 <column name="created_at" type="timestamp" /> 39 42 </table> trunk/data/fixtures/test_data.yml
r14 r16 9 9 first_name: Fabien 10 10 last_name: Potencier 11 password: symfony 12 email: fp@example.com 11 13 12 14 francois: … … 14 16 first_name: François 15 17 last_name: Zaninotto 18 password: adventcal 19 email: fz@example.com 16 20 17 21 Question: trunk/data/sql/schema.sql
r12 r16 59 59 `first_name` VARCHAR(100) , 60 60 `last_name` VARCHAR(100) , 61 `email` VARCHAR(100) , 62 `sha1_password` VARCHAR(40) , 63 `salt` VARCHAR(32) , 61 64 `created_at` DATETIME , 62 65 PRIMARY KEY(`id`)) trunk/frontend/lib/myUser.class.php
r2 r16 3 3 class myUser extends sfBasicSecurityUser 4 4 { 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 } 5 36 } 6 37 trunk/frontend/modules/user/actions/actions.class.php
r14 r16 20 20 { 21 21 // display the form 22 $this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer()); 22 $this->getRequest()->getParameterHolder()->set('referer', $this->getRequest()->getReferer()); 23 return sfView::SUCCESS; 23 24 } 24 25 else 25 26 { 26 27 // 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')); 49 30 } 50 31 } … … 52 33 public function executeLogout() 53 34 { 54 // $this->getUser()->setAuthenticated(false); 55 // $this->getUser()->clearCredentials(); 35 $this->getUser()->signOut(); 56 36 57 $this->getUser()->getAttributeHolder()->removeNamespace('subscriber'); 37 $this->redirect('@homepage'); 38 } 58 39 59 $this->redirect('question/list'); 40 public function handleErrorLogin() 41 { 42 return sfView::SUCCESS; 60 43 } 61 44 } trunk/frontend/modules/user/templates/loginSuccess.php
r14 r16 1 <?php use_helper('Validation') ?> 1 2 <?php echo form_tag('user/login') ?> 2 3 … … 4 5 5 6 <div class="form-row"> 7 <?php echo form_error('nickname') ?> 6 8 <label for="nickname">nickname:</label> 7 9 <?php echo input_tag('nickname', $params->get('nickname')) ?> 8 10 </div> 9 11 10 12 <div class="form-row"> 13 <?php echo form_error('password') ?> 11 14 <label for="password">password:</label> 12 15 <?php echo input_password_tag('password') ?> trunk/lib/model/User.php
r12 r16 21 21 return $this->getFirstName().' '.$this->getLastName(); 22 22 } 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 } 23 30 } 24 31 trunk/lib/model/map/UserMapBuilder.php
r4 r16 73 73 $tMap->addColumn('LAST_NAME', 'LastName', 'string', CreoleTypes::VARCHAR, false); 74 74 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 75 81 $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 76 82 trunk/lib/model/om/BaseAnswer.php
r12 r16 4 4 5 5 require_once 'propel/om/Persistent.php'; 6 7 8 include_once 'propel/util/Criteria.php'; 9 10 include_once 'model/AnswerPeer.php'; 6 11 7 12 /** trunk/lib/model/om/BaseAnswerPeer.php
r12 r16 2 2 3 3 require_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() 6 include_once 'model/Answer.php'; 4 7 5 8 /** trunk/lib/model/om/BaseInterest.php
r12 r16 4 4 5 5 require_once 'propel/om/Persistent.php'; 6 7 8 include_once 'propel/util/Criteria.php'; 9 10 include_once 'model/InterestPeer.php'; 6 11 7 12 /** trunk/lib/model/om/BaseInterestPeer.php
r12 r16 2 2 3 3 require_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() 6 include_once 'model/Interest.php'; 4 7 5 8 /** trunk/lib/model/om/BaseQuestion.php
r12 r16 4 4 5 5 require_once 'propel/om/Persistent.php'; 6 7 8 include_once 'propel/util/Criteria.php'; 9 10 include_once 'model/QuestionPeer.php'; 6 11 7 12 /** trunk/lib/model/om/BaseQuestionPeer.php
r12 r16 2 2 3 3 require_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() 6 include_once 'model/Question.php'; 4 7 5 8 /** trunk/lib/model/om/BaseRelevancy.php
r12 r16 4 4 5 5 require_once 'propel/om/Persistent.php'; 6 7 8 include_once 'propel/util/Criteria.php'; 9 10 include_once 'model/RelevancyPeer.php'; 6 11 7 12 /** trunk/lib/model/om/BaseRelevancyPeer.php
r12 r16 2 2 3 3 require_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() 6 include_once 'model/Relevancy.php'; 4 7 5 8 /** trunk/lib/model/om/BaseUser.php
r12 r16 4 4 5 5 require_once 'propel/om/Persistent.php'; 6 7 8 include_once 'propel/util/Criteria.php'; 9 10 include_once 'model/UserPeer.php'; 6 11 7 12 /** … … 53 58 54 59 /** 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 /** 55 81 * The value for the created_at field. 56 82 * @var int … … 162 188 163 189 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; 164 223 } 165 224 … … 260 319 261 320 /** 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 /** 262 369 * Set the value of [created_at] column. 263 370 * … … 308 415 $this->last_name = $rs->getString($startcol + 3); 309 416 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); 311 424 312 425 $this->resetModified(); … … 315 428 316 429 // 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). 318 431 319 432 } catch (Exception $e) { … … 581 694 break; 582 695 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: 583 705 return $this->getCreatedAt(); 584 706 break; … … 607 729 $keys[2] => $this->getFirstName(), 608 730 $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(), 610 735 ); 611 736 return $result; … … 653 778 break; 654 779 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: 655 789 $this->setCreatedAt($value); 656 790 break; … … 682 816 if (array_key_exists($keys[2], $arr)) $this->setFirstName($arr[$keys[2]]); 683 817 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]]); 685 822 } 686 823 … … 698 835 if ($this->isColumnModified(UserPeer::FIRST_NAME)) $criteria->add(UserPeer::FIRST_NAME, $this->first_name); 699 836 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); 700 840 if ($this->isColumnModified(UserPeer::CREATED_AT)) $criteria->add(UserPeer::CREATED_AT, $this->created_at); 701 841 … … 758 898 759 899 $copyObj->setLastName($this->last_name); 900 901 $copyObj->setEmail($this->email); 902 903 $copyObj->setSha1Password($this->sha1_password); 904 905 $copyObj->setSalt($this->salt); 760 906 761 907 $copyObj->setCreatedAt($this->created_at); trunk/lib/model/om/BaseUserPeer.php
r12 r16 2 2 3 3 require_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() 6 include_once 'model/User.php'; 4 7 5 8 /** … … 22 25 23 26 /** The total number of columns. */ 24 const NUM_COLUMNS = 5;27 const NUM_COLUMNS = 8; 25 28 26 29 /** The number of lazy-loaded columns. */ … … 40 43 const LAST_NAME = 'ask_user.LAST_NAME'; 41 44 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 42 54 /** the column name for the CREATED_AT field */ 43 55 const CREATED_AT = 'ask_user.CREATED_AT'; … … 54 66 */ 55 67 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, ) 60 72 ); 61 73 … … 67 79 */ 68 80 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, ) 73 85 ); 74 86 … … 178 190 179 191 $criteria->addSelectColumn(UserPeer::LAST_NAME); 192 193 $criteria->addSelectColumn(UserPeer::EMAIL); 194 195 $criteria->addSelectColumn(UserPeer::SHA1_PASSWORD); 196 197 $criteria->addSelectColumn(UserPeer::SALT); 180 198 181 199 $criteria->addSelectColumn(UserPeer::CREATED_AT); trunk/web/css/main.css
r8 r16 142 142 background-color: #bbb; 143 143 } 144 145 .form_error 146 { 147 color: #f00; 148 }
