~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/register/classes/GalleryPendingUserHelper.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: GalleryPendingUserHelper.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.15 $ $Date: 2005/08/23 03:49:52 $
 
23
 * @version $Revision: 1.19 $ $Date: 2006/02/05 10:44:36 $
24
24
 * @package SelfRegistration
25
25
 * @author Sebastian Eichner <mailsp@sebastian-eichner.de>
26
26
 */
51
51
        WHERE [GalleryPendingUser::userName] = ?
52
52
        ';
53
53
        list ($ret, $searchResults) = $gallery->search($query, array($userName));
54
 
        if ($ret->isError()) {
 
54
        if ($ret) {
55
55
            return array($ret->wrap(__FILE__, __LINE__), null);
56
56
        }
57
57
 
58
58
        if ($searchResults->resultCount() == 0) {
59
 
            return array(GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__), null);
 
59
            return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__), null);
60
60
        } else {
61
61
            $result = $searchResults->nextResult();
62
 
            $id = $result[0];
 
62
            $id = (int)$result[0];
63
63
            list ($ret, $user) = GalleryCoreApi::loadEntitiesById($id);
64
 
            if ($ret->isError()) {
 
64
            if ($ret) {
65
65
                return array($ret->wrap(__FILE__, __LINE__), null);
66
66
            }
67
67
 
68
 
            return array(GalleryStatus::success(), $user);
 
68
            return array(null, $user);
69
69
        }
70
70
    }
71
71
 
89
89
        }
90
90
 
91
91
        list ($ret, $searchResults) = $gallery->search($query, $data);
92
 
        if ($ret->isError()) {
 
92
        if ($ret) {
93
93
            return array($ret->wrap(__FILE__, __LINE__), null);
94
94
        }
95
95
 
96
96
        $result = $searchResults->nextResult();
97
 
        return array(GalleryStatus::success(), (int)$result[0]);
 
97
        return array(null, (int)$result[0]);
98
98
    }
99
99
 
100
100
    /**
129
129
        $query .= ' ORDER BY [GalleryPendingUser::userName] ASC';
130
130
 
131
131
        list ($ret, $searchResults) = $gallery->search($query, $data,
132
 
             array('limit' => array('count' => $count, 'offset' => $offset)));
133
 
        if ($ret->isError()) {
 
132
             array('limit' => array('count' => (int)$count, 'offset' => (int)$offset)));
 
133
        if ($ret) {
134
134
            return array($ret->wrap(__FILE__, __LINE__), null);
135
135
        }
136
136
 
142
142
                                      'creationTimestamp' => (int)$result[4]);
143
143
        }
144
144
 
145
 
        return array(GalleryStatus::success(), $data);
 
145
        return array(null, $data);
146
146
    }
147
147
 
148
148
    /**
156
156
        global $gallery;
157
157
 
158
158
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'register');
159
 
        if ($ret->isError()) {
 
159
        if ($ret) {
160
160
            return $ret->wrap(__FILE__, __LINE__);
161
161
        }
162
162
        list($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'register');
163
 
        if ($ret->isError()) {
 
163
        if ($ret) {
164
164
            return $ret->wrap(__FILE__, __LINE__);
165
165
        }
166
166
 
167
167
        $generator =& $gallery->getUrlGenerator();
168
168
        $confirmationUrl = $generator->generateUrl(
169
 
                         array( 'controller' => 'register.ConfirmRegistration',
170
 
                                  /* Incoming url params will get sanitized, so decode here */
171
 
                                'username' =>
172
 
                                  GalleryUtilities::htmlEntityDecode($pendingUser->getUserName()),
173
 
                                'key' => $pendingUser->getRegistrationKey() ));
174
 
        $confirmationUrl = str_replace('&amp;', '&', $confirmationUrl);
175
 
        $baseUrl = str_replace('&amp;', '&', $generator->generateUrl());
 
169
            array('controller' => 'register.ConfirmRegistration',
 
170
                  /* Incoming url params will get sanitized, so decode here */
 
171
                  'username' => GalleryUtilities::htmlEntityDecode($pendingUser->getUserName()),
 
172
                  'key' => $pendingUser->getRegistrationKey()),
 
173
            array('forceFullUrl' => true, 'htmlEntities' => false));
 
174
        $baseUrl = $generator->generateUrl(
 
175
            array(), array('forceFullUrl' => true, 'htmlEntities' => false));
176
176
 
177
177
        $ret = GalleryCoreApi::sendTemplatedEmail(
178
178
                'modules/register/templates/ConfirmationEmail.tpl',
185
185
                $params['from'],
186
186
                $pendingUser->getEmail(),
187
187
                $module->translate($params['subject']));
188
 
        if ($ret->isError()) {
 
188
        if ($ret) {
189
189
            return $ret->wrap(__FILE__, __LINE__);
190
190
        }
191
191
 
192
 
        return GalleryStatus::success();
 
192
        return null;
193
193
    }
194
194
 
195
195
    /**
201
201
     */
202
202
    function sendAdminEmail(&$pendingUser) {
203
203
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'register');
204
 
        if ($ret->isError()) {
 
204
        if ($ret) {
205
205
            return $ret->wrap(__FILE__, __LINE__);
206
206
        }
207
207
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'register');
208
 
        if ($ret->isError()) {
 
208
        if ($ret) {
209
209
            return $ret->wrap(__FILE__, __LINE__);
210
210
        }
211
211
        list ($ret, $adminGroupId) =
212
212
            GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
213
 
        if ($ret->isError()) {
 
213
        if ($ret) {
214
214
            return $ret->wrap(__FILE__, __LINE__);
215
215
        }
216
216
        list ($ret, $adminUserIds) = GalleryCoreApi::fetchUsersForGroup($adminGroupId);
217
 
        if ($ret->isError()) {
 
217
        if ($ret) {
218
218
            return $ret->wrap(__FILE__, __LINE__);
219
219
        }
220
220
        list ($ret, $adminUsers) = GalleryCoreApi::loadEntitiesById(array_keys($adminUserIds));
221
 
        if ($ret->isError()) {
 
221
        if ($ret) {
222
222
            return $ret->wrap(__FILE__, __LINE__);
223
223
        }
224
224
        $toList = array();
240
240
                    $params['from'],
241
241
                    implode(',', $toList),
242
242
                    $module->translate($params['adminsubject']));
243
 
            if ($ret->isError()) {
 
243
            if ($ret) {
244
244
                return $ret->wrap(__FILE__, __LINE__);
245
245
            }
246
246
        }
247
247
 
248
 
        return GalleryStatus::success();
 
248
        return null;
249
249
    }
250
250
 
251
251
    /**
258
258
     */
259
259
    function createGalleryUser(&$pendingUser, $delete=true) {
260
260
        list ($ret, $user) = GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryUser');
261
 
        if ($ret->isError()) {
 
261
        if ($ret) {
262
262
            return $ret->wrap(__FILE__, __LINE__);
263
263
        }
264
264
 
265
265
        if (!isset($user)) {
266
 
            return GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__);
 
266
            return GalleryCoreApi::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__);
267
267
        }
268
268
 
269
269
        $ret = $user->create($pendingUser->getUserName());
270
 
        if ($ret->isError()) {
 
270
        if ($ret) {
271
271
            return $ret->wrap(__FILE__, __LINE__);
272
272
        }
273
273
 
278
278
        $user->setHashedPassword($pendingUser->getHashedPassword());
279
279
 
280
280
        $ret = $user->save();
281
 
        if ($ret->isError()) {
 
281
        if ($ret) {
282
282
            return $ret->wrap(__FILE__, __LINE__);
283
283
        }
284
284
 
287
287
        $event = GalleryCoreApi::newEvent($eventName);
288
288
        $event->setEntity($pendingUser);
289
289
        list ($ret) = GalleryCoreApi::postEvent($event);
290
 
        if ($ret->isError()) {
 
290
        if ($ret) {
291
291
            return  $ret->wrap(__FILE__, __LINE__);
292
292
        }
293
293
 
294
294
        if ($delete) {
295
295
            list($ret, $lock) = GalleryCoreApi::acquireWriteLock(array($pendingUser->getId()));
296
 
            if ($ret->isError()) {
 
296
            if ($ret) {
297
297
                return $ret->wrap(__FILE__, __LINE__);
298
298
            }
299
299
 
300
300
            $ret = $pendingUser->delete();
301
 
            if ($ret->isError()) {
 
301
            if ($ret) {
302
302
                return $ret->wrap(__FILE__, __LINE__);
303
303
            }
304
304
 
305
305
            $ret = GalleryCoreApi::releaseLocks($lock);
306
 
            if ($ret->isError()) {
 
306
            if ($ret) {
307
307
                return $ret->wrap(__FILE__, __LINE__);
308
308
            }
309
309
        }
310
310
 
311
 
        return GalleryStatus::success();
 
311
        return null;
312
312
    }
313
313
}
314
314
?>