1: <?php
2: /**
3: * This class defines the abstract driver implementation for
4: * Horde_Core_Auth_Signup.
5: *
6: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you did
9: * not receive this file, see http://opensource.org/licenses/lgpl-2.1.php
10: *
11: * @author Marko Djukic <marko@oblo.com>
12: * @author Michael Slusarz <slusarz@horde.org>
13: * @category Horde
14: * @license http://opensource.org/licenses/lgpl-2.1.php LGPL
15: * @package Core
16: */
17: abstract class Horde_Core_Auth_Signup_Base
18: {
19: /**
20: * Adds a new user to the system and handles any extra fields that may have
21: * been compiled, relying on the hooks.php file.
22: *
23: * @param mixed $info Reference to array of parameters to be passed
24: * to hook.
25: *
26: * @throws Horde_Exception
27: */
28: public function addSignup(&$info)
29: {
30: // Perform any preprocessing if requested.
31: $this->_preSignup($info);
32:
33: // Attempt to add the user to the system.
34: $GLOBALS['auth']->addUser($info['user_name'], array('password' => $info['password']));
35:
36: // Attempt to add/update any extra data handed in.
37: if (!empty($info['extra'])) {
38: try {
39: Horde::callHook('signup_addextra', array($info['user_name'], $info['extra'], $info['password']));
40: } catch (Horde_Exception_HookNotSet $e) {
41: }
42: }
43: }
44:
45: /**
46: * Queues the user's submitted registration info for later admin approval.
47: *
48: * @param mixed $info Reference to array of parameters to be passed
49: * to hook.
50: *
51: * @throws Horde_Exception
52: * @throws Horde_Mime_Exception
53: */
54: public function queueSignup(&$info)
55: {
56: global $conf;
57:
58: // Perform any preprocessing if requested.
59: $this->_preSignup($info);
60:
61: // If it's a unique username, go ahead and queue the request.
62: $signup = $this->newSignup($info['user_name']);
63: if (!empty($info['extra'])) {
64: $signup->setData($info['extra']);
65: }
66: $signup->setData(array_merge($signup->getData(), array(
67: 'dateReceived' => time(),
68: 'password' => $info['password'],
69: )));
70:
71: $this->_queueSignup($signup);
72:
73: try {
74: Horde::callHook('signup_queued', array($info['user_name'], $info));
75: } catch (Horde_Exception_HookNotSet $e) {
76: }
77:
78: if (!empty($conf['signup']['email'])) {
79: $link = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/admin/signup_confirm.php', true, -1)->setRaw(true)->add(array(
80: 'u' => $signup->getName(),
81: 'h' => hash_hmac('sha1', $signup->getName(), $conf['secret_key'])
82: ));
83: $message = sprintf(Horde_Core_Translation::t("A new account for the user \"%s\" has been requested through the signup form."), $signup->getName())
84: . "\n\n"
85: . Horde_Core_Translation::t("Approve the account:")
86: . "\n" . $link->copy()->add('a', 'approve') . "\n"
87: . Horde_Core_Translation::t("Deny the account:")
88: . "\n" . $link->copy()->add('a', 'deny');
89: $mail = new Horde_Mime_Mail(array(
90: 'body' => $message,
91: 'Subject' => sprintf(Horde_Core_Translation::t("Account signup request for \"%s\""), $signup->getName()),
92: 'To' => $conf['signup']['email'],
93: 'From' => $conf['signup']['email']));
94: $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
95: }
96: }
97:
98: /**
99: * Perform common presignup actions.
100: *
101: * @param array $info Reference to array of parameters.
102: *
103: * @throws Horde_Exception
104: */
105: protected function _preSignup(&$info)
106: {
107: try {
108: $info = Horde::callHook('signup_preprocess', array($info));
109: } catch (Horde_Exception_HookNotSet $e) {
110: }
111:
112: // Check to see if the username already exists in the auth backend or
113: // the signup queue.
114: if ($GLOBALS['auth']->exists($info['user_name']) ||
115: $this->exists($info['user_name'])) {
116: throw new Horde_Exception(sprintf(Horde_Core_Translation::t("Username \"%s\" already exists."), $info['user_name']));
117: }
118: }
119:
120: /**
121: * Queues the user's submitted registration info for later admin approval.
122: *
123: * @param object $signup Signup data.
124: *
125: * @throws Horde_Exception
126: */
127: abstract protected function _queueSignup($signup);
128:
129: /**
130: * Get a user's queued signup information.
131: *
132: * @param string $username The username to retrieve the queued info for.
133: *
134: * @return object The object for the requested signup.
135: * @throws Horde_Exception
136: */
137: abstract public function getQueuedSignup($username);
138:
139: /**
140: * Get the queued information for all pending signups.
141: *
142: * @return array An array of objects, one for each signup in the queue.
143: * @throws Horde_Exception
144: */
145: abstract public function getQueuedSignups();
146:
147: /**
148: * Remove a queued signup.
149: *
150: * @param string $username The user to remove from the signup queue.
151: *
152: * @throws Horde_Exception
153: */
154: abstract public function removeQueuedSignup($username);
155:
156: /**
157: * Return a new signup object.
158: *
159: * @param string $name The signups's name.
160: *
161: * @return object A new signup object.
162: * @throws Horde_Exception
163: */
164: abstract public function newSignup($name);
165: }
166: