From 3310a85ac8f276ad270388a4242b623f30abe74d Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 15 Jan 2017 08:07:54 -0800 Subject: store the user's timezone after their location is found --- controllers/controllers.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'controllers') diff --git a/controllers/controllers.php b/controllers/controllers.php index 4de4aee..505589f 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -213,6 +213,25 @@ $app->post('/prefs', function() use($app) { ))); }); +$app->post('/prefs/timezone', function() use($app) { + // Called when the interface finds the user's location. + // Look up the timezone for this location and store it as their default. + $timezone = false; + if($user=require_login($app)) { + $params = $app->request()->params(); + $timezone = p3k\Timezone::timezone_for_location($params['latitude'], $params['longitude']); + if($timezone) { + $user->default_timezone = $timezone; + $user->save(); + } + } + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'result' => 'ok', + 'timezone' => $timezone, + ))); +}); + $app->get('/add-to-home', function() use($app) { $params = $app->request()->params(); header("Cache-Control: no-cache, must-revalidate"); -- cgit v1.2.3