Пример #1
0
 function testUsersOverviewScreen()
 {
     newUser('*****@*****.**', 'some-user', 'abc');
     $u2 = newUser('*****@*****.**', 'other-user', 'def');
     DB\updateByID('users', $u2->id, array('created_at' => new \DateTime('now')));
     newUser('*****@*****.**', 'chris', 'secret!');
     $this->login('chris', 'secret!');
     $this->get('/admin/users/');
 }
Пример #2
0
 function signup()
 {
     $form = new F\Form('post');
     $form->addSection('account-details', array(F\newBasicTextField('username', 'Username')->minLength(5, "Sorry, the minimum allowed length for a username is five characters.")->addValidation(function ($un) {
         try {
             User::loadFromUsername($un);
             return array("Sorry &mdash; that username's already taken! If it belongs to you, " . "you can <a href=\"/account/lost-pass\">reset your password</a> " . "or <a href=\"/account/signin\">try to login here</a>.");
         } catch (NoSuchUser $_) {
             return array();
         }
     }), F\newEmailAddressField('email', "Email Address")->addValidation(function ($email) {
         try {
             User::loadFromEmailAddr($email);
             return array("It looks like you already have an account here, registered under " . "that email address. If you've forgotten your password, you can " . "<a href=\"/account/lost-pass\">reset it here</a>.");
         } catch (NoSuchUser $_) {
             return array();
         }
     }), F\newPasswordField('password1', 'Password')->required('Please provide a password'), F\newPasswordField('password2', 'Re-enter password')->required('Please confirm your password by entering it again.')->shouldMatch('password1', "The two entered passwords do not match."), F\newCheckboxField('chipin-updates', '', $checked = false), F\newCheckboxField('memorydealers-updates', '', $checked = false)));
     $form->addSubmitButton('Register');
     if ($this->isPostRequestAndFormIsValid($form)) {
         $username = $form->getValue("username");
         $passwordHashed = Passwords\hash($form->getValue("password1"));
         $email = $form->getValue("email");
         $recordValues = array('username' => $username, 'password' => $passwordHashed, 'email' => $email, 'created_at' => new DateTime('now'));
         $activeUser = $this->getActiveUser();
         if (empty($activeUser)) {
             # In this case, the user is most likely registering using the straight-up registration
             # form (as opposed to the post-Wizard signup form).
             DB\insertOne('users', $recordValues);
         } else {
             # In this case there's an "active user", one which created a widget and used the
             # post-Wizard signup form to register following widget creation.
             DB\updateByID('users', $activeUser->id, $recordValues);
         }
         $user = User::loadFromUsername($username);
         $this->setAuthenticatedUser($user);
         DB\insertOne('subscriptions', array('user_id' => $user->id, 'chipin' => $form->getValue('chipin-updates') ? 1 : 0, 'memorydealers' => $form->getValue('memorydealers-updates') ? 1 : 0));
         $this->userCreatedNotification($user);
         $this->saveInSession('successMessage', "You have successfully registered!");
         return $this->redirect("/dashboard/index/");
     } else {
         //      $captcha = $this->getCaptchaTool();
         $captcha = null;
         return $this->render('account/signup.php', array('form' => $form, 'captcha' => $captcha));
     }
 }
Пример #3
0
 function testAccessingWidgetWhoseOwnerHasNoUsernameSet()
 {
     $u = getUser();
     $u->username = null;
     DB\updateByID('users', $u->id, array('username' => null));
     $w = getWidget($u);
     $this->get("/widgets/by-id/{$w->id}");
     $this->assertContains("//div[contains(., '{$w->title}')]");
 }