This commit is contained in:
2024-12-19 08:14:21 +06:00
parent 63e7081516
commit 5abfd87c06
2 changed files with 136 additions and 48 deletions

View File

@ -4,11 +4,7 @@ import java.io.FileInputStream;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.sql.Connection; import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -65,6 +61,7 @@ public class EngineController implements ServletContextAware {
@Autowired @Autowired
public EngineController(NamedParameterJdbcTemplate jdbcTemplate) { public EngineController(NamedParameterJdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
this.m_props = new Properties();
} }
private PublicKey getPublicKey(){ private PublicKey getPublicKey(){
@ -116,7 +113,7 @@ public class EngineController implements ServletContextAware {
long country_id=0; long country_id=0;
try { try {
String sql=""" String sql="""
select language_id,country_id from main._users where id=user_id select language_id,country_id from main._users where id=:user_id
"""; """;
MapSqlParameterSource parameters = new MapSqlParameterSource(); MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("user_id", claims.getBody().get("user_id")); parameters.addValue("user_id", claims.getBody().get("user_id"));
@ -354,12 +351,13 @@ public class EngineController implements ServletContextAware {
}*/ }*/
//Для перевода выбираю всё что под номером 1 в переводе //Для перевода выбираю всё что под номером 1 в переводе
try { try {
String sql=""" String sql="""
select identifier,translation from main._translations t where t.del=false and t.language_id=:language_id and translation_type_id=1 select identifier,translation from main._translations t where t.del=false and t.language_id=:language_id and translation_type_id=1;
"""; """;
MapSqlParameterSource parameters = new MapSqlParameterSource(); MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("language_id", language_id); parameters.addValue("language_id", language_id, Types.INTEGER);
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper()); List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
for (int i = 0; i < ret.size(); i++) { for (int i = 0; i < ret.size(); i++) {
JSONObject obj = new JSONObject(ret.get(i)); JSONObject obj = new JSONObject(ret.get(i));
@ -401,9 +399,9 @@ public class EngineController implements ServletContextAware {
for (int i = 0; i < ret.size(); i++) { for (int i = 0; i < ret.size(); i++) {
JSONObject obj = new JSONObject(ret.get(i)); JSONObject obj = new JSONObject(ret.get(i));
//m_props.setProperty(obj.getString("identifier"), obj.getString("translation")); //m_props.setProperty(obj.getString("identifier"), obj.getString("translation"));
Substrate_head+=" <option value=\""+obj.getString("id")+"\">"+obj.getString("description")+"</option>\n"; Substrate_head+=" <option value=\""+obj.getInt("id")+"\">"+obj.getString("description")+"</option>\n";
Substrate_tail+="g_Layouts[\""+obj.getString("id")+"\"] = new ol.source.XYZ({\n"; Substrate_tail+="g_Layouts[\""+obj.getInt("id")+"\"] = new ol.source.XYZ({\n";
Substrate_tail+=" url: '"+obj.getString("path")+"',\n"; Substrate_tail+=" url: '"+obj.getString("path")+"',\n";
if(!obj.isNull("projection") && obj.getString("projection").indexOf("EPSG:")!=-1) if(!obj.isNull("projection") && obj.getString("projection").indexOf("EPSG:")!=-1)
Substrate_tail+=" projection: '"+obj.getString("projection")+"',\n"; Substrate_tail+=" projection: '"+obj.getString("projection")+"',\n";

View File

@ -1,11 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org" lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title th:text="${Authorization}">Authorization</title> <title th:text="${Authorization}">Authorization</title>
<link rel="icon" href="../resources/favicon.ico" type="image/x-icon"> <link rel="icon" href="../resources/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../resources/engine/css/buttons.css?v=8">
<link rel="stylesheet" href="../resources/engine/normalize.css?v=8">
<link rel="stylesheet" type="text/css" href="../resources/engine/index.css?v=14"/>
<link rel="stylesheet" type="text/css" href="../resources/metadata/dbms/dbms.css?v=14"/>
<script type="text/javascript" src="../translation?v=9"></script>
<script type="text/javascript" src="../resources/metadata/dbms/tools.js?v=14"></script> <script type="text/javascript" src="../resources/metadata/dbms/tools.js?v=14"></script>
<script type="text/javascript" src="../resources/metadata/dbms/window.js?v=14"></script>
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@ -13,6 +19,7 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
display: flex; display: flex;
flex-direction: column; /* Вертикальная ориентация */
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
@ -79,11 +86,38 @@
margin-top: 10px; margin-top: 10px;
text-align: center; text-align: center;
} }
/* Custom style for checkbox */
.checkbox-group {
display: flex;
align-items: center;
}
.checkbox-group input {
margin-right: 8px;
}
.centered-text {
text-align: center;
font-size: 14px;
color: #333;
margin-top: auto; /* Этот стиль заставит блок с .centered-text быть внизу */
}
.centered-text a {
color: #007bff;
text-decoration: none;
}
.centered-text a:hover {
text-decoration: underline;
}
</style> </style>
</head> </head>
<body> <body>
<div class="login-container"> <!-- Форма авторизации -->
<div class="login-container" id="loginForm">
<h2 th:text="${Authorization}">Authorization</h2> <h2 th:text="${Authorization}">Authorization</h2>
<div> <div>
<div class="form-group"> <div class="form-group">
@ -110,59 +144,115 @@
</div> </div>
</div> </div>
<!-- Форма регистрации -->
<div class="login-container" style="display: none;" id="registrationForm">
<h2 th:text="${Registration}">Registration</h2>
<div>
<div class="form-group">
<label for="3_country_id"><span th:text="${Country}">Country</span> *</label>
<input type="text" id="3_country_id" name="country" maxlength="50" placeholder="Country">
</div>
<div class="form-group">
<label for="3_lastname"><span th:text="${Surname}">Surname</span></label>
<input type="text" id="3_lastname" name="lastname" maxlength="50" placeholder="Surname">
</div>
<div class="form-group">
<label for="3_firstname"><span th:text="${Name}">Name</span> *</label>
<input type="text" id="3_firstname" name="firstname" maxlength="50" placeholder="Name">
</div>
<div class="form-group">
<label for="3_company"><span th:text="${Company}">Company</span></label>
<input type="text" id="3_company" name="company" maxlength="50" placeholder="Company">
</div>
<div class="form-group">
<label for="3_position"><span th:text="${Position}">Position</span></label>
<input type="text" id="3_position" name="position" maxlength="50" placeholder="Position">
</div>
<div class="form-group">
<label for="3_phone"><span th:text="${Phone}">Phone</span></label>
<input type="text" id="3_phone" name="phone" maxlength="50" placeholder="Phone">
</div>
<div class="form-group">
<label for="3_email"><span th:text="${E_mail}">Email</span> *</label>
<input type="text" id="3_email" name="email" maxlength="50" placeholder="E-mail">
</div>
<!-- Checkbox for Privacy Policy -->
<div class="form-group checkbox-group">
<input type="checkbox" id="privacyPolicy" onclick="toggleRegisterButton()">
<label for="privacyPolicy">
Я согласен с <a href="#">политикой конфиденциальности</a>
</label>
</div>
<div class="form-group">
<button id="registerBtn" class="button" th:text="${Registration}" disabled>Registration</button>
</div>
<div class="progress-bar" id="progressBar2">
<span>Загрузка...</span>
</div>
</div>
</div>
<!-- Password recovery -->
<div class="login-container" style="display: none;" id="registrationForm">
<h2 th:text="${Password_recovery}">Password_recovery</h2>
<div>
</div>
</div>
<!-- Ссылки для переключения -->
<div class="centered-text">
<p><a href="#" onclick="showForm(1);" th:text="${Authorization}">Authorization</a></p>
<p><a href="#" onclick="showForm(2);" th:text="${Create_a_new_user}">Create a new user</a></p>
<p><a href="#" onclick="showForm(3);" th:text="${Password_recovery}">Password recovery</a></p>
<p><a href="#" onclick="showForm(4);" th:text="${Change_password}">Change password</a></p>
<p><a href="#" onclick="showForm(5);" th:text="${Get_new_TOTP_key}">Get new TOTP key</a></p>
</div>
<script> <script>
// Функция для отправки данных на сервер // Функция для отображения формы авторизации
function postJsonData(url, data, callback) { function showForm(num) {
fetch(url, { document.getElementById('loginForm').style.display = num === 1 ? 'block' : 'none';
method: 'POST', document.getElementById('registrationForm').style.display = num === 2 ? 'block' : 'none';
headers: { }
'Content-Type': 'application/json'
},
body: JSON.stringify(data) // Функция для включения/выключения кнопки регистрации в зависимости от состояния галочки
}) function toggleRegisterButton() {
.then(response => response.json()) const checkbox = document.getElementById('privacyPolicy');
.then(data => callback(true, data)) const registerBtn = document.getElementById('registerBtn');
.catch(error => { registerBtn.disabled = !checkbox.checked;
console.error('Error:', error);
callback(false, { error_message: 'Что-то пошло не так. Попробуйте еще раз.' });
});
} }
// Функция для обработки авторизации // Функция для обработки авторизации
function authorizeUser() { function authorizeUser() {
const login = document.getElementById('login0').value; const login = document.getElementById('login0').value;
const password = document.getElementById('password0').value; const password = document.getElementById('password0').value;
const obj = { login, password, appid: 'ccalm' };
const obj = {
login: login,
password: password,
appid: 'ccalm'
};
// Отправляем запрос на сервер для авторизации
postJsonData('/api/authorization/v02/login', obj, (ok, data) => { postJsonData('/api/authorization/v02/login', obj, (ok, data) => {
if (ok) { if (ok) {
if (data.error_code == 0) { if (data.error_code == 0) {
window.location.href = "/engine"; window.location.href = "/engine";
} else { } else {
alert2(trt('Alert'), data.error_message); alert2(trt('Alert'), trt(data.error_message));
} }
}else{ } else {
alert2(trt('Error'),data); alert2(trt('Alert'), trt('Error: Unable to authorize.'));
} }
document.getElementById('progressBar').style.display = 'none'; // Скрываем прогресс-бар
}); });
document.getElementById('progressBar').style.display = 'block';
} }
// Функция для восстановления пароля // Изначально показываем форму авторизации
function showRestoreForm() { showLoginForm();
alert('Форма восстановления пароля будет здесь!');
}
// Обработчик клика на кнопку "Войти"
document.getElementById('loginBtn').onclick = authorizeUser;
</script> </script>
</body> </body>