<?php
defined($security_key) or exit;

//------------------------------------------
// Get user_details based on securitykey
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//Define Query
$stmt = $pdo->prepare('SELECT * FROM users WHERE service = ? OR userkey = ?');
//Excute Query
$stmt->execute([$userkey, $userkey]);
//Get results
$user_data = $stmt->fetch();
//Define User data
$partnerhierarchy = $user_data['partnerhierarchy'];
$permission = userRights($user_data['view']);
$profile= getProfile($user_data['settings'],$permission);
$username = $user_data['username'];
$useremail = $user_data['email'];
$servicekey = $user_data['service'];
$partner = json_decode($partnerhierarchy);  
$language = $user_data['language'];
$clientsecret = $user_data['userkey'];

//Update Lastlogin
$logindate = date('Y-m-d H:i:s');
$stmt = $pdo->prepare('UPDATE users SET lastlogin = ? WHERE id = ?');
//Excute Query
$stmt->execute([$logindate, $user_data['id']]);

?>