Example #1
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);
 }
Example #2
0
 function signin()
 {
     $failure = false;
     if ($this->isPostRequest()) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $existingHash = $this->getStoredHashForUser($username);
         $isGood = Passwords\isValid($password, $existingHash);
         if ($isGood) {
             $user = User::loadFromUsername($username);
             $this->setAuthenticatedUser($user);
             return $this->redirect('/dashboard/');
         } else {
             $failure = true;
         }
     }
     return $this->render('account/signin.php', array('failure' => $failure, 'authenticationRequired' => $this->takeFromSession('authenticationRequired')));
 }
Example #3
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");
     }
 }
 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);
 }
Example #5
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'));
 }