Skip to content

Commit 946fc86

Browse files
committed
Merge pull request #910 from rjmackay/2.6.x
2.6 post launch fixes
2 parents 6d41ec2 + f7cbc22 commit 946fc86

File tree

14 files changed

+345
-261
lines changed

14 files changed

+345
-261
lines changed

application/config/openlayers.ushahidi.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ OpenLayers/Layer/Google.js
3030
OpenLayers/Layer/Google/v3.js
3131
OpenLayers/Layer/Markers.js
3232
OpenLayers/Layer/OSM.js
33+
OpenLayers/Layer/TMS.js
3334
OpenLayers/Layer/Vector.js
3435
OpenLayers/Layer/WMS.js
3536
OpenLayers/Layer/XYZ.js

application/controllers/json.php

+48-7
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,21 @@ protected function markers_geojson($incidents, $category_id, $color, $icon, $inc
169169
{
170170
// Handle both reports::fetch_incidents() response and actual ORM objects
171171
$marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id;
172-
$latitude = isset($marker->latitude) ? $marker->latitude : $marker->location->latitude;
173-
$longitude = isset($marker->longitude) ? $marker->longitude : $marker->location->longitude;
172+
if (isset($marker->latitude) AND isset($marker->longitude))
173+
{
174+
$latitude = $marker->latitude;
175+
$longitude = $marker->longitude;
176+
}
177+
elseif (isset($marker->location) AND isset($marker->location->latitude) AND isset($marker->location->longitude))
178+
{
179+
$latitude = $marker->location->latitude;
180+
$longitude = $marker->location->longitude;
181+
}
182+
else
183+
{
184+
// No location - skip this report
185+
continue;
186+
}
174187

175188
// Get thumbnail
176189
$thumb = "";
@@ -296,16 +309,44 @@ protected function clusters_geojson($incidents, $category_id, $color, $icon)
296309
{
297310
$marker = array_pop($markers);
298311
$cluster = array();
312+
313+
// Handle both reports::fetch_incidents() response and actual ORM objects
314+
$marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id;
315+
if (isset($marker->latitude) AND isset($marker->longitude))
316+
{
317+
$marker_latitude = $marker->latitude;
318+
$marker_longitude = $marker->longitude;
319+
}
320+
elseif (isset($marker->location) AND isset($marker->location->latitude) AND isset($marker->location->longitude))
321+
{
322+
$marker_latitude = $marker->location->latitude;
323+
$marker_longitude = $marker->location->longitude;
324+
}
325+
else
326+
{
327+
// No location - skip this report
328+
continue;
329+
}
299330

300331
// Compare marker against all remaining markers.
301332
foreach ($markers as $key => $target)
302333
{
303334
// Handle both reports::fetch_incidents() response and actual ORM objects
304-
$marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id;
305-
$marker_latitude = isset($marker->latitude) ? $marker->latitude : $marker->location->latitude;
306-
$marker_longitude = isset($marker->longitude) ? $marker->longitude : $marker->location->longitude;
307-
$target_latitude = isset($target->latitude) ? $target->latitude : $target->location->latitude;
308-
$target_longitude = isset($target->longitude) ? $target->longitude : $target->location->longitude;
335+
if (isset($target->latitude) AND isset($target->longitude))
336+
{
337+
$target_latitude = $target->latitude;
338+
$target_longitude = $target->longitude;
339+
}
340+
elseif (isset($target->location) AND isset($target->location->latitude) AND isset($target->location->longitude))
341+
{
342+
$target_latitude = $target->location->latitude;
343+
$target_longitude = $target->location->longitude;
344+
}
345+
else
346+
{
347+
// No location - skip this report
348+
continue;
349+
}
309350

310351
// This function returns the distance between two markers, at a defined zoom level.
311352
// $pixels = $this->_pixelDistance($marker['latitude'], $marker['longitude'],

application/controllers/login.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,9 @@ public function index($user_id = 0)
320320
else
321321
{
322322
// Reset locally
323-
324-
// Secret consists of email and the last_login field.
325-
// So as soon as the user logs in again,
326-
// the reset link expires automatically.
327-
$secret = $auth->hash_password($user->email.$user->last_login);
328-
$secret_link = url::site('login/index/'.$user->id.'/'.$secret.'?reset');
329-
$email_sent = $this->_email_resetlink($post->resetemail,$user->name,$secret_link);
323+
$secret = $user->forgot_password_token();
324+
$secret_link = url::site('login/index/'.$user->id.'/'.urlencode($secret).'?reset');
325+
$email_sent = $this->_email_resetlink($post->resetemail, $user->name, $secret_link);
330326
}
331327

332328
if ($email_sent == TRUE)
@@ -870,8 +866,7 @@ private function _new_password($user_id = 0, $password, $token)
870866
else
871867
{
872868
// Use Standard
873-
874-
if($auth->hash_password($user->email.$user->last_login, $auth->find_salt($token)) == $token)
869+
if($user->check_forgot_password_token($token))
875870
{
876871
$user->password = $password;
877872
$user->save();

application/helpers/alert.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function _send_mobile_alert($post, $alert)
3131
// Should be 8 distinct characters
3232
$alert_code = text::random('distinct', 8);
3333

34-
$sms_from = $this->_sms_from();
34+
$sms_from = self::_sms_from();
3535

3636
$message = Kohana::lang('ui_admin.confirmation_code').$alert_code
3737
.'.'.Kohana::lang('ui_admin.not_case_sensitive');
@@ -196,7 +196,7 @@ public static function mobile_alerts_unsubscribe($message_from, $message_descrip
196196
return FALSE;
197197
}
198198

199-
$sms_from = $this->_sms_from();
199+
$sms_from = self::_sms_from();
200200

201201
$site_name = $settings->site_name;
202202
$message = Kohana::lang('ui_admin.unsubscribe_message').' ' .$site_name;

application/helpers/customforms.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ public static function get_custom_form_fields($incident_id = FALSE, $form_id = N
5555
// Check if the provided incident exists, then fill in the data
5656
if ($valid_incident)
5757
{
58-
$sql = "SELECT form_field.*, form_response.form_response
59-
FROM form_field
60-
LEFT JOIN roles ON (roles.id = field_ispublic_visible)
58+
$sql = "SELECT ff.*, fr.form_response
59+
FROM `{$table_prefix}form_field` ff
60+
LEFT JOIN `{$table_prefix}roles` r ON (r.id = field_ispublic_visible)
6161
LEFT JOIN
62-
form_response ON (
63-
form_response.form_field_id = form_field.id AND
64-
form_response.incident_id = :incident_id
62+
`{$table_prefix}form_response` fr ON (
63+
fr.form_field_id = ff.id AND
64+
fr.incident_id = :incident_id
6565
)
6666
WHERE (access_level <= :user_level OR access_level IS NULL) "
6767
. ( ! empty($form_id) ? "AND form_id = :form_id " : '')
6868
. "ORDER BY field_position ASC";
6969
}
7070
else
7171
{
72-
$sql = "SELECT form_field.*
73-
FROM form_field
74-
LEFT JOIN roles ON (roles.id = field_ispublic_visible)
72+
$sql = "SELECT ff.*
73+
FROM `{$table_prefix}form_field` ff
74+
LEFT JOIN `{$table_prefix}roles` r ON (r.id = field_ispublic_visible)
7575
WHERE (access_level <= :user_level OR access_level IS NULL) "
7676
. ( ! empty($form_id) ? "AND form_id = :form_id " : '')
7777
. "ORDER BY field_position ASC";

application/hooks/2_settings.php

+10
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@
6060
// Additional Mime Types (KMZ/KML)
6161
Kohana::config_set('mimes.kml', array('text/xml'));
6262
Kohana::config_set('mimes.kmz', array('text/xml'));
63+
64+
// Set 'settings.forgot_password_key' if not set already
65+
if ( ! Kohana::config('settings.forgot_password_secret'))
66+
{
67+
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+[]{};:,.?`~';
68+
$key = text::random($pool, 64);
69+
Settings_Model::save_setting('forgot_password_secret', $key);
70+
Kohana::config_set('settings.forgot_password_secret', $key);
71+
$cache->delete($subdomain.'_settings');
72+
}

application/models/settings.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static function save_setting($key, $value)
7878
{
7979
$setting = ORM::factory('settings')->where('key', $key)->find();
8080

81+
$setting->key = $key;
8182
$setting->value = $value;
8283
$setting->save();
8384
}

application/models/user.php

+35
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,40 @@ public function dashboard()
360360
// Send anyone else to login
361361
return 'login';
362362
}
363+
364+
/**
365+
* Get a new forgotten password challenge token for this user
366+
* @param string $salt Optional salt for token generation (use this)
367+
* @return string
368+
*/
369+
public function forgot_password_token()
370+
{
371+
return $this->_forgot_password_token();
372+
}
373+
374+
/**
375+
* Check to see if forgotten password token is valid
376+
* @param string $token token to check
377+
* @return boolean is token valid
378+
**/
379+
public function check_forgot_password_token($token)
380+
{
381+
$salt = substr($token, 0, 32);
382+
return $this->_forgot_password_token($salt) == $token;
383+
}
384+
385+
/**
386+
* Generate a forgotten password challenge token for this user
387+
* @param string $salt Optional salt for token generation (only use this for checking a token in URL)
388+
* @return string token
389+
*/
390+
private function _forgot_password_token($salt = FALSE)
391+
{
392+
// Secret consists of email and the last_login field.
393+
// So as soon as the user logs in again, the reset link expires automatically.
394+
$salt = $salt ? $salt : text::random('alnum', 32); // Limited charset to keep it URL friendly
395+
$key = Kohana::config('settings.forgot_password_secret');
396+
return $salt . hash_hmac('sha1', $this->last_login . $this->email, $salt . $key);
397+
}
363398

364399
} // End User_Model

application/views/admin/manage/categories/main.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@
211211
<?php if($category_trusted == 1) { ?>
212212
<div class="right">
213213
<?php if($category_id == '4') { ?>
214-
<a href="#" class="tooltip" title="<?php echo htmlentities(Kohana::lang('ui_admin.special_category_explanation'),ENT_QUOTES);?>"><strong><?php echo Kohana::lang('ui_admin.special_category');?></strong></a>
214+
<a href="#" class="tooltip" title="<?php echo htmlentities(Kohana::lang('ui_admin.special_category_explanation'),ENT_QUOTES, "UTF-8");?>"><strong><?php echo Kohana::lang('ui_admin.special_category');?></strong></a>
215215
<?php } else {?>
216-
<a href="#" class="tooltip" title="<?php echo htmlentities(Kohana::lang('ui_admin.none_category_explanation'),ENT_QUOTES); ?>"><strong><?php echo Kohana::lang('ui_admin.special_category');?></strong></a>
216+
<a href="#" class="tooltip" title="<?php echo htmlentities(Kohana::lang('ui_admin.none_category_explanation'),ENT_QUOTES, "UTF-8"); ?>"><strong><?php echo Kohana::lang('ui_admin.special_category');?></strong></a>
217217
<?php } ?>
218218
</div>
219219
<?php } ?>

application/views/header_nav.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<li class="header_nav_user header_nav_has_dropdown">
1414
<?php if($loggedin_user != FALSE){ ?>
1515

16-
<a href="<?php echo url::site().$loggedin_role;?>"><span class="header_nav_label"><?php echo htmlentities($loggedin_user->username); ?></span> <img alt="<?php echo htmlentities($loggedin_user->username, ENT_QUOTES); ?>" src="<?php echo htmlentities(members::gravatar($loggedin_user->email, 20), ENT_QUOTES); ?>" width="20" /></a>
16+
<a href="<?php echo url::site().$loggedin_role;?>"><span class="header_nav_label"><?php echo htmlentities($loggedin_user->username, ENT_QUOTES, "UTF-8"); ?></span> <img alt="<?php echo htmlentities($loggedin_user->username, ENT_QUOTES, "UTF-8"); ?>" src="<?php echo htmlentities(members::gravatar($loggedin_user->email, 20), ENT_QUOTES); ?>" width="20" /></a>
1717

1818
<ul class="header_nav_dropdown" style="display:none;">
1919
<?php if($loggedin_role != ""){ ?>

0 commit comments

Comments
 (0)