Пример #1
0
 public static function loadAll()
 {
     return array_map(function ($row) {
         $u = new User();
         $u->populateFromRow($row);
         return $u;
     }, DB\selectAllRows('users'));
 }
Пример #2
0
function newUser($email, $username, $pw)
{
    require_once 'chipin/users.php';
    require_once 'chipin/passwords.php';
    # XXX: Note, we're not hashing passwords here...
    $uid = DB\insertOne('users', array('email' => $email, 'username' => $username, 'password' => Passwords\hash($pw)), true);
    return User::loadFromID($uid);
}
 function testChangingPassword()
 {
     $userB4 = $this->loginAsNormalUser();
     assertFalse(Passwords\isValid('n00p@ss', $userB4->passwordEncrypted));
     $this->get('/account/change-password');
     $this->submitForm($this->getForm('change-password-form'), array('current-password' => 'abc123', 'password' => 'n00p@ss', 'confirm-password' => 'n00p@ss'));
     $userAfter = User::loadFromID($userB4->id);
     assertTrue(Passwords\isValid('n00p@ss', $userAfter->passwordEncrypted));
 }
Пример #4
0
function getUserForCode($code)
{
    $rows = DB\simpleSelect('confirmation_codes', 'code = ?', array($code));
    $row = current($rows);
    if ($row == null) {
        throw new InvalidCode("No such confirmation code found ({$code})");
    }
    return User::loadFromID($row['user_id']);
}
Пример #5
0
 protected function login($username, $password)
 {
     try {
         $this->get('/account/signin');
         $this->submitForm($this->getForm('signin-form'), array('username' => $username, 'password' => $password));
     } catch (HttpRedirect $_) {
         /* That's okay -- we should be redirected to the Dashboard. */
     }
     $this->user = User::loadFromUsername($username);
 }
Пример #6
0
 function u(RequestContext $context)
 {
     $username = $context->takeNextPathComponent();
     $uriID = $context->takeNextPathComponentOrNull();
     try {
         if (empty($uriID)) {
             $user = User::loadFromUsername($username);
             return $this->render('widgets-for-user.diet-php', array('user' => $user, 'widgets' => Widget::getManyByOwner($user)));
         } else {
             $widget = Widget::getByURI(User::loadFromUsername($username), $uriID);
             return $this->renderWidgetObj($widget);
         }
     } catch (\Chipin\NoSuchUser $_) {
         return $this->pageNotFound("No such user");
     } catch (\Chipin\Widgets\NoSuchWidget $_) {
         return $this->pageNotFound("No such widget");
     }
 }
Пример #7
0
 function testAddingWidgetAsUnauthenticatedUser()
 {
     $this->logout();
     $this->get('/widget-wiz/step-one');
     $expires = new DateTime("+50 days");
     $this->submitForm($this->getForm(), array('title' => 'What is Bitcoin?', 'goal' => '100', 'currency' => 'USD', 'ending' => $expires->format("m/d/Y"), 'bitcoinAddress' => $this->btcAddr()));
     $this->submitForm($this->getForm(), array('about' => 'Donate some bitcoins so I can learn it.', 'color' => Widgets\defaultColor(), 'size' => (string) Widgets\defaultSize()));
     $widgets = Widget::getAll();
     assertEqual(1, count($widgets));
     $pass = '******';
     $this->submitForm($this->getForm('signup-form'), array('email' => '*****@*****.**', 'username' => 'butter-cookie', 'password1' => $pass, 'password2' => $pass));
     $this->logout();
     $this->login('butter-cookie', $pass);
     $user = User::loadFromUsername('butter-cookie');
     $widgets = Widget::getManyByOwner($user);
     assertEqual(1, count($widgets));
     assertEqual('*****@*****.**', $user->email);
 }
Пример #8
0
 function testSignupProcess()
 {
     $this->createHomepageWidgets();
     $this->get('/');
     $this->clickLink("//a[contains(@href, 'signup')]");
     $this->get('/account/signup');
     $this->followRedirects(true);
     $this->submitForm($this->getForm(), array('username' => 'sammy', 'email' => '*****@*****.**', 'password1' => 'luckystars', 'password2' => 'luckystars', 'memorydealers-updates' => 'on'));
     $u = User::loadFromUsername('sammy');
     assertEqual('*****@*****.**', $u->email);
     $subscriptions = current(DB\simpleSelect('subscriptions', 'user_id = ?', array($u->id)));
     assertFalse(empty($subscriptions), 'Expected to find record in subscriptions table for user');
     assertTrue($subscriptions['chipin'] == false || $subscriptions['chipin'] == 0);
     assertTrue($subscriptions['memorydealers'] == true || $subscriptions['memorydealers'] == 1);
     $this->logout();
     $this->login('sammy', 'luckystars');
     $this->get('/dashboard/');
     assertTrue(beginsWith($this->getCurrentPath(), '/dashboard'));
 }
Пример #9
0
 function stepTwo()
 {
     $widget = $this->requireWidget();
     if ($this->isPostRequest()) {
         $user = $this->getActiveUser();
         if (empty($user)) {
             $uid = DB\insertOne('users', array('created_at' => new DateTime('now')), $returnId = true);
             $user = User::loadFromID($uid);
             $this->setActiveUser($user);
         }
         $widget->ownerID = $user->id;
         $widget->about = $_POST['about'];
         list($widget->width, $widget->height) = explode('x', $_POST['size']);
         $widget->color = $_POST['color'];
         $widget->countryCode = $this->getCountryCodeForIP();
         $widget->save();
         //$widget->updateProgress();
         $this->storeWidgetInSession($widget);
         return $this->redirect("/widget-wiz/step-three?w={$widget->id}");
     } else {
         return $this->renderStep('step-two.php', $widget);
     }
 }
Пример #10
0
 function index()
 {
     $users = User::loadAll();
     return $this->render('admin/users.diet-php', array('users' => $users));
 }
Пример #11
0
 function lostPass()
 {
     $noSuchAccount = false;
     $email = at($_POST, 'email', null);
     if ($email) {
         try {
             $user = User::loadFromEmailAddr($email);
             $confCode = ConfCodes\generateAndSave($user);
             $this->sendPassResetEmail($email, $confCode);
             /*
             $this->saveInSession('passwordResetEmailSent', true);
             return $this->redirect('/account/signin');
             */
             return $this->successMessage("<strong>We've sent you an email!</strong> Please check your inbox " . "and look for a link there that will help you reset your password.");
         } catch (NoSuchUser $_) {
             $noSuchAccount = true;
         }
     }
     return $this->render('account/lost-pass.diet-php', array('noSuchAccount' => $noSuchAccount, 'invalidConfCode' => $this->takeFromSession('invalidConfCode')));
 }
Пример #12
0
 function getOwner()
 {
     return User::loadFromID($this->ownerID);
 }