Feature: Запомнить меня (cookie 30 дней)

- HTML: <input type=checkbox id='el-remember' checked>
- api.js: loginEmail(email, password, remember)
- app.js: emailLogin/register читают флаг и шлют в /auth/login
- backend: remember=true → accessTTL=30дн, false → 1ч
This commit is contained in:
root 2026-08-21 11:18:59 +00:00
parent f72f890076
commit 8016e2976e
3 changed files with 20 additions and 13 deletions

View File

@ -34,15 +34,15 @@
</button> </button>
</nav> </nav>
</div> </div>
<script src="/js/tg.js?v=20"></script> <script src="/js/tg.js?v=21"></script>
<script src="/js/api.js?v=20"></script> <script src="/js/api.js?v=21"></script>
<script src="/js/views/map.js?v=20"></script> <script src="/js/views/map.js?v=21"></script>
<script src="/js/views/chats.js?v=20"></script> <script src="/js/views/chats.js?v=21"></script>
<script src="/js/views/chat.js?v=20"></script> <script src="/js/views/chat.js?v=21"></script>
<script src="/js/views/profile.js?v=20"></script> <script src="/js/views/profile.js?v=21"></script>
<script src="/js/views/settings.js?v=20"></script> <script src="/js/views/settings.js?v=21"></script>
<script src="/js/views/onboarding.js?v=20"></script> <script src="/js/views/onboarding.js?v=21"></script>
<script src="/js/views/review.js?v=20"></script> <script src="/js/views/review.js?v=21"></script>
<script src="/js/app.js?v=20"></script> <script src="/js/app.js?v=21"></script>
</body> </body>
</html> </html>

View File

@ -65,7 +65,7 @@ const Store = {
}; };
const Auth = { const Auth = {
loginEmail: function (email, password) { return apiPost('/api/v1/auth/login', { email: email, password: password }); }, loginEmail: function (email, password, remember) { return apiPost('/api/v1/auth/login', { email: email, password: password, remember: !!remember }); },
registerEmail: function (data) { return apiPost('/api/v1/auth/register', data); }, registerEmail: function (data) { return apiPost('/api/v1/auth/register', data); },
me: function () { return apiGet('/api/v1/me'); }, me: function () { return apiGet('/api/v1/me'); },
updateMe: function (p) { return apiPut('/api/v1/me', p); }, updateMe: function (p) { return apiPut('/api/v1/me', p); },

View File

@ -212,6 +212,10 @@ const App = {
<input class="input" id="el-email" type="email" placeholder="you@example.com" autocomplete="email"> <input class="input" id="el-email" type="email" placeholder="you@example.com" autocomplete="email">
<label>Пароль (≥8 символов)</label> <label>Пароль (≥8 символов)</label>
<input class="input" id="el-pass" type="password" placeholder="минимум 8 символов" autocomplete="current-password"> <input class="input" id="el-pass" type="password" placeholder="минимум 8 символов" autocomplete="current-password">
<label style="display:flex;align-items:center;gap:8px;margin-top:8px;font-size:14px;">
<input type="checkbox" id="el-remember" checked>
<span>Запомнить меня (30 дней)</span>
</label>
<button class="btn" id="el-login" disabled>Войти</button> <button class="btn" id="el-login" disabled>Войти</button>
<button class="btn ghost" id="el-register">Регистрация</button> <button class="btn ghost" id="el-register">Регистрация</button>
<div class="sub" id="el-hint" style="margin-top:8px;text-align:center;">Введите email и пароль (≥8 символов)</div> <div class="sub" id="el-hint" style="margin-top:8px;text-align:center;">Введите email и пароль (≥8 символов)</div>
@ -300,10 +304,10 @@ const App = {
async emailLogin() { async emailLogin() {
const email = document.getElementById('el-email').value.trim(); const email = document.getElementById('el-email').value.trim();
const pass = document.getElementById('el-pass').value; const pass = document.getElementById('el-pass').value;
const remember = document.getElementById('el-remember')?.checked ?? true;
try { try {
const r = await API.Auth.loginEmail(email, pass); const r = await API.Auth.loginEmail(email, pass, remember);
if (r && r.tokens) API.Store.save(r.tokens); if (r && r.tokens) API.Store.save(r.tokens);
// same-origin: cookie + body, ничего не висит
const me = await API.Auth.me(); const me = await API.Auth.me();
API.Store.user = me.user || me; API.Store.user = me.user || me;
this.onLogin(); this.onLogin();
@ -330,12 +334,15 @@ const App = {
target.appendChild(ov); target.appendChild(ov);
try { try {
const remember = document.getElementById('el-remember')?.checked ?? true;
const r = await API.Auth.registerEmail({ const r = await API.Auth.registerEmail({
email, email,
password: pass, password: pass,
name: email.split('@')[0], name: email.split('@')[0],
consents: { adult: true, terms: true, privacy: true, disclaimer: true }, consents: { adult: true, terms: true, privacy: true, disclaimer: true },
remember: remember,
}); });
if (r && r.tokens) API.Store.save(r.tokens);
await API.Auth.me(); await API.Auth.me();
ov.remove(); ov.remove();
await this.maybeOnboard(); await this.maybeOnboard();