示例#1
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));
     }
 }
 function stepOne()
 {
     $widget = $this->getWidget();
     $f = new Forms\Form('post');
     $f->addSection('step-one', array(Forms\newBasicTextField('title', 'Title'), Forms\newDollarAmountField('goal', 'Goal')->minAmount(0.001)->maxAmount(self::maxGoal, "Sorry, at the present time " . self::maxGoal . " is the maximum allowed goal."), Forms\newDateField('ending', 'End Date')->nameForValidation("Ending Date field"), Forms\newBasicTextField('bitcoinAddress', 'Bitcoin Address')));
     if ($this->isPostRequestAndFormIsValid($f)) {
         foreach (array('title', 'ending', 'bitcoinAddress') as $v) {
             $widget->{$v} = $_POST[$v];
         }
         $widget->setGoal($_POST['goal'], $_POST['currency']);
         $widget->uriID = URL\titleToUrlComponent($widget->title);
         if (at($_POST, 'save-and-return')) {
             $widget->save();
             return $this->redirect('/dashboard/');
         } else {
             $this->storeWidgetInSession($widget);
             return $this->redirect('/widget-wiz/step-two');
         }
     } else {
         return $this->renderStep('step-one.php', $widget, $f);
     }
 }