Passed
Push — master ( 7a5639...e602b6 )
by Christian
09:25
created
drupal/sites/default/boinc/modules/boincuser/boincuser.module 1 patch
Switch Indentation   +447 added lines, -447 removed lines patch added patch discarded remove patch
@@ -27,287 +27,287 @@  discard block
 block discarded – undo
27 27
  * with defined URL paths
28 28
  */
29 29
 function boincuser_menu() {
30
-  $items['account/posts'] = array(
31
-    'title' => 'Recent posts',
32
-    'description' => '',
33
-    'page callback' => 'boincuser_goto_recent_posts',
34
-    'access callback' => 'user_is_logged_in',
35
-    'type' => MENU_CALLBACK,
36
-  );
37
-  $items['account/profile'] = array(
38
-    'title' => '',
39
-    'description' => '',
40
-    'page callback' => 'boincuser_view_profile',
41
-    'access callback' => 'user_is_logged_in',
42
-    'type' => MENU_NORMAL_ITEM
43
-  );
44
-  $items['account/profile/view'] = array(
45
-    'title' => 'View',
46
-    'description' => 'Show a user profile',
47
-    'page callback' => 'boincuser_view_profile',
48
-    'access callback' => 'user_is_logged_in',
49
-    'type' => MENU_DEFAULT_LOCAL_TASK,
50
-    'weight' => 0
51
-  );
52
-  $items['account/profile/edit'] = array(
53
-    'title' => 'Edit',
54
-    'description' => 'Edit a user profile',
55
-    'page callback' => 'boincuser_edit_profile',
56
-    'access callback' => 'user_is_logged_in',
57
-    'type' => MENU_LOCAL_TASK,
58
-    'weight' => 5
59
-  );
60
-  $items['account/team'] = array(
61
-    'title' => 'User team',
62
-    'description' => '',
63
-    'page callback' => 'boincuser_goto_team',
64
-    'access callback' => 'user_is_logged_in',
65
-    'type' => MENU_CALLBACK,
66
-  );
67
-  $items['moderate/profile/%user/approve'] = array(
68
-    'title' => 'Profile approval',
69
-    'description' => 'Approve profile content',
70
-    'page callback' => 'boincuser_moderate_profile_approve',
71
-    'page arguments' => array(2),
72
-    'access arguments' => array('edit any profile content'),
73
-    'type' => MENU_CALLBACK,
74
-    'weight' => 5
75
-  );
76
-  $items['moderate/profile/%user/edit'] = array(
77
-    'title' => 'Profile editor',
78
-    'description' => 'Edit a user profile',
79
-    'page callback' => 'boincuser_edit_profile',
80
-    'page arguments' => array(2),
81
-    'access arguments' => array('edit any profile content'),
82
-    'type' => MENU_CALLBACK,
83
-    'weight' => 5
84
-  );
85
-  $items['moderate/profile/%/reject'] = array(
86
-    'title' => bts('Reject profile', array(), NULL, 'boinc:moderate-user'),
87
-    'description' => 'Reject profile content',
88
-    'page callback' => 'drupal_get_form',
89
-    'page arguments' => array('boincuser_moderate_profile_reject_form', 2),
90
-    'access arguments' => array('edit any profile content'),
91
-    'type' => MENU_CALLBACK,
92
-    'weight' => 5
93
-  );
94
-  $items['moderate/user/%/ban'] = array(
95
-    'title' => bts('Ban user', array(), NULL, 'boinc:moderate-ban-user'),
96
-    'description' => 'Ban a user from using community features',
97
-    'page callback' => 'drupal_get_form',
98
-    'page arguments' => array('boincuser_moderate_user_ban_form', 2),
99
-    'access callback' => 'boincuser_moderate_community_access',
100
-    'type' => MENU_CALLBACK,
101
-  );
102
-  $items['join'] = array(
103
-    'title' => '',
104
-    'description' => '',
105
-    'page callback' => 'join_page',
106
-    'access arguments' => array('access content'),
107
-    'type' => MENU_NORMAL_ITEM
108
-  );
109
-  $items['join/new'] = array(
110
-    'title' => bts("I'm new"),
111
-    'page callback' => 'join_page',
112
-    'page arguments' => array(1),
113
-    'access arguments' => array('access content'),
114
-    'type' => MENU_DEFAULT_LOCAL_TASK,
115
-    'weight' => 0
116
-  );
117
-  $items['join/boinc'] = array(
118
-    'title' => bts("I'm a BOINC user"),
119
-    'page callback' => 'join_page',
120
-    'page arguments' => array(1),
121
-    'access arguments' => array('access content'),
122
-    'type' => MENU_LOCAL_TASK,
123
-    'weight' => 5
124
-  );
125
-  $items['user/login/auth'] = array(
126
-    'title' => bts('Authenticator login', array(), NULL, 'boinc:authenticator-login-page'),
127
-    'description' => 'Log in using a user authenticator',
128
-    'page callback' => 'drupal_get_form',
129
-    'page arguments' => array('boincuser_authloginform'),
130
-    'access arguments' => array('access content'),
131
-    'type' => MENU_CALLBACK,
132
-  );
133
-  $items['user/termsofuse'] = array(
134
-    'title' => bts('Terms of Use', array(), NULL, 'boinc:termsofuse-form'),
135
-    'description' => 'A site\'s term of use.',
136
-    'page callback' => 'drupal_get_form',
137
-    'page arguments' => array('boincuser_termsofuse_form'),
138
-    'access callback' => 'user_is_logged_in',
139
-    'type' => MENU_CALLBACK,
140
-  );
141
-  $items['user_control'] = array(
142
-    'page callback' => 'boincuser_control',
143
-    'access arguments' => array('access user profiles'),
144
-    'type' => MENU_CALLBACK
145
-  );
146
-  $items['admin/boinc'] = array(
147
-    'title' => 'BOINC configuration',
148
-    'position' => 'right',
149
-    'weight' => -8,
150
-    'page callback' => 'system_admin_menu_block_page',
151
-    'access arguments' => array('administer site configuration'),
152
-    'file' => 'system.admin.inc',
153
-    'file path' => drupal_get_path('module', 'system'),
154
-  );
155
-  $items['admin/boinc/environment'] = array(
156
-    'title' => 'Environment: General',
157
-    'description' => 'Set paths to BOINC functions and any other necessary
30
+$items['account/posts'] = array(
31
+'title' => 'Recent posts',
32
+'description' => '',
33
+'page callback' => 'boincuser_goto_recent_posts',
34
+'access callback' => 'user_is_logged_in',
35
+'type' => MENU_CALLBACK,
36
+);
37
+$items['account/profile'] = array(
38
+'title' => '',
39
+'description' => '',
40
+'page callback' => 'boincuser_view_profile',
41
+'access callback' => 'user_is_logged_in',
42
+'type' => MENU_NORMAL_ITEM
43
+);
44
+$items['account/profile/view'] = array(
45
+'title' => 'View',
46
+'description' => 'Show a user profile',
47
+'page callback' => 'boincuser_view_profile',
48
+'access callback' => 'user_is_logged_in',
49
+'type' => MENU_DEFAULT_LOCAL_TASK,
50
+'weight' => 0
51
+);
52
+$items['account/profile/edit'] = array(
53
+'title' => 'Edit',
54
+'description' => 'Edit a user profile',
55
+'page callback' => 'boincuser_edit_profile',
56
+'access callback' => 'user_is_logged_in',
57
+'type' => MENU_LOCAL_TASK,
58
+'weight' => 5
59
+);
60
+$items['account/team'] = array(
61
+'title' => 'User team',
62
+'description' => '',
63
+'page callback' => 'boincuser_goto_team',
64
+'access callback' => 'user_is_logged_in',
65
+'type' => MENU_CALLBACK,
66
+);
67
+$items['moderate/profile/%user/approve'] = array(
68
+'title' => 'Profile approval',
69
+'description' => 'Approve profile content',
70
+'page callback' => 'boincuser_moderate_profile_approve',
71
+'page arguments' => array(2),
72
+'access arguments' => array('edit any profile content'),
73
+'type' => MENU_CALLBACK,
74
+'weight' => 5
75
+);
76
+$items['moderate/profile/%user/edit'] = array(
77
+'title' => 'Profile editor',
78
+'description' => 'Edit a user profile',
79
+'page callback' => 'boincuser_edit_profile',
80
+'page arguments' => array(2),
81
+'access arguments' => array('edit any profile content'),
82
+'type' => MENU_CALLBACK,
83
+'weight' => 5
84
+);
85
+$items['moderate/profile/%/reject'] = array(
86
+'title' => bts('Reject profile', array(), NULL, 'boinc:moderate-user'),
87
+'description' => 'Reject profile content',
88
+'page callback' => 'drupal_get_form',
89
+'page arguments' => array('boincuser_moderate_profile_reject_form', 2),
90
+'access arguments' => array('edit any profile content'),
91
+'type' => MENU_CALLBACK,
92
+'weight' => 5
93
+);
94
+$items['moderate/user/%/ban'] = array(
95
+'title' => bts('Ban user', array(), NULL, 'boinc:moderate-ban-user'),
96
+'description' => 'Ban a user from using community features',
97
+'page callback' => 'drupal_get_form',
98
+'page arguments' => array('boincuser_moderate_user_ban_form', 2),
99
+'access callback' => 'boincuser_moderate_community_access',
100
+'type' => MENU_CALLBACK,
101
+);
102
+$items['join'] = array(
103
+'title' => '',
104
+'description' => '',
105
+'page callback' => 'join_page',
106
+'access arguments' => array('access content'),
107
+'type' => MENU_NORMAL_ITEM
108
+);
109
+$items['join/new'] = array(
110
+'title' => bts("I'm new"),
111
+'page callback' => 'join_page',
112
+'page arguments' => array(1),
113
+'access arguments' => array('access content'),
114
+'type' => MENU_DEFAULT_LOCAL_TASK,
115
+'weight' => 0
116
+);
117
+$items['join/boinc'] = array(
118
+'title' => bts("I'm a BOINC user"),
119
+'page callback' => 'join_page',
120
+'page arguments' => array(1),
121
+'access arguments' => array('access content'),
122
+'type' => MENU_LOCAL_TASK,
123
+'weight' => 5
124
+);
125
+$items['user/login/auth'] = array(
126
+'title' => bts('Authenticator login', array(), NULL, 'boinc:authenticator-login-page'),
127
+'description' => 'Log in using a user authenticator',
128
+'page callback' => 'drupal_get_form',
129
+'page arguments' => array('boincuser_authloginform'),
130
+'access arguments' => array('access content'),
131
+'type' => MENU_CALLBACK,
132
+);
133
+$items['user/termsofuse'] = array(
134
+'title' => bts('Terms of Use', array(), NULL, 'boinc:termsofuse-form'),
135
+'description' => 'A site\'s term of use.',
136
+'page callback' => 'drupal_get_form',
137
+'page arguments' => array('boincuser_termsofuse_form'),
138
+'access callback' => 'user_is_logged_in',
139
+'type' => MENU_CALLBACK,
140
+);
141
+$items['user_control'] = array(
142
+'page callback' => 'boincuser_control',
143
+'access arguments' => array('access user profiles'),
144
+'type' => MENU_CALLBACK
145
+);
146
+$items['admin/boinc'] = array(
147
+'title' => 'BOINC configuration',
148
+'position' => 'right',
149
+'weight' => -8,
150
+'page callback' => 'system_admin_menu_block_page',
151
+'access arguments' => array('administer site configuration'),
152
+'file' => 'system.admin.inc',
153
+'file path' => drupal_get_path('module', 'system'),
154
+);
155
+$items['admin/boinc/environment'] = array(
156
+'title' => 'Environment: General',
157
+'description' => 'Set paths to BOINC functions and any other necessary
158 158
       variables that establish a BOINC environment.',
159
-    'page callback' => 'drupal_get_form',
160
-    'page arguments' => array('boincuser_admin_environment'),
161
-    'access arguments' => array('administer site configuration'),
162
-    'type' => MENU_NORMAL_ITEM,
163
-    'file' => 'boincuser.admin.inc'
164
-  );
165
-  $items['admin/boinc/scheduler'] = array(
166
-    'title' => 'Environment: Scheduling server URLs',
167
-    'description' => 'Set BOINC scheduler options.',
168
-    'page callback' => 'drupal_get_form',
169
-    'page arguments' => array('boincuser_admin_scheduler'),
170
-    'access arguments' => array('administer site configuration'),
171
-    'type' => MENU_NORMAL_ITEM,
172
-    'file' => 'boincuser.admin.inc'
173
-  );
174
-  $items['admin/boinc/weboptions'] = array(
175
-    'title' => 'Environment: Website Options',
176
-    'description' => 'Set options configuring this Drupal-BOINC Web site.',
177
-    'page callback' => 'drupal_get_form',
178
-    'page arguments' => array('boincuser_admin_weboptions'),
179
-    'access arguments' => array('administer site configuration'),
180
-    'type' => MENU_NORMAL_ITEM,
181
-    'file' => 'boincuser.admin.inc'
182
-  );
159
+'page callback' => 'drupal_get_form',
160
+'page arguments' => array('boincuser_admin_environment'),
161
+'access arguments' => array('administer site configuration'),
162
+'type' => MENU_NORMAL_ITEM,
163
+'file' => 'boincuser.admin.inc'
164
+);
165
+$items['admin/boinc/scheduler'] = array(
166
+'title' => 'Environment: Scheduling server URLs',
167
+'description' => 'Set BOINC scheduler options.',
168
+'page callback' => 'drupal_get_form',
169
+'page arguments' => array('boincuser_admin_scheduler'),
170
+'access arguments' => array('administer site configuration'),
171
+'type' => MENU_NORMAL_ITEM,
172
+'file' => 'boincuser.admin.inc'
173
+);
174
+$items['admin/boinc/weboptions'] = array(
175
+'title' => 'Environment: Website Options',
176
+'description' => 'Set options configuring this Drupal-BOINC Web site.',
177
+'page callback' => 'drupal_get_form',
178
+'page arguments' => array('boincuser_admin_weboptions'),
179
+'access arguments' => array('administer site configuration'),
180
+'type' => MENU_NORMAL_ITEM,
181
+'file' => 'boincuser.admin.inc'
182
+);
183 183
   
184
-  $items['create_account.php'] = array(
185
-    'title' => 'Create Account RPC',
186
-    'description' => 'RPC for creating user accounts.',
187
-    'page callback' => 'boincuser_create_account',
188
-    'access callback' => TRUE,
189
-    'type' => MENU_CALLBACK
190
-  );
191
-  $items['account_finish.php'] = array(
192
-    'title' => 'Welcome to ' . variable_get('site_name', 'Drupal-BOINC'),
193
-    'description' => 'RPC for after a user has created an account.',
194
-    'page callback' => 'boincuser_account_finish',
195
-    'access callback' => TRUE,
196
-    'type' => MENU_CALLBACK,
197
-  );
198
-  $items['boincuser/autocomplete'] = array(
199
-    'page callback' => '_boincuser_user_name_autocomplete',
200
-    'access callback' => TRUE,
201
-    'type' => MENU_CALLBACK,
202
-  );
203
-  $items['user/%user/recoveremail/%'] = array(
204
-    'title' => t('Recover previous email'),
205
-    'description' => t('Form to revert email to previous address.'),
206
-    'page callback' => 'drupal_get_form',
207
-    'page arguments' => array('boincuser_revertemail', 3),
208
-    'access callback' => 'user_is_logged_in',
209
-    'type' => MENU_CALLBACK,
210
-  );
211
-  $items['recover_email.php'] = array(
212
-    'title' => t('Recover previous email'),
213
-    'description' => t('redirect'),
214
-    'page callback' => '_boincuser_redirect_recover_email',
215
-    'access callback' => TRUE,
216
-    'type' => MENU_CALLBACK,
217
-  );
218
-  return $items;
184
+$items['create_account.php'] = array(
185
+'title' => 'Create Account RPC',
186
+'description' => 'RPC for creating user accounts.',
187
+'page callback' => 'boincuser_create_account',
188
+'access callback' => TRUE,
189
+'type' => MENU_CALLBACK
190
+);
191
+$items['account_finish.php'] = array(
192
+'title' => 'Welcome to ' . variable_get('site_name', 'Drupal-BOINC'),
193
+'description' => 'RPC for after a user has created an account.',
194
+'page callback' => 'boincuser_account_finish',
195
+'access callback' => TRUE,
196
+'type' => MENU_CALLBACK,
197
+);
198
+$items['boincuser/autocomplete'] = array(
199
+'page callback' => '_boincuser_user_name_autocomplete',
200
+'access callback' => TRUE,
201
+'type' => MENU_CALLBACK,
202
+);
203
+$items['user/%user/recoveremail/%'] = array(
204
+'title' => t('Recover previous email'),
205
+'description' => t('Form to revert email to previous address.'),
206
+'page callback' => 'drupal_get_form',
207
+'page arguments' => array('boincuser_revertemail', 3),
208
+'access callback' => 'user_is_logged_in',
209
+'type' => MENU_CALLBACK,
210
+);
211
+$items['recover_email.php'] = array(
212
+'title' => t('Recover previous email'),
213
+'description' => t('redirect'),
214
+'page callback' => '_boincuser_redirect_recover_email',
215
+'access callback' => TRUE,
216
+'type' => MENU_CALLBACK,
217
+);
218
+return $items;
219 219
 }
220 220
 
221 221
 /**
222 222
  * Implementation of hook_init()
223 223
  */
224 224
 function boincuser_init() {
225
-  global $user;
226
-  // Skip this check for charts, which are loaded separately
227
-  // (may get duplicate or unexpected messages otherwise)
228
-  if (substr($_GET['q'], 0, 7) == 'charts/') {
229
-    return;
230
-  }
225
+global $user;
226
+// Skip this check for charts, which are loaded separately
227
+// (may get duplicate or unexpected messages otherwise)
228
+if (substr($_GET['q'], 0, 7) == 'charts/') {
229
+return;
230
+}
231 231
 
232
-  // If admin user, do some basic site functionality checks
233
-  if (user_access('administer site configuration')) {
234
-    // Ensure we have a configured BOINC environment
235
-    boinc_get_path();
236
-    boinc_get_scheduler_tags();
237
-  }
232
+// If admin user, do some basic site functionality checks
233
+if (user_access('administer site configuration')) {
234
+// Ensure we have a configured BOINC environment
235
+boinc_get_path();
236
+boinc_get_scheduler_tags();
237
+}
238 238
   
239
-  // Check credits for the verified contributor role
240
-  boincuser_check_credit_requirements();
239
+// Check credits for the verified contributor role
240
+boincuser_check_credit_requirements();
241 241
   
242
-  if (module_exists('boincteam')) {
243
-    // Display any persistent team messages
244
-    boincteam_show_messages();
245
-  }
242
+if (module_exists('boincteam')) {
243
+// Display any persistent team messages
244
+boincteam_show_messages();
245
+}
246 246
 
247
-  // Check if user has agreed to the terms of use. If not, send the
248
-  // user to the terms-of-use form. This is only makes sense if the
249
-  // termsofuse is enabled, by having text in the termsofuse variable.
250
-  $existinguser_tou = variable_get('boinc_weboptions_existinguser_tou', FALSE);
251
-  $termsofuse = variable_get('boinc_weboptions_termsofuse', '');
252
-  if ( (!empty($termsofuse)) and ($user->uid) ) {
253
-    if ( !boincuser_check_termsofuse($user) and ($existinguser_tou) ) {
254
-
255
-      // Admins are exempt, otherwise the admin may not be able to
256
-      // access the site!
257
-      $administrator_role = array_search('administrator', user_roles(true));
258
-      if (!isset($user->roles[$administrator_role])) {
259
-        $path = drupal_get_path_alias($_GET['q']);
260
-
261
-        // Any paths that should NOT be redirected go here.
262
-        // @todo - replace this static array with one that allows
263
-        // admins to specify custom paths (patterns) to ignore.
264
-        $paths_to_ignore = array(
265
-          'user/termsofuse',
266
-          'logout',
267
-          'privacy',
268
-          'moderation',
269
-          'account/info/edit',
270
-          'user/' . $user->uid . '/edit',
271
-          'user/' . $user->uid . '/recoveremail/*',
272
-          'recover_email.php',
273
-        );
274
-        if (module_exists('boincuser_delete')) {
275
-          $paths_to_ignore[] = 'user/' . $user->uid . '/delete';
276
-          $paths_to_ignore[] = 'user/' . $user->uid . '/deleteconfirm/*';
277
-          $paths_to_ignore[] = 'user/' . $user->uid . '/odeleteconfirm/*';
278
-        }
279
-        if (!_boincuser_ignore_paths($path, $paths_to_ignore)) {
280
-          drupal_goto('user/termsofuse');
281
-        }
282
-      }
247
+// Check if user has agreed to the terms of use. If not, send the
248
+// user to the terms-of-use form. This is only makes sense if the
249
+// termsofuse is enabled, by having text in the termsofuse variable.
250
+$existinguser_tou = variable_get('boinc_weboptions_existinguser_tou', FALSE);
251
+$termsofuse = variable_get('boinc_weboptions_termsofuse', '');
252
+if ( (!empty($termsofuse)) and ($user->uid) ) {
253
+if ( !boincuser_check_termsofuse($user) and ($existinguser_tou) ) {
254
+
255
+  // Admins are exempt, otherwise the admin may not be able to
256
+  // access the site!
257
+  $administrator_role = array_search('administrator', user_roles(true));
258
+  if (!isset($user->roles[$administrator_role])) {
259
+    $path = drupal_get_path_alias($_GET['q']);
260
+
261
+    // Any paths that should NOT be redirected go here.
262
+    // @todo - replace this static array with one that allows
263
+    // admins to specify custom paths (patterns) to ignore.
264
+    $paths_to_ignore = array(
265
+      'user/termsofuse',
266
+      'logout',
267
+      'privacy',
268
+      'moderation',
269
+      'account/info/edit',
270
+      'user/' . $user->uid . '/edit',
271
+      'user/' . $user->uid . '/recoveremail/*',
272
+      'recover_email.php',
273
+    );
274
+    if (module_exists('boincuser_delete')) {
275
+      $paths_to_ignore[] = 'user/' . $user->uid . '/delete';
276
+      $paths_to_ignore[] = 'user/' . $user->uid . '/deleteconfirm/*';
277
+      $paths_to_ignore[] = 'user/' . $user->uid . '/odeleteconfirm/*';
278
+    }
279
+    if (!_boincuser_ignore_paths($path, $paths_to_ignore)) {
280
+      drupal_goto('user/termsofuse');
283 281
     }
284 282
   }
285 283
 }
284
+}
285
+}
286 286
 
287 287
 /**
288 288
  * Implementation of hook_user(); add custom actions to standard
289 289
  * Drupal user operations
290 290
  */
291 291
 function boincuser_user($op, &$edit, &$account, $category = NULL) {
292
-  require_boinc('boinc_db');
293
-  require_boinc('user');
294
-  require_boinc('xml');
295
-
296
-  require_boinc('password_compat/password');
297
-  // Handle BOINC integration for users with UID > 1 (skip anonymous and admin)
298
-  if ($account->uid > 1) {
299
-    switch($op) {
300
-    case 'load':
301
-      // User loading; insert BOINC data into the user object
302
-      $drupal_user = db_fetch_object(db_query("
292
+require_boinc('boinc_db');
293
+require_boinc('user');
294
+require_boinc('xml');
295
+
296
+require_boinc('password_compat/password');
297
+// Handle BOINC integration for users with UID > 1 (skip anonymous and admin)
298
+if ($account->uid > 1) {
299
+switch($op) {
300
+case 'load':
301
+// User loading; insert BOINC data into the user object
302
+$drupal_user = db_fetch_object(db_query("
303 303
         SELECT boinc_id, penalty_expiration
304 304
         FROM {boincuser} WHERE uid = %d",
305
-        $account->uid
306
-      ));
307
-      $account->boincuser_id = $drupal_user->boinc_id;
308
-      $account->boincuser_penalty_expiration = $drupal_user->penalty_expiration;
309
-      db_set_active('boinc_rw');
310
-      $boinc_user = db_fetch_object(db_query("
305
+$account->uid
306
+));
307
+$account->boincuser_id = $drupal_user->boinc_id;
308
+$account->boincuser_penalty_expiration = $drupal_user->penalty_expiration;
309
+db_set_active('boinc_rw');
310
+$boinc_user = db_fetch_object(db_query("
311 311
         SELECT
312 312
           name,
313 313
           authenticator,
@@ -322,30 +322,30 @@  discard block
 block discarded – undo
322 322
           email_addr_change_time
323 323
         FROM {user}
324 324
         WHERE id = %d",
325
-        $account->boincuser_id
326
-      ));
327
-      $account->boincuser_name = $boinc_user->name;
328
-      $account->boincuser_account_key = $boinc_user->authenticator;
329
-      $account->boincuser_weak_auth = md5($boinc_user->authenticator . $boinc_user->passwd_hash);
330
-      $account->boincuser_total_credit = round($boinc_user->total_credit);
331
-      $account->boincuser_expavg_credit = round($boinc_user->expavg_credit);
332
-      $account->boincuser_expavg_time = round($boinc_user->expavg_time);
333
-      $account->boincuser_cpid = md5($boinc_user->cross_project_id . $account->mail);
334
-      $account->boincuser_default_pref_set = $boinc_user->venue;
335
-      $account->boincteam_id = $boinc_user->teamid;
336
-      $account->boincuser_previous_email_addr = $boinc_user->previous_email_addr;
337
-      $account->boincuser_email_addr_change_time = $boinc_user->email_addr_change_time;
338
-      db_set_active('default');
339
-      // Set Drupal team ID
340
-      $account->team = NULL;
341
-      if ($account->boincteam_id) {
342
-        $account->team = db_result(db_query("
325
+$account->boincuser_id
326
+));
327
+$account->boincuser_name = $boinc_user->name;
328
+$account->boincuser_account_key = $boinc_user->authenticator;
329
+$account->boincuser_weak_auth = md5($boinc_user->authenticator . $boinc_user->passwd_hash);
330
+$account->boincuser_total_credit = round($boinc_user->total_credit);
331
+$account->boincuser_expavg_credit = round($boinc_user->expavg_credit);
332
+$account->boincuser_expavg_time = round($boinc_user->expavg_time);
333
+$account->boincuser_cpid = md5($boinc_user->cross_project_id . $account->mail);
334
+$account->boincuser_default_pref_set = $boinc_user->venue;
335
+$account->boincteam_id = $boinc_user->teamid;
336
+$account->boincuser_previous_email_addr = $boinc_user->previous_email_addr;
337
+$account->boincuser_email_addr_change_time = $boinc_user->email_addr_change_time;
338
+db_set_active('default');
339
+// Set Drupal team ID
340
+$account->team = NULL;
341
+if ($account->boincteam_id) {
342
+$account->team = db_result(db_query("
343 343
           SELECT nid FROM {boincteam} WHERE team_id = %d",
344
-          $account->boincteam_id
345
-        ));
346
-      }
347
-      // Set post count
348
-      $account->post_count = db_result(db_query("
344
+$account->boincteam_id
345
+));
346
+}
347
+// Set post count
348
+$account->post_count = db_result(db_query("
349 349
         SELECT COUNT(*) +
350 350
         (
351 351
           SELECT COUNT(*) FROM {node}
@@ -357,13 +357,13 @@  discard block
 block discarded – undo
357 357
         INNER JOIN node ON comments.nid = node.nid
358 358
         WHERE comments.uid = '%d'
359 359
         AND node.status = 1",
360
-        $account->uid, $account->uid
361
-      ));
362
-      break;
360
+$account->uid, $account->uid
361
+));
362
+break;
363 363
       
364
-    case 'view':
365
-      // SAMPLE: Add BOINC data to the user profile
366
-      /*$account->content['summary']['boinc_id'] = array(
364
+case 'view':
365
+// SAMPLE: Add BOINC data to the user profile
366
+/*$account->content['summary']['boinc_id'] = array(
367 367
         '#type' => 'user_profile_item',
368 368
         '#title' => bts('BIONC ID'),
369 369
         '#value' => $account->boincuser_id,
@@ -377,174 +377,174 @@  discard block
 block discarded – undo
377 377
         '#attributes' => array('class' => 'boinc-data'),
378 378
         '#weight' => 10
379 379
       );*/
380
-      break;
380
+break;
381 381
       
382
-    case 'validate':
383
-      if (isset($edit['validation_source'])) {
384
-        switch ($edit['validation_source']) {
385
-        case 'user_account':
386
-          // Validate data before updating user account info
387
-          boincuser_account_validate($edit, $account);
388
-          break;
382
+case 'validate':
383
+if (isset($edit['validation_source'])) {
384
+switch ($edit['validation_source']) {
385
+case 'user_account':
386
+// Validate data before updating user account info
387
+boincuser_account_validate($edit, $account);
388
+break;
389 389
         
390
-        default:
390
+default:
391 391
           
392
-        }
393
-        // We don't want to save validation source, so remove it
394
-        $edit['validation_source'] = null;
395
-      }
396
-      break;
392
+}
393
+    // We don't want to save validation source, so remove it
394
+    $edit['validation_source'] = null;
395
+  }
396
+  break;
397 397
       
398
-    case 'insert':
399
-      // New user being added to the system
400
-      $imported = $_SESSION['importedUser'];
401
-      unset($_SESSION['importedUser']);
398
+case 'insert':
399
+  // New user being added to the system
400
+  $imported = $_SESSION['importedUser'];
401
+  unset($_SESSION['importedUser']);
402 402
       
403
-      watchdog(
404
-        'boincuser',
405
-        'Creating user account for %email_addr',
406
-        array('%email_addr' => $edit['mail']),
407
-        WATCHDOG_NOTICE
408
-      );
403
+  watchdog(
404
+    'boincuser',
405
+    'Creating user account for %email_addr',
406
+    array('%email_addr' => $edit['mail']),
407
+    WATCHDOG_NOTICE
408
+  );
409 409
       
410
-      // The create_acount RPC will call this block of code when
411
-      // user_save() is used. If user is registering using the Web
412
-      // registration form, create a BOINC user and relationships.
413
-      // Create a BOINC account unless importing from BOINC.
414
-      if (!$imported) {
410
+  // The create_acount RPC will call this block of code when
411
+  // user_save() is used. If user is registering using the Web
412
+  // registration form, create a BOINC user and relationships.
413
+  // Create a BOINC account unless importing from BOINC.
414
+  if (!$imported) {
415 415
 
416
-        // set email address lower-case
417
-        $lower_email_addr = strtolower($edit['mail']);
416
+    // set email address lower-case
417
+    $lower_email_addr = strtolower($edit['mail']);
418 418
 
419
-        if ($edit['boincuser_name']) {
420
-          $myname = $edit['boincuser_name'];
421
-        }
422
-        else if ($edit['name']) {
423
-          $myname = $edit['name'];
424
-        }
425
-        else {
426
-          $myname = 'noname';
427
-        }
419
+    if ($edit['boincuser_name']) {
420
+      $myname = $edit['boincuser_name'];
421
+    }
422
+    else if ($edit['name']) {
423
+      $myname = $edit['name'];
424
+    }
425
+    else {
426
+      $myname = 'noname';
427
+    }
428 428
 
429
-        $user_params = array(
430
-          'email_addr' => $lower_email_addr,
431
-          'name' => $myname,
432
-        );
429
+    $user_params = array(
430
+      'email_addr' => $lower_email_addr,
431
+      'name' => $myname,
432
+    );
433 433
 
434
-        // If the 'pass' variable is already a hash, then don't hash it again.
435
-        if ($edit['boinchash_flag']) {
436
-          $user_params['passwd_hash'] = $edit['pass'];
437
-        }
438
-        else {
439
-          // The passwd_hash here is only the md5() hash. This is
440
-          // because BOINC make_user(), called later, will run
441
-          // password_hash() on this md5 hash.
442
-          $user_params['passwd_hash'] = md5($edit['pass'].$lower_email_addr);
443
-        }
434
+    // If the 'pass' variable is already a hash, then don't hash it again.
435
+    if ($edit['boinchash_flag']) {
436
+      $user_params['passwd_hash'] = $edit['pass'];
437
+    }
438
+    else {
439
+      // The passwd_hash here is only the md5() hash. This is
440
+      // because BOINC make_user(), called later, will run
441
+      // password_hash() on this md5 hash.
442
+      $user_params['passwd_hash'] = md5($edit['pass'].$lower_email_addr);
443
+    }
444 444
 
445
-        $boinc_user = boincuser_register_make_user($user_params);
446
-        if (!$boinc_user) {
447
-          // Account exists with this email addr
448
-          form_set_error('email', bts('Error creating BOINC account.', array(), NULL, 'boinc:add-new-user'));
449
-          return;
450
-        }
445
+    $boinc_user = boincuser_register_make_user($user_params);
446
+    if (!$boinc_user) {
447
+      // Account exists with this email addr
448
+      form_set_error('email', bts('Error creating BOINC account.', array(), NULL, 'boinc:add-new-user'));
449
+      return;
450
+    }
451 451
 
452
-        // Add user to community role by default (not banned)
453
-        $unrestricted_role = array_search('community member', user_roles(true)); 
454
-        $edit['roles'] = array(
455
-          $unrestricted_role => ''
456
-        );
452
+    // Add user to community role by default (not banned)
453
+    $unrestricted_role = array_search('community member', user_roles(true)); 
454
+    $edit['roles'] = array(
455
+      $unrestricted_role => ''
456
+    );
457 457
 
458
-        // Disable show_hosts flag, set to TRUE by default
459
-        db_set_active('boinc_rw');
460
-        db_query("UPDATE {user} SET show_hosts=0 WHERE id='%d'", $boinc_user->id);
461
-        db_set_active('default');
458
+    // Disable show_hosts flag, set to TRUE by default
459
+    db_set_active('boinc_rw');
460
+    db_query("UPDATE {user} SET show_hosts=0 WHERE id='%d'", $boinc_user->id);
461
+    db_set_active('default');
462 462
 
463
-        // Cross reference Drupal account with BOINC
464
-        $reference = db_query("INSERT INTO {boincuser} SET uid='%d', boinc_id='%d'", $account->uid, $boinc_user->id);
465
-        if (!$reference) {
466
-          drupal_set_message(t('Error connecting BOINC account.'), 'error');
467
-          return;
468
-        }
463
+    // Cross reference Drupal account with BOINC
464
+    $reference = db_query("INSERT INTO {boincuser} SET uid='%d', boinc_id='%d'", $account->uid, $boinc_user->id);
465
+    if (!$reference) {
466
+      drupal_set_message(t('Error connecting BOINC account.'), 'error');
467
+      return;
468
+    }
469 469
 
470
-        // if terms of use exist, the user must agree.
471
-        $termsofuse = variable_get('boinc_weboptions_termsofuse', '');
472
-        if (!empty($termsofuse)) {
473
-          $reference2 = boincuser_consentto_termsofuse($account);
474
-        }
470
+    // if terms of use exist, the user must agree.
471
+    $termsofuse = variable_get('boinc_weboptions_termsofuse', '');
472
+    if (!empty($termsofuse)) {
473
+      $reference2 = boincuser_consentto_termsofuse($account);
474
+    }
475 475
 
476
-        // Don't save custom fields to the Drupal user object
477
-        $edit['boincuser_name'] = null;
478
-        $edit['boinchash_flag'] = null;
479
-        // Set email address to lower case in Drupal users table
480
-        if ($account) {
481
-          user_save($account, array('mail' => $lower_email_addr));
482
-        }
483
-      }
484
-      break;
476
+    // Don't save custom fields to the Drupal user object
477
+    $edit['boincuser_name'] = null;
478
+    $edit['boinchash_flag'] = null;
479
+    // Set email address to lower case in Drupal users table
480
+    if ($account) {
481
+      user_save($account, array('mail' => $lower_email_addr));
482
+    }
483
+  }
484
+  break;
485 485
       
486
-    case 'update':
487
-      if (isset($edit['update_source'])) {
488
-        require_boinc('boinc_db');
489
-        $boinc_user = BoincUser::lookup_id($account->boincuser_id);
490
-        switch ($edit['update_source']) {
491
-        case 'user_account':
492
-          // Ensure that BOINC data is altered
493
-
494
-          $changing_email = ($edit['mail'] AND $edit['mail'] != $boinc_user->email_addr) ? true : false;
495
-          $changing_pass = ($edit['pass']) ? true : false;
496
-          if ($changing_email OR $changing_pass) {
497
-            // set email address to lower-case
498
-            $lower_email_addr = strtolower($edit['mail']);
499
-
500
-            // Set password hash appropriately
501
-            $passwd = ($edit['pass']) ? $edit['pass'] : $edit['current_pass'];
502
-            $passwd_hash = password_hash( md5($passwd.$lower_email_addr), PASSWORD_DEFAULT );
503
-            // Algorithm for changing email and/or password
504
-            if ($changing_email) {
505
-              // locally store current email to set as previous email
506
-              $prev_email = $account->mail;
507
-              $mytime = (user_access('administer users')) ? $boinc_user->email_addr_change_time : time();
508
-              $querypart = "email_addr='{$lower_email_addr}', passwd_hash='{$passwd_hash}', previous_email_addr = '{$prev_email}', email_addr_change_time = $mytime";
509
-            }
510
-            else {
511
-              $querypart = "email_addr='{$lower_email_addr}', passwd_hash='{$passwd_hash}'";
512
-            }
513
-
514
-            // Update user account information
515
-            $result = $boinc_user->update($querypart);
516
-
517
-            if ($changing_email) {
518
-              // reload account
519
-              $account = user_load($account->uid);
520
-              _boincuser_send_emailchange($account, $lower_email_addr, $prev_email, user_access('administer users'));
521
-            }
522
-
523
-            // Change email to edit to lower-case version, this sets
524
-            // email in Drupal database to the lower-case email
525
-            // address.
526
-            $edit['mail'] = strtolower($lower_email_addr);
527
-          }
528
-
529
-          // Change boinc username
530
-          if ($edit['boincuser_name'] and ($edit['boincuser_name'] != $boinc_user->name)) {
531
-            $boincuser_name = $edit['boincuser_name'];
532
-            $result = $boinc_user->update(
533
-                "name='{$boincuser_name}'"
534
-            );
535
-          }
536
-
537
-          break;
538
-        case 'user_profile':
539
-          if ($edit['boincuser_name'] != $boinc_user->name) {
540
-            $boincuser_name = $edit['boincuser_name'];
541
-            $result = $boinc_user->update(
542
-                "name='{$boincuser_name}'"
543
-            );
544
-          }
545
-          break;
546
-        default:
547
-        }
486
+case 'update':
487
+  if (isset($edit['update_source'])) {
488
+    require_boinc('boinc_db');
489
+    $boinc_user = BoincUser::lookup_id($account->boincuser_id);
490
+    switch ($edit['update_source']) {
491
+    case 'user_account':
492
+    // Ensure that BOINC data is altered
493
+
494
+    $changing_email = ($edit['mail'] AND $edit['mail'] != $boinc_user->email_addr) ? true : false;
495
+    $changing_pass = ($edit['pass']) ? true : false;
496
+    if ($changing_email OR $changing_pass) {
497
+    // set email address to lower-case
498
+    $lower_email_addr = strtolower($edit['mail']);
499
+
500
+    // Set password hash appropriately
501
+    $passwd = ($edit['pass']) ? $edit['pass'] : $edit['current_pass'];
502
+    $passwd_hash = password_hash( md5($passwd.$lower_email_addr), PASSWORD_DEFAULT );
503
+    // Algorithm for changing email and/or password
504
+    if ($changing_email) {
505
+    // locally store current email to set as previous email
506
+    $prev_email = $account->mail;
507
+    $mytime = (user_access('administer users')) ? $boinc_user->email_addr_change_time : time();
508
+    $querypart = "email_addr='{$lower_email_addr}', passwd_hash='{$passwd_hash}', previous_email_addr = '{$prev_email}', email_addr_change_time = $mytime";
509
+    }
510
+    else {
511
+    $querypart = "email_addr='{$lower_email_addr}', passwd_hash='{$passwd_hash}'";
512
+    }
513
+
514
+    // Update user account information
515
+    $result = $boinc_user->update($querypart);
516
+
517
+    if ($changing_email) {
518
+    // reload account
519
+    $account = user_load($account->uid);
520
+    _boincuser_send_emailchange($account, $lower_email_addr, $prev_email, user_access('administer users'));
521
+    }
522
+
523
+    // Change email to edit to lower-case version, this sets
524
+    // email in Drupal database to the lower-case email
525
+    // address.
526
+    $edit['mail'] = strtolower($lower_email_addr);
527
+    }
528
+
529
+    // Change boinc username
530
+    if ($edit['boincuser_name'] and ($edit['boincuser_name'] != $boinc_user->name)) {
531
+    $boincuser_name = $edit['boincuser_name'];
532
+    $result = $boinc_user->update(
533
+    "name='{$boincuser_name}'"
534
+    );
535
+    }
536
+
537
+    break;
538
+    case 'user_profile':
539
+    if ($edit['boincuser_name'] != $boinc_user->name) {
540
+    $boincuser_name = $edit['boincuser_name'];
541
+    $result = $boinc_user->update(
542
+    "name='{$boincuser_name}'"
543
+    );
544
+    }
545
+    break;
546
+    default:
547
+    }
548 548
         // We don't want to save update source or duplicate custom fields, so
549 549
         // remove them before continuing to core Drupal routines
550 550
         $edit['update_source'] = null;
@@ -552,17 +552,17 @@  discard block
 block discarded – undo
552 552
       }
553 553
       break;
554 554
 
555
-    case 'login':
556
-      // Function is forward compatible to Drupal 7
557
-      boincuser_user_login($edit, $account);
558
-      break;
555
+case 'login':
556
+  // Function is forward compatible to Drupal 7
557
+  boincuser_user_login($edit, $account);
558
+  break;
559 559
 
560
-    case 'delete':
561
-      // Function is forward compatible to Drupal 7
562
-      boincuser_user_delete($account);
563
-      break;
560
+case 'delete':
561
+  // Function is forward compatible to Drupal 7
562
+  boincuser_user_delete($account);
563
+  break;
564 564
 
565
-    default:
565
+default:
566 566
       
567 567
     }
568 568
   }
Please login to merge, or discard this patch.