]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add registration events to EmailregisterAction
authorZach Copley <zach@status.net>
Thu, 28 Apr 2011 22:53:17 +0000 (15:53 -0700)
committerZach Copley <zach@status.net>
Thu, 28 Apr 2011 22:53:17 +0000 (15:53 -0700)
plugins/EmailRegistration/emailregister.php

index d5ccf79f46f48a2329c3fd788ef8461dba1c1036..2d32b40456e891225878696012e76330e51645a3 100644 (file)
@@ -240,78 +240,85 @@ class EmailregisterAction extends Action
 
     function setPassword()
     {
-        if (!empty($this->invitation)) {
-            $email = trim($this->invitation->address);
-        } else if (!empty($this->confirmation)) {
-            $email = trim($this->confirmation->address);
-        } else {
-            throw new Exception('No confirmation thing.');
-        }
+        if (Event::handle('StartRegistrationTry', array($this))) {
+            if (!empty($this->invitation)) {
+                $email = trim($this->invitation->address);
+            } else if (!empty($this->confirmation)) {
+                $email = trim($this->confirmation->address);
+            } else {
+                throw new Exception('No confirmation thing.');
+            }
 
-        if (!$this->tos) {
-            // TRANS: Error text when trying to register without agreeing to the terms.
-            $this->error = _m('You must accept the terms of service and privacy policy to register.');
-            return;
-        } else if (empty($this->password1)) {
-            // TRANS: Error text when trying to register without a password.
-            $this->error = _m('You must set a password');
-        } else if (strlen($this->password1) < 6) {
-            // TRANS: Error text when trying to register with too short a password.
-            $this->error = _m('Password must be 6 or more characters.');
-        } else if ($this->password1 != $this->password2) {
-            // TRANS: Error text when trying to register without providing the same password twice.
-            $this->error = _m('Passwords do not match.');
-        }
+            if (!$this->tos) {
+                // TRANS: Error text when trying to register without agreeing to the terms.
+                $this->error = _m('You must accept the terms of service and privacy policy to register.');
+                return;
+            } else if (empty($this->password1)) {
+                // TRANS: Error text when trying to register without a password.
+                $this->error = _m('You must set a password');
+            } else if (strlen($this->password1) < 6) {
+                // TRANS: Error text when trying to register with too short a password.
+                $this->error = _m('Password must be 6 or more characters.');
+            } else if ($this->password1 != $this->password2) {
+                // TRANS: Error text when trying to register without providing the same password twice.
+                $this->error = _m('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;
+            }
 
-        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;
+            }
 
-        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.');
+            }
 
-        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);
 
-        common_set_user($this->user);
-        // this is a real login
-        common_real_login(true);
+            // Re-init language env in case it changed (not yet, but soon)
+            common_init_language();
 
-        // Re-init language env in case it changed (not yet, but soon)
-        common_init_language();
+            if (!empty($this->invitation)) {
+                $inviter = User::staticGet('id', $this->invitation->user_id);
+                if (!empty($inviter)) {
+                    Subscription::start($inviter->getProfile(),
+                                        $this->user->getProfile());
+                }
 
-        if (!empty($this->invitation)) {
-            $inviter = User::staticGet('id', $this->invitation->user_id);
-            if (!empty($inviter)) {
-                Subscription::start($inviter->getProfile(),
-                                    $this->user->getProfile());
+                $this->invitation->delete();
+            } else if (!empty($this->confirmation)) {
+                $this->confirmation->delete();
+            } else {
+                throw new Exception('No confirmation thing.');
             }
 
-            $this->invitation->delete();
-        } else if (!empty($this->confirmation)) {
-            $this->confirmation->delete();
-        } else {
-            throw new Exception('No confirmation thing.');
+            Event::handle('EndRegistrationTry', array($this));
         }
 
-        common_redirect(common_local_url('doc', array('title' => 'welcome')),
-                        303);
+        if (Event::handle('StartRegisterSuccess', array($this))) {
+            common_redirect(common_local_url('doc', array('title' => 'welcome')),
+                            303);
+            Event::handle('EndRegisterSuccess', array($this));
+        }
     }
 
     function sendConfirmEmail($confirm)