Esempio n. 1
0
 /**
  * Registration.
  *
  * We just ask for login, email and to agree with the terms. Then,
  * we go ahead and send a confirmation email. The confirmation
  * email will allow to set the password, first name and last name
  * of the user.
  */
 function register($request, $match)
 {
     $title = __('Create Your Account');
     $params = array('request' => $request);
     if ($request->method == 'POST') {
         $form = new IDF_Form_Register($request->POST, $params);
         if ($form->isValid()) {
             $user = $form->save();
             // It is sending the confirmation email
             $url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey');
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         if (isset($request->GET['login'])) {
             $params['initial'] = array('login' => $request->GET['login']);
         }
         $form = new IDF_Form_Register(null, $params);
     }
     $context = new Pluf_Template_Context(array());
     $tmpl = new Pluf_Template('idf/terms.html');
     $terms = Pluf_Template::markSafe($tmpl->render($context));
     return Pluf_Shortcuts_RenderToResponse('idf/register/index.html', array('page_title' => $title, 'form' => $form, 'terms' => $terms), $request);
 }
Esempio n. 2
0
 /**
  * Send the reminder email.
  *
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     $account = $this->cleaned_data['account'];
     $sql = new Pluf_SQL('email=%s OR login=%s', array($account, $account));
     $users = Pluf::factory('Pluf_User')->getList(array('filter' => $sql->gen()));
     $return_url = '';
     foreach ($users as $user) {
         if ($user->active) {
             $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode');
             $tmpl = new Pluf_Template('idf/user/passrecovery-email.txt');
             $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
             $code = trim($cr->encrypt($user->email . ':' . $user->id . ':' . time()), '~');
             $code = substr(md5(Pluf::f('secret_key') . $code), 0, 2) . $code;
             $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecovery', array($code), array(), false);
             $urlic = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode', array(), array(), false);
             $context = new Pluf_Template_Context(array('url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlic), 'user' => Pluf_Template::markSafe($user), 'key' => Pluf_Template::markSafe($code)));
             $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Password Recovery - InDefero'));
             $email->setReturnPath(Pluf::f('bounce_email', Pluf::f('from_email')));
             $email->addTextMessage($tmpl->render($context));
             $email->sendMail();
         }
         if (!$user->active and $user->first_name == '---') {
             $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey');
             IDF_Form_Register::sendVerificationEmail($user);
         }
     }
     return $return_url;
 }