Пример #1
0
 /**
  * Just a simple control.
  */
 public function clean_key()
 {
     $this->cleaned_data['key'] = trim($this->cleaned_data['key']);
     $error = __('We are sorry but this confirmation key is not valid. Maybe you should directly copy/paste it from your confirmation email.');
     if (false === ($email_id = IDF_Form_RegisterInputKey::checkKeyHash($this->cleaned_data['key']))) {
         throw new Pluf_Form_Invalid($error);
     }
     $guser = new Pluf_User();
     $sql = new Pluf_SQL('email=%s AND id=%s', $email_id);
     $users = $guser->getList(array('filter' => $sql->gen()));
     if ($users->count() != 1) {
         throw new Pluf_Form_Invalid($error);
     }
     if ($users[0]->active) {
         throw new Pluf_Form_Invalid(__('This account has already been confirmed. Maybe should you try to recover your password using the help link.'));
     }
     $this->_user_id = $email_id[1];
     return $this->cleaned_data['key'];
 }
Пример #2
0
 /**
  * Registration confirmation.
  *
  * Input first/last name, password and sign in the user.
  *
  * Maybe in the future send the user to its personal page for
  * customization.
  */
 function registerConfirmation($request, $match)
 {
     $title = __('Confirm Your Account Creation');
     $key = $match[1];
     // first "check", full check is done in the form.
     $email_id = IDF_Form_RegisterInputKey::checkKeyHash($key);
     if (false == $email_id) {
         $url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey');
         return new Pluf_HTTP_Response_Redirect($url);
     }
     $user = new Pluf_User($email_id[1]);
     $extra = array('key' => $key, 'user' => $user);
     if ($request->method == 'POST') {
         $form = new IDF_Form_RegisterConfirmation($request->POST, $extra);
         if ($form->isValid()) {
             $user = $form->save();
             $request->user = $user;
             $request->session->clear();
             $request->session->setData('login_time', gmdate('Y-m-d H:i:s'));
             $user->last_login = gmdate('Y-m-d H:i:s');
             $user->update();
             $request->user->setMessage(__('Welcome! You can now participate in the life of your project of choice.'));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views::index');
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_RegisterConfirmation(null, $extra);
     }
     return Pluf_Shortcuts_RenderToResponse('idf/register/confirmation.html', array('page_title' => $title, 'new_user' => $user, 'form' => $form), $request);
 }