Changeset 44
- Timestamp:
- 12/17/05 10:07:41 (7 years ago)
- Files:
-
- trunk/config/schema.xml (modified) (1 diff)
- trunk/data/sql/schema.sql (modified) (1 diff)
- trunk/frontend/config/routing.yml (modified) (2 diffs)
- trunk/frontend/lib/myLoginValidator.class.php (modified) (1 diff)
- trunk/frontend/lib/myUser.class.php (modified) (1 diff)
- trunk/frontend/modules/api (added)
- trunk/frontend/modules/api/actions (added)
- trunk/frontend/modules/api/actions/actions.class.php (added)
- trunk/frontend/modules/api/config (added)
- trunk/frontend/modules/api/config/.sf (added)
- trunk/frontend/modules/api/config/view.yml (added)
- trunk/frontend/modules/api/lib (added)
- trunk/frontend/modules/api/lib/.sf (added)
- trunk/frontend/modules/api/templates (added)
- trunk/frontend/modules/api/templates/errorSuccess.php (added)
- trunk/frontend/modules/api/templates/questionSuccess.php (added)
- trunk/frontend/modules/api/validate (added)
- trunk/frontend/modules/api/validate/.sf (added)
- trunk/frontend/modules/user/actions/actions.class.php (modified) (2 diffs)
- trunk/frontend/modules/user/templates/showSuccess.php (modified) (1 diff)
- trunk/frontend/modules/user/validate/update.yml (added)
- trunk/lib/model/UserPeer.php (modified) (1 diff)
- trunk/lib/model/map/UserMapBuilder.php (modified) (1 diff)
- trunk/lib/model/om/BaseUser.php (modified) (11 diffs)
- trunk/lib/model/om/BaseUserPeer.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/schema.xml
r42 r44 41 41 <column name="sha1_password" type="varchar" size="40" /> 42 42 <column name="salt" type="varchar" size="32" /> 43 <column name="has_paypal" type="boolean" default="0" /> 43 44 <column name="created_at" type="timestamp" /> 44 45 </table> trunk/data/sql/schema.sql
r42 r44 64 64 `sha1_password` VARCHAR(40) , 65 65 `salt` VARCHAR(32) , 66 `has_paypal` INTEGER default 0 , 66 67 `created_at` DATETIME , 67 68 PRIMARY KEY(`id`)) trunk/frontend/config/routing.yml
r38 r44 37 37 url: /user/:nickname 38 38 param: { module: user, action: show } 39 40 user_update: 41 url: /update_user 42 param: { module: user, action: update } 39 43 40 44 current_user_profile: … … 98 102 param: { module: content, action: about } 99 103 104 # api 105 api_question: 106 url: /api/question/:stripped_title 107 param: { module: api, action: question } 108 100 109 # default rules 101 110 homepage: trunk/frontend/lib/myLoginValidator.class.php
r16 r44 47 47 } 48 48 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); 52 52 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; 63 54 } 64 55 trunk/frontend/lib/myUser.class.php
r16 r44 22 22 public function getSubscriberId() 23 23 { 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 } 25 32 } 26 33 27 34 public function getSubscriber() 28 35 { 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 } 30 44 } 31 45 32 46 public function getNickname() 33 47 { 34 return $this->getAttribute('nickname', '', 'subscriber'); 48 if ($this->isAuthenticated()) 49 { 50 return $this->getAttribute('nickname', '', 'subscriber'); 51 } 52 else 53 { 54 return ''; 55 } 35 56 } 36 57 } trunk/frontend/modules/user/actions/actions.class.php
r38 r44 51 51 else 52 52 { 53 $this->subscriber = UserPeer::retrieveByPk($this->getUser()->getSubscriberId());53 $this->subscriber = $this->getUser()->getSubscriber(); 54 54 } 55 55 $this->forward404Unless($this->subscriber); 56 56 57 $this->interests = $this->subscriber->getInterestsJoinQuestion(); 58 $this->answers = $this->subscriber->getAnswersJoinQuestion(); 59 $this->questions = $this->subscriber->getQuestions(); 60 61 $this->setTitle('askeet! » '.$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()); 62 81 } 63 82 … … 162 181 return sfView::SUCCESS; 163 182 } 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! » '.$this->subscriber->__toString().'\'s profile'); 210 } 164 211 } 165 212 trunk/frontend/modules/user/templates/showSuccess.php
r38 r44 1 <?php use_helpers('Date', 'Question', 'Text' ) ?>1 <?php use_helpers('Date', 'Question', 'Text', 'Object') ?> 2 2 3 3 <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 ?> 4 63 5 64 <h3>tags</h3> trunk/lib/model/UserPeer.php
r23 r44 28 28 return self::doSelectOne($c); 29 29 } 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 } 30 49 } 31 50 trunk/lib/model/map/UserMapBuilder.php
r16 r44 79 79 $tMap->addColumn('SALT', 'Salt', 'string', CreoleTypes::VARCHAR, false); 80 80 81 $tMap->addColumn('HAS_PAYPAL', 'HasPaypal', 'boolean', CreoleTypes::BOOLEAN, false); 82 81 83 $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 82 84 trunk/lib/model/om/BaseUser.php
r31 r44 79 79 80 80 /** 81 * The value for the has_paypal field. 82 * @var boolean 83 */ 84 protected $has_paypal = false; 85 86 87 /** 81 88 * The value for the created_at field. 82 89 * @var int … … 233 240 234 241 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; 235 253 } 236 254 … … 379 397 380 398 /** 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 /** 381 415 * Set the value of [created_at] column. 382 416 * … … 433 467 $this->salt = $rs->getString($startcol + 6); 434 468 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); 436 472 437 473 $this->resetModified(); … … 440 476 441 477 // 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). 443 479 444 480 } catch (Exception $e) { … … 731 767 break; 732 768 case 7: 769 return $this->getHasPaypal(); 770 break; 771 case 8: 733 772 return $this->getCreatedAt(); 734 773 break; … … 760 799 $keys[5] => $this->getSha1Password(), 761 800 $keys[6] => $this->getSalt(), 762 $keys[7] => $this->getCreatedAt(), 801 $keys[7] => $this->getHasPaypal(), 802 $keys[8] => $this->getCreatedAt(), 763 803 ); 764 804 return $result; … … 815 855 break; 816 856 case 7: 857 $this->setHasPaypal($value); 858 break; 859 case 8: 817 860 $this->setCreatedAt($value); 818 861 break; … … 847 890 if (array_key_exists($keys[5], $arr)) $this->setSha1Password($arr[$keys[5]]); 848 891 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]]); 850 894 } 851 895 … … 866 910 if ($this->isColumnModified(UserPeer::SHA1_PASSWORD)) $criteria->add(UserPeer::SHA1_PASSWORD, $this->sha1_password); 867 911 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); 868 913 if ($this->isColumnModified(UserPeer::CREATED_AT)) $criteria->add(UserPeer::CREATED_AT, $this->created_at); 869 914 … … 932 977 933 978 $copyObj->setSalt($this->salt); 979 980 $copyObj->setHasPaypal($this->has_paypal); 934 981 935 982 $copyObj->setCreatedAt($this->created_at); trunk/lib/model/om/BaseUserPeer.php
r16 r44 25 25 26 26 /** The total number of columns. */ 27 const NUM_COLUMNS = 8;27 const NUM_COLUMNS = 9; 28 28 29 29 /** The number of lazy-loaded columns. */ … … 52 52 const SALT = 'ask_user.SALT'; 53 53 54 /** the column name for the HAS_PAYPAL field */ 55 const HAS_PAYPAL = 'ask_user.HAS_PAYPAL'; 56 54 57 /** the column name for the CREATED_AT field */ 55 58 const CREATED_AT = 'ask_user.CREATED_AT'; … … 66 69 */ 67 70 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, ) 72 75 ); 73 76 … … 79 82 */ 80 83 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, ) 85 88 ); 86 89 … … 196 199 197 200 $criteria->addSelectColumn(UserPeer::SALT); 201 202 $criteria->addSelectColumn(UserPeer::HAS_PAYPAL); 198 203 199 204 $criteria->addSelectColumn(UserPeer::CREATED_AT);
