]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Don't use bogus event in emailregistration
authorEvan Prodromou <evan@status.net>
Mon, 18 Apr 2011 23:33:12 +0000 (19:33 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 18 Apr 2011 23:33:12 +0000 (19:33 -0400)
I was trying to be smart by calling the same registration event as 'register'
when doing EmailRegistration. However, that event is so low-bandwidth that plugins
go fingerpoken in all the attributes and call methods on the passed-in action and
things like that.

So, now we just fall back to using the low-level stuff, catch any
exceptions, and feel happy. Some stuff might not work, but it's
generally anti-spam stuff more suited to public sites.

plugins/Blacklist/BlacklistPlugin.php
plugins/EmailRegistration/emailregister.php
plugins/RequireValidatedEmail/RequireValidatedEmailPlugin.php

index 92202dfb2e8349528fe99045a88c903e5b059c29..babf7031313e22565e0a0b366a009940834e585d 100644 (file)
@@ -141,9 +141,9 @@ class BlacklistPlugin extends Plugin
      *
      * @return boolean hook value
      */
-    function onStartRegistrationTry($action)
+    function onStartRegisterUser(&$user, &$profile)
     {
-        $homepage = strtolower($action->trimmed('homepage'));
+        $homepage = strtolower($profile->homepage);
 
         if (!empty($homepage)) {
             if (!$this->_checkUrl($homepage)) {
@@ -154,7 +154,7 @@ class BlacklistPlugin extends Plugin
             }
         }
 
-        $nickname = strtolower($action->trimmed('nickname'));
+        $nickname = strtolower($profile->nickname);
 
         if (!empty($nickname)) {
             if (!$this->_checkNickname($nickname)) {
index 9da6196ee5fd7fbcd4b8650e93297fcaeccbd718..1eb7d2c00007b4c0abf922913b999eb1eb982fb8 100644 (file)
@@ -264,66 +264,70 @@ class EmailregisterAction extends Action
 
     function setPassword()
     {
-        if (Event::handle('StartRegistrationTry', array($this))) {
-            if (!empty($this->invitation)) {
-                $email = $this->invitation->address;
-            } else if (!empty($this->confirmation)) {
-                $email = $this->confirmation->address;
-            } else {
-                throw new Exception('No confirmation thing.');
-            }
-
-            if (!$this->tos) {
-                $this->error = _('You must accept the terms of service and privacy policy to register.');
-                return;
-            } else if (empty($this->password1)) {
-                $this->error = _('You must set a password');
-            } else if (strlen($this->password1) < 6) {
-                $this->error = _('Password must be 6 or more characters.');
-            } else if ($this->password1 != $this->password2) {
-                $this->error = _('Passwords do not match.');
-            }
+        if (!empty($this->invitation)) {
+            $email = $this->invitation->address;
+        } else if (!empty($this->confirmation)) {
+            $email = $this->confirmation->address;
+        } else {
+            throw new Exception('No confirmation thing.');
+        }
 
-            if (!empty($this->error)) {
-                $nickname = $this->nicknameFromEmail($email);
-                $this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
-                $this->showPage();
-                return;
-            }
+        if (!$this->tos) {
+            $this->error = _('You must accept the terms of service and privacy policy to register.');
+            return;
+        } else if (empty($this->password1)) {
+            $this->error = _('You must set a password');
+        } else if (strlen($this->password1) < 6) {
+            $this->error = _('Password must be 6 or more characters.');
+        } else if ($this->password1 != $this->password2) {
+            $this->error = _('Passwords do not match.');
+        }
 
+        if (!empty($this->error)) {
             $nickname = $this->nicknameFromEmail($email);
+            $this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
+            $this->showPage();
+            return;
+        }
 
+        $nickname = $this->nicknameFromEmail($email);
+
+        try {
             $this->user = User::register(array('nickname' => $nickname,
                                                'email' => $email,
                                                'password' => $this->password1,
                                                'email_confirmed' => true));
+        } catch (ClientException $e) {
+            $this->error = $e->getMessage();
+            $nickname = $this->nicknameFromEmail($email);
+            $this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
+            $this->showPage();
+            return;
+        }
 
-            if (empty($this->user)) {
-                throw new Exception("Failed to register user.");
-            }
-
-            common_set_user($this->user);
-            // this is a real login
-            common_real_login(true);
+        if (empty($this->user)) {
+            throw new Exception("Failed to register user.");
+        }
 
-            // Re-init language env in case it changed (not yet, but soon)
-            common_init_language();
+        common_set_user($this->user);
+        // this is a real login
+        common_real_login(true);
 
-            if (!empty($this->invitation)) {
-                $inviter = User::staticGet('id', $this->invitation->user_id);
-                if (!empty($inviter)) {
-                    Subscription::start($inviter->getProfile(),
-                                        $this->user->getProfile());
-                }
+        // Re-init language env in case it changed (not yet, but soon)
+        common_init_language();
 
-                $this->invitation->delete();
-            } else if (!empty($this->confirmation)) {
-                $this->confirmation->delete();
-            } else {
-                throw new Exception('No confirmation thing.');
+        if (!empty($this->invitation)) {
+            $inviter = User::staticGet('id', $this->invitation->user_id);
+            if (!empty($inviter)) {
+                Subscription::start($inviter->getProfile(),
+                                    $this->user->getProfile());
             }
 
-            Event::handle('EndRegistrationTry', array($this));
+            $this->invitation->delete();
+        } else if (!empty($this->confirmation)) {
+            $this->confirmation->delete();
+        } else {
+            throw new Exception('No confirmation thing.');
         }
 
         common_redirect(common_local_url('doc', array('title' => 'welcome')),
index b6bd6f7e5fbeae4bc8c47ca44e22652c2e8fd181..0d4bc4da16db8f648e1cb1623e46c0999fad28d4 100644 (file)
@@ -147,6 +147,26 @@ class RequireValidatedEmailPlugin extends Plugin
         return true;
     }
 
+    /**
+     * Event handler for registration attempts; rejects the registration
+     * if email field is missing.
+     *
+     * @param Action $action Action being executed
+     *
+     * @return bool hook result code
+     */
+
+    function onStartRegisterUser(&$user, &$profile)
+    {
+        $email = $user->email;
+
+        if (empty($email)) {
+            throw new ClientException(_m('You must provide an email address to register.'));
+        }
+
+        return true;
+    }
+
     /**
      * Check if a user has a validated email address or has been
      * otherwise grandfathered in.