Companies: register web page with RECAPTCHA
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 20:36:39 +0000 (22:36 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 20:36:39 +0000 (22:36 +0200)
apps/companyfront/config/app.yml
apps/companyfront/config/routing.yml
apps/companyfront/modules/register/actions/actions.class.php [new file with mode: 0644]
apps/companyfront/modules/register/config/security.yml [new file with mode: 0644]
apps/companyfront/modules/register/config/view.yml [new file with mode: 0644]
apps/companyfront/modules/register/templates/_form.php [new file with mode: 0644]
apps/companyfront/modules/register/templates/indexSuccess.php [new file with mode: 0644]
apps/companyfront/modules/sfGuardAuth/templates/_signin_form.php
lib/form/doctrine/CompaniesRegisterForm.class.php [new file with mode: 0644]

index c36f791..2d31786 100644 (file)
@@ -18,3 +18,6 @@ all:
      remember_cookie_path:        /companyfront.php   # used by sfGuardSecurityUser.class.php. The scope of the Remeber cookie
      remember_cookie_domain:      .localhost
 
+  recaptcha:
+     private_key: 6Lcg9dESAAAAACrrfQ5l9OLp3nq93lN1ra1q-8Kn
+     public_key:  6Lcg9dESAAAAAG-QQLfE8By9c8ufO8WjuhBMz2-M
index 41a4507..b105651 100644 (file)
@@ -48,3 +48,7 @@ sf_guard_signin:
 sf_guard_signout:
   url:   /logout
   param: { module: sfGuardAuth, action: signout }
+
+register_index:
+  url:   /register
+  param: { module: register, action: index }
diff --git a/apps/companyfront/modules/register/actions/actions.class.php b/apps/companyfront/modules/register/actions/actions.class.php
new file mode 100644 (file)
index 0000000..7afdf37
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * api actions.
+ *
+ * @package    mobileadvertising
+ * @subpackage api
+ * @author     Gustavo Martin Morcuende
+ * @version
+ */
+class registerActions extends sfActions
+{
+ /**
+  * Executes index action
+  *
+  * @param sfRequest $request A request object
+  */
+  public function executeIndex(sfWebRequest $request)
+  {
+    if ($this->getUser()->isAuthenticated())
+    {
+      $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
+      $this->redirect('@homepage');
+    }
+
+
+    $this->form = new CompaniesRegisterForm();
+
+    if ($request->isMethod('post'))
+    {
+      $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
+                       'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
+                      );
+      $this->form->bind(array_merge($request->getParameter($this->form->getName()), array('captcha' => $captcha)));
+      if ($this->form->isValid())
+      {
+        $user = $this->form->save();
+        $user->addPermissionByName('companies');
+        $this->getUser()->signIn($user);
+
+        $this->redirect('@homepage');
+      }
+    }
+  }
+}
diff --git a/apps/companyfront/modules/register/config/security.yml b/apps/companyfront/modules/register/config/security.yml
new file mode 100644 (file)
index 0000000..72dcee0
--- /dev/null
@@ -0,0 +1,4 @@
+
+
+index:
+  is_secure: false
diff --git a/apps/companyfront/modules/register/config/view.yml b/apps/companyfront/modules/register/config/view.yml
new file mode 100644 (file)
index 0000000..4084c6e
--- /dev/null
@@ -0,0 +1,20 @@
+# You can find more information about this file on the symfony website:
+# http://www.symfony-project.org/reference/1_4/en/13-View
+
+default:
+  http_metas:
+    content-type: text/html
+
+  metas:
+    #title:        symfony project
+    #description:  symfony project
+    #keywords:     symfony, project
+    #language:     en
+    #robots:       index, follow
+
+  stylesheets:    [inadminpanel/style.css, inadminpanel/niceforms-default.css]
+
+  javascripts:    [jquery-1.6.2.min.js, inadminpanel/ddaccordion.js]
+
+  has_layout:     true
+  layout:         layoutsfGuardAuth
diff --git a/apps/companyfront/modules/register/templates/_form.php b/apps/companyfront/modules/register/templates/_form.php
new file mode 100644 (file)
index 0000000..b4f9ba0
--- /dev/null
@@ -0,0 +1,14 @@
+<?php use_helper('I18N') ?>
+
+<form action="<?php echo url_for('@register_index') ?>" method="post">
+  <table>
+    <?php echo $form ?>
+    <tfoot>
+      <tr>
+        <td colspan="2">
+          <input type="submit" name="register" value="<?php echo __('Register', null, 'sf_guard') ?>" />
+        </td>
+      </tr>
+    </tfoot>
+  </table>
+</form>
diff --git a/apps/companyfront/modules/register/templates/indexSuccess.php b/apps/companyfront/modules/register/templates/indexSuccess.php
new file mode 100644 (file)
index 0000000..f756829
--- /dev/null
@@ -0,0 +1,4 @@
+<?php use_helper('I18N') ?>
+<h1><?php echo __('Register', null, 'sf_guard') ?></h1>
+
+<?php include_partial('form', array('form' => $form)) ?>
index 924a8c7..b13e241 100644 (file)
@@ -15,8 +15,8 @@
             <a href="<?php echo url_for('@sf_guard_forgot_password') ?>"><?php echo __('Forgot your password?', null, 'sf_guard') ?></a>
           <?php endif; ?>
 
-          <?php if (isset($routes['sf_guard_register'])): ?>
-            &nbsp; <a href="<?php echo url_for('@sf_guard_register') ?>"><?php echo __('Want to register?', null, 'sf_guard') ?></a>
+          <?php if (isset($routes['register_index'])): ?>
+            &nbsp; <a href="<?php echo url_for('@register_index') ?>"><?php echo __('Want to register?', null, 'sf_guard') ?></a>
           <?php endif; ?>
         </td>
       </tr>
diff --git a/lib/form/doctrine/CompaniesRegisterForm.class.php b/lib/form/doctrine/CompaniesRegisterForm.class.php
new file mode 100644 (file)
index 0000000..049056a
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * CompaniesRegisterForm for registering new users
+ *
+ * @package    mobileadvertising
+ * @subpackage form
+ * @author     Gustavo Martin Morcuende
+ * @version
+ */
+class CompaniesRegisterForm extends UsersRegisterForm
+{
+  /**
+   * @see sfForm
+   */
+  public function configure()
+  { 
+    //Company creation form
+    $company = new Company();
+    $company->User = $this->getObject();
+    $newCompanyForm = new CompanyForm($company);
+
+    $this->embedForm('new', $newCompanyForm);
+
+    parent::configure();
+  }   
+}