Add a 'one-click' imap registration page.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 10:37:28 +0000 (12:37 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 10:37:28 +0000 (12:37 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/email.php
templates/emails/imap_register.tpl [new file with mode: 0644]

index 63cd1ab..1961dc5 100644 (file)
@@ -33,6 +33,8 @@ class EmailModule extends PLModule
             'emails/antispam/submit'  => $this->make_hook('submit', AUTH_COOKIE),
             'emails/test'     => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH),
 
+            'emails/imap/in'  => $this->make_hook('imap_in', AUTH_PUBLIC),
+
             'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
             'admin/emails/watch'      => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
             'admin/emails/lost'       => $this->make_hook('lost', AUTH_MDP, 'admin'),
@@ -443,6 +445,34 @@ class EmailModule extends PLModule
         exit;
     }
 
+    function handler_imap_in(&$page, $hash = null, $login = null)
+    {
+        $page->changeTpl('emails/imap_register.tpl');
+        $id = null;
+        if (!empty($hash) || !empty($login)) {
+            $req = XDB::query("SELECT  u.prenom, id
+                                 FROM  aliases AS a
+                           INNER JOIN  newsletter_ins AS ni ON (a.id = ni.user_id)
+                           INNER JOIN  auth_user_md5 AS u ON (u.user_id = a.id)
+                                WHERE  a.alias = {?} AND ni.hash = {?}", $login, $hash);
+            list($prenom, $id) = $req->fetchOneRow();
+        }
+
+        require_once('emails.inc.php');
+        $page->assign('ok', false);
+        if (S::logged() && (is_null($id) || $id == S::i('uid'))) {
+            $storage = new EmailStorage(S::i('uid'), 'imap');
+            $storage->activate();
+            $page->assign('ok', true);
+            $page->assign('prenom', S::v('prenom'));
+        } else if (!S::logged() && $id) {
+            $storage = new EmailStorage($id, 'imap');
+            $storage->activate();
+            $page->assign('ok', true);
+            $page->assign('prenom', $prenom);
+        }
+    }
+
     function handler_broken(&$page, $warn = null, $email = null)
     {
         require_once 'emails.inc.php';
diff --git a/templates/emails/imap_register.tpl b/templates/emails/imap_register.tpl
new file mode 100644 (file)
index 0000000..62581f3
--- /dev/null
@@ -0,0 +1,44 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2008 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{if $ok}
+<p>
+  Cher {$prenom},
+</p>
+
+<p>
+le stockage de secours de tes emails a été activé avec succès. Tu trouveras d'avantages d'informations à ce
+sujet sur la page de <a href="Xorg/IMAP">documentation</a>.
+</p>
+
+<p>
+Tu peux également modifier à tout moment ton abonnement à ce service en te rendant sur la page de
+<a href="emails/redirect">gestion de tes redirections</a>.
+</p>
+{else}
+<p class="erreur">
+Une erreur s'est produite lors de ton inscription au service de stockage de secours. N'hésite pas à nous signaler le
+problème en écrivant à <a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.
+</p>
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}