<?php
defined($security_key) or exit;

//------------------------------------------
// Get user_details based on securitykey
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname_users);
//Define Query
$stmt = $pdo->prepare('SELECT * FROM users WHERE service = ? OR userkey = ?');
//Excute Query
$stmt->execute([$userkey, $userkey]);
// Check if username exists.
if ($stmt->rowCount() == 1) {
    //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'];
    $servicekey = $user_data['service'];
    $language = $user_data['language'];
    $partner = json_decode($partnerhierarchy);  

    //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']]);
} else 
{
    http_response_code(403);//Not authorized
}

?>