cmxx - Improved login
This commit is contained in:
211
reset.php
211
reset.php
@@ -3,7 +3,6 @@
|
||||
include './assets/functions.php';
|
||||
include './settings/settings_redirector.php';
|
||||
include './settings/config_redirector.php';
|
||||
include_once './settings/translations/translations_US.php';
|
||||
|
||||
// Check if the user is already logged in, if yes then redirect him to welcome page
|
||||
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
|
||||
@@ -11,6 +10,38 @@ if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
|
||||
exit();
|
||||
}
|
||||
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
//=========================================
|
||||
//GET Language
|
||||
//=========================================
|
||||
if (isset($_GET['language']) && $_GET['language'] !=''){
|
||||
//INCLUDE LANGUAGE FILE
|
||||
$api_file_language = './settings/translations/translations_'.strtoupper($_GET['language']).'.php';
|
||||
if (file_exists($api_file_language)){
|
||||
include $api_file_language; //Include the code
|
||||
//DEFINE LANGUAGE
|
||||
$_SESSION['country_code'] = trim($_GET['language']);
|
||||
}
|
||||
else {
|
||||
include './settings/translations/translations_US.php';
|
||||
//DEFINE LANGUAGE
|
||||
$_SESSION['country_code'] = 'US';
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_SESSION['country_code'])){
|
||||
$api_file_language = './settings/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
|
||||
if (file_exists($api_file_language)){
|
||||
include $api_file_language; //Include the code
|
||||
}
|
||||
else {
|
||||
include './settings/translations/translations_US.php';
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================
|
||||
//GET DOMAIN FOR CORRECT STYLING AND SETTINGS
|
||||
$domain = getDomainName($_SERVER['SERVER_NAME']);
|
||||
@@ -24,7 +55,7 @@ $username_err = $password_err = '';
|
||||
if ($_POST['submit'] === 'Reset' && $_POST['username'] !='EMP-updater') {
|
||||
// Check if username is empty
|
||||
if(empty(trim($_POST['username']))){
|
||||
$username_err = 'Please enter username.';
|
||||
$username_err = $username_enter ?? 'Please enter username';
|
||||
} else{
|
||||
$username = trim($_POST['username']);
|
||||
}
|
||||
@@ -39,7 +70,7 @@ if ($_POST['submit'] === 'Reset' && $_POST['username'] !='EMP-updater') {
|
||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
$usernameerr = 'Not authorized, please retry';
|
||||
$username_err = $password_err_1 ?? 'Not authorized, please retry';
|
||||
} else {
|
||||
|
||||
$username_err = $reset_message;
|
||||
@@ -83,10 +114,10 @@ if (isset($_POST['resetkey']) && $_POST['resetkey'] !='' && $_POST['password_upd
|
||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
$usernameerr = 'Not authorized, please retry';
|
||||
$username_err = $password_err_1 ?? 'Not authorized, please retry';
|
||||
} else {
|
||||
// success
|
||||
$username_err = 'You will be redirected';
|
||||
$username_err = $redirect_succes ?? 'You will be redirected';
|
||||
//redirect to login page
|
||||
header("Refresh:2; url=index.php");
|
||||
}
|
||||
@@ -94,7 +125,7 @@ if (isset($_POST['resetkey']) && $_POST['resetkey'] !='' && $_POST['password_upd
|
||||
//$username_err = 'You will be redirected';
|
||||
}
|
||||
else {
|
||||
$username_err = 'Passwords do not match';
|
||||
$username_err = $password_err_3 ?? 'Passwords do not match';
|
||||
$reset_id_valid = 1;
|
||||
}
|
||||
}
|
||||
@@ -117,7 +148,7 @@ if (isset($_GET['resetkey']) && $_GET['resetkey'] !=''){
|
||||
$username_err = $reset_message2 ;
|
||||
|
||||
//redirect to login page
|
||||
header("Refresh:5; url=index.php");
|
||||
header("Refresh:3; url=index.php");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -125,69 +156,125 @@ echo'
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
|
||||
<title>'.site_title.'</title>
|
||||
<link rel="shortcut icon" href="'.icon_image.'" type="image/x-icon" />
|
||||
<link href="'.$custom_css.'" rel="stylesheet" type="text/css">
|
||||
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
|
||||
<title>'.site_title.'</title>
|
||||
<link rel="shortcut icon" href="'.icon_image.'" type="image/x-icon" />
|
||||
<link href="'.$custom_css.'" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
';
|
||||
|
||||
//Maintenance mode notification message
|
||||
if (maintenance_mode_communication){
|
||||
//Logon view
|
||||
echo'
|
||||
<p style="text-align: center;">
|
||||
<small>'.maintenance_mode_notification.'</small>
|
||||
</p>';
|
||||
}
|
||||
<div class="login-container">
|
||||
<div class="login-form">
|
||||
<div class="logo"></div>
|
||||
<a href="#" class="register-link"></a>';
|
||||
|
||||
if (maintenance_mode)
|
||||
{
|
||||
//Maintenance mode is on => Show maintenance mode text
|
||||
echo '
|
||||
<div class="message">
|
||||
<p>'.maintenance_mode_text.'</p>
|
||||
</div>
|
||||
';
|
||||
|
||||
//Logon view
|
||||
echo'
|
||||
<div class="logon">
|
||||
<div class="logon_center" style="position: static;">
|
||||
<div id="imagelogon"></div>
|
||||
<div class="login-box">
|
||||
<small style="color:#fff;">'.site_title.'</small>
|
||||
<h1>'.site_name.'</h1>
|
||||
';
|
||||
|
||||
if (maintenance_mode)
|
||||
{
|
||||
//Maintenance mode is on => Show maintenance mode text
|
||||
echo '
|
||||
<p style="margin-top: 10%;color: white;">'.maintenance_mode_text.'</p>
|
||||
';
|
||||
} else {
|
||||
//Maintenance mode is off => Show login
|
||||
echo '
|
||||
<form style="margin-top:15px;" action="'.$_SERVER['PHP_SELF'].'" method="POST">
|
||||
';
|
||||
if ($reset_id_valid != 1){
|
||||
echo'
|
||||
<input type="text" id="username" name="username" placeholder="Username" value="'; echo $username; echo '" autofocus>
|
||||
<div id="reset"><a href="index.php">Back to login</a></div>
|
||||
<input type="hidden" name="submit" value="Reset">
|
||||
<input type="submit" value="Request reset">
|
||||
';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//Maintenance mode is off => Show login
|
||||
echo '
|
||||
<input type="hidden" id="resetkey" name="resetkey" value="'.$resetkey.'">
|
||||
<input type="password" id="password_new" name="password" min="8" max="20" placeholder="New Password" autofocus>
|
||||
<input type="password" id="password_update" name="password_update" min="8" max="20" placeholder="Repeat password">
|
||||
<input type="submit" name="submit" value="Update password">
|
||||
';
|
||||
}
|
||||
<div class="header">
|
||||
<h1>'.($login_reset_h1 ?? 'Forgot your password').'</h1>
|
||||
<p>'.($login_reset_p ?? 'Enter your username to reset password.').'</p>
|
||||
</div>
|
||||
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
|
||||
|
||||
echo' </form>
|
||||
<div id="message"><p>'.$username_err.'<p></div>
|
||||
';
|
||||
}
|
||||
echo '
|
||||
|
||||
</div>
|
||||
if ($reset_id_valid != 1){
|
||||
echo'
|
||||
<div class="input-group">
|
||||
<input type="text" id="username" name="username" placeholder="'.($User_username ?? 'Username').'" value="'.$username.'" autofocus>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<a href="index.php" class="forgot-password">'.($button_back_to_login ?? 'Back to login').'</a>
|
||||
<input type="hidden" name="submit" value="Reset">
|
||||
</div>';
|
||||
} else {
|
||||
echo '
|
||||
<div class="input-group">
|
||||
<input type="hidden" id="resetkey" name="resetkey" value="'.$resetkey.'">
|
||||
<input type="password" id="password_new" name="password" min="8" max="20" placeholder="'.($password_new ?? 'New Password').'" autofocus>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<input type="password" id="password_update" name="password_update" min="8" max="20" placeholder="'.($password_check ?? 'Repeat password').'">
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo'
|
||||
<div class="remember-me">
|
||||
<label for="remember-me"></label>
|
||||
</div>';
|
||||
|
||||
if ($reset_id_valid != 1){
|
||||
echo '
|
||||
<button type="submit" class="login-btn">'.($button_reset ?? 'Request reset').'</button>
|
||||
';
|
||||
} else {
|
||||
echo '
|
||||
<button type="submit" name="submit" class="login-btn">'.($button_password_update ?? 'Update password').'</button>
|
||||
';
|
||||
}
|
||||
echo '
|
||||
|
||||
</form>';
|
||||
}
|
||||
|
||||
if($username_err != ''){
|
||||
echo'
|
||||
<div class="message"><p>'.$username_err.'</p></div>
|
||||
';
|
||||
}
|
||||
//Maintenance mode notification message
|
||||
if (maintenance_mode_communication){
|
||||
echo'
|
||||
<div class="maintenance">
|
||||
<p style="text-align: center;">
|
||||
<small>'.maintenance_mode_notification.'</small>
|
||||
</p>
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo'
|
||||
<div class="trademark">'.site_title.'</div>
|
||||
<div class="language-selector">
|
||||
<span>🌐</span>
|
||||
<select id="language-selector">
|
||||
<option value="US" '.((isset($_SESSION['country_code']) && $_SESSION['country_code'] == 'US') ? 'selected' : '').'>US</option>
|
||||
<option value="NL" '.((isset($_SESSION['country_code']) && $_SESSION['country_code'] == 'NL') ? 'selected' : '').'>NL</option>
|
||||
<option value="ES" '.((isset($_SESSION['country_code']) && $_SESSION['country_code'] == 'ES') ? 'selected' : '').'>ES</option>
|
||||
<option value="PT" '.((isset($_SESSION['country_code']) && $_SESSION['country_code'] == 'PT') ? 'selected' : '').'>PT</option>
|
||||
<option value="DE" '.((isset($_SESSION['country_code']) && $_SESSION['country_code'] == 'DE') ? 'selected' : '').'>DE</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="login-visual">
|
||||
<img src="https://dev.veliti.nl/assets/images/emergencyplug-auto-in-licht.jpg" alt="Login Visual">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
<script>
|
||||
document.getElementById(\'language-selector\').addEventListener(\'change\', function() {
|
||||
if (this.value) {
|
||||
// Get the current URL
|
||||
let currentUrl = window.location.pathname;
|
||||
|
||||
// Append the selected value as a query parameter
|
||||
window.location.href = `${currentUrl}?language=${this.value}`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</html>';
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user