вход в систему

This commit is contained in:
IoT Manager
2023-10-02 17:51:40 +02:00
parent 781d61f917
commit 10cacbbc22
3 changed files with 32 additions and 8 deletions

View File

@@ -1401,11 +1401,11 @@
<a class="menu__item" href="/login">{"Вход"}</a>
</li>
<li class="flex flex-col pl-6 pt-3 w-full h-screen">
<select class="border border-indigo-500 border-1 h-6 w-12" bind:value={$locale}>
<!--<select class="border border-indigo-500 border-1 h-6 w-12" bind:value={$locale}>
{#each locales as l}
<option value={l}>{l}</option>
{/each}
</select>
</select>-->
</li>
</ul>
</nav>

View File

@@ -3,10 +3,30 @@ export default {
"login.email": "Введите email",
"login.pass": "Введите пароль",
"login.login": "Вход",
err_of_registration: "Ошибка регестрации",
err_of_login: "Ошибка входа в систему",
err_user_exist: "Такой пользователь уже был зарегестрирован",
err_user_not_exist: "Такой пользователь не был зарегестрирован",
err_pass: "Неправильный пароль",
err_empty_fullname: "Пустое поле имени",
err_empty_user: "Пустое поле Email адреса",
err_not_email: "Неправильно введен Email",
err_pass_lenth: "Пароль должен быть от 4 до 10 символов",
ok_success_login: "Вы вошли в систему",
},
en: {
"login.email": "Email",
"login.pass": "Password",
"login.login": "Login",
err_of_registration: "Ошибка регестрации",
err_of_login: "Ошибка входа в систему",
err_user_exist: "Такой пользователь уже был зарегестрирован",
err_user_not_exist: "Такой пользователь не был зарегестрирован",
err_pass: "Неправильный пароль",
err_empty_fullname: "Пустое поле имени",
err_empty_user: "Пустое поле Email адреса",
err_not_email: "Неправильно введен Email",
err_pass_lenth: "Пароль должен быть от 4 до 10 символов",
ok_success_login: "Вы вошли в систему",
},
};

View File

@@ -5,10 +5,10 @@
export let show = true;
let user = {};
let errors = [];
const login = async (user) => {
errors = [];
try {
let res = await fetch("https://portal.iotmanager.org/api/auth/login", {
mode: "cors",
@@ -20,17 +20,21 @@
body: JSON.stringify(user),
});
const content = await res.json();
console.log(content);
//console.log(content);
if (res.ok) {
//
errors = [{ msg: "ok_success_login" }];
saveToken(content.message);
} else {
errors = content.message;
}
} catch (e) {
//console.log("er");
//errors = e;
console.log(e);
}
};
const saveToken = async (token) => {
console.log("token to be saved: ", token);
};
</script>
{#if show}
@@ -50,7 +54,7 @@
<input bind:value={user.password} class="shadow appearance-none border rounded w-full h-10 px-3 text-gray-700 mb-0 leading-tight focus:outline-none focus:shadow-outline" id="password" type="password" placeholder="**********" />
</div>
{#each errors as e, i}
<p class="text-red-500 p-0 m-0 font-bold text-xs italic">{e.msg}</p>
<p class="text-red-500 p-0 m-0 font-bold text-xs italic">{$t(e.msg)}</p>
{/each}
<button class="btn-lg mt-6" on:click={() => login(user)}>{$t("login.login")}</button>
</form>