Новые изменения в систему регистрации
This commit is contained in:
parent
d69a7acd5a
commit
2391a3c7d6
2 changed files with 32 additions and 21 deletions
|
|
@ -1,11 +1,21 @@
|
|||
import nodemailer from 'nodemailer';
|
||||
import type { EmailOptions } from '../globalInterfaces';
|
||||
|
||||
const SMTP_HOST = import.meta.env.SMTP_HOST; // || 'localhost';
|
||||
const SMTP_PORT = import.meta.env.SMTP_PORT; // || 1025;
|
||||
const FROM_EMAIL = import.meta.env.FROM_EMAIL; // || 'noreply@avtourist-surgut.ru';
|
||||
const FROM_NAME = import.meta.env.FROM_NAME; // || 'Автоюрист Сургут';
|
||||
const SITE_URL = import.meta.env.SITE_URL; // || 'http://localhost:4321';
|
||||
const isDev = import.meta.env.DEV;
|
||||
|
||||
const SMTP_HOST = isDev
|
||||
? 'localhost'
|
||||
: (import.meta.env.SMTP_HOST || 'smtp.gmail.com');
|
||||
const SMTP_PORT = isDev
|
||||
? '1025'
|
||||
: (import.meta.env.SMTP_PORT || '465');
|
||||
const SMTP_AUTH_USER = import.meta.env.SMTP_AUTH_USER || '';
|
||||
const SMTP_AUTH_PASS = import.meta.env.SMTP_AUTH_PASS || '';
|
||||
const FROM_EMAIL = import.meta.env.FROM_EMAIL || 'noreply@localhost';
|
||||
const FROM_NAME = import.meta.env.FROM_NAME || 'Dev';
|
||||
const SITE_URL = isDev
|
||||
? 'http://localhost:4321'
|
||||
: (import.meta.env.SITE_URL || 'https://avtourist-surgut.ru');
|
||||
|
||||
let transporter: nodemailer.Transporter | null = null;
|
||||
|
||||
|
|
@ -13,9 +23,13 @@ function getTransporter() {
|
|||
if (!transporter) {
|
||||
transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(String(SMTP_PORT)),
|
||||
secure: false,
|
||||
ignoreTLS: true,
|
||||
port: parseInt(SMTP_PORT),
|
||||
secure: !isDev,
|
||||
requireTLS: !isDev,
|
||||
auth: isDev ? undefined : {
|
||||
user: SMTP_AUTH_USER,
|
||||
pass: SMTP_AUTH_PASS,
|
||||
},
|
||||
});
|
||||
}
|
||||
return transporter;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import { pb } from '../../../lib/pb';
|
||||
|
||||
const POCKETBASE_URL = import.meta.env.POCKETBASE_URL || 'http://127.0.0.1:8090';
|
||||
const ADMIN_EMAIL = import.meta.env.PB_ADMIN_EMAIL || 'redibedi2019@gmail.com';
|
||||
const ADMIN_PASSWORD = import.meta.env.PB_ADMIN_PASSWORD || 'Stalin4444';
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
|
|
@ -43,21 +46,15 @@ export const POST: APIRoute = async ({ request }) => {
|
|||
error: 'Срок действия ссылки истёк'
|
||||
}), { status: 400 });
|
||||
}
|
||||
|
||||
console.log('Attempting admin auth...');
|
||||
await pb.collection('_superusers').authWithPassword(ADMIN_EMAIL, ADMIN_PASSWORD);
|
||||
console.log('Admin auth success, updating user...');
|
||||
|
||||
const response = await fetch(`${POCKETBASE_URL}/api/collections/users/records/${userId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ verified: true }),
|
||||
await pb.collection('users').update(userId, {
|
||||
verified: true,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
console.error('Verify error:', err);
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
error: 'Не удалось подтвердить email'
|
||||
}), { status: 400 });
|
||||
}
|
||||
console.log('User verified:', userId);
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue