fix: bind Telegram pairing to expiring single-use account challenges
This commit is contained in:
+11
-8
@@ -39,6 +39,7 @@ import { kalemleriCikar } from './kalem-cikar.mjs';
|
||||
import { searchInDocuments, searchByOkas, okasAra } from './ekap-v2.mjs';
|
||||
import { iknCikar } from './kalem-cikar.mjs';
|
||||
import { bonusHesapla, gommeDurumu, arkaPlandaIsit } from './uyum-gomme.mjs';
|
||||
import { createTelegramLinker } from './telegram-link.mjs';
|
||||
import { telegramConfigured, botAdi, kodIleBagla, sendTelegram } from './telegram.mjs';
|
||||
import { bildirimleriOku, okunduIsaretle, zeyilnameDurumu, zeyilnameTara, sonucTara } from './zeyilname.mjs';
|
||||
|
||||
@@ -897,7 +898,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { success: true, ...gommeDurumu() });
|
||||
}
|
||||
// --- Telegram bağlantısı (kullanıcı kodu bota yazar, biz getUpdates'te görürüz) ---
|
||||
if (url.pathname.startsWith('/api/me/telegram')) {
|
||||
if (url.pathname === '/api/me/telegram') {
|
||||
const user = userFromAuthHeader(req.headers['authorization']);
|
||||
if (!user) return json(res, 401, { success: false, error: 'oturum yok' });
|
||||
const tg = store.getData(user.email, 'telegram');
|
||||
@@ -913,15 +914,16 @@ const server = http.createServer(async (req, res) => {
|
||||
await sendTelegram(tg.chatId, '✅ İhaleist bağlantı testi — bildirimler bu sohbete gelecek.');
|
||||
return json(res, 200, { success: true });
|
||||
}
|
||||
const kod = String(body.kod || '').replace(/\D/g, '');
|
||||
if (kod.length !== 6) return json(res, 400, { success: false, error: '6 haneli kod gerekli' });
|
||||
const bulunan = await kodIleBagla(kod);
|
||||
if (!bulunan) return json(res, 404, { success: false, error: 'Kod bota gönderilmiş görünmüyor. Önce bota yazın, sonra doğrulayın.' });
|
||||
store.setData(user.email, 'telegram', { ...bulunan, baglanma: new Date().toISOString() });
|
||||
await sendTelegram(bulunan.chatId, `✅ İhaleist hesabınız (${user.email}) bu sohbete bağlandı.`).catch(() => {});
|
||||
const linker=createTelegramLinker(store);
|
||||
if(body.islem==='kod'){
|
||||
if(!telegramConfigured())return json(res,503,{success:false,error:'Telegram hizmeti etkin değil.'});
|
||||
return json(res,200,{success:true,...linker.issue(user.email)});
|
||||
}
|
||||
const bulunan=await linker.link(user.email,body.kod,kodIleBagla);
|
||||
return json(res, 200, { success: true, ad: bulunan.ad });
|
||||
} catch (e) { return json(res, 502, { success: false, error: e.message }); }
|
||||
} catch (e) { return json(res,e.kod==='VERSION_CONFLICT'?409:e.status||502,{success:false,error:e.message}); }
|
||||
}
|
||||
return json(res,405,{success:false,error:'Desteklenmeyen metot.'});
|
||||
}
|
||||
// --- Takip bildirimleri (zeyilname / sonuç) ---
|
||||
if (url.pathname === '/api/me/bildirimler') {
|
||||
@@ -1217,6 +1219,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const protectedKey=['firma_profil','saved_filters','ekip','favori_kurumlar','rakip_izleme','reminder','brief'].includes(k);
|
||||
if(protectedKey && (!Object.hasOwn(body,'revision') || (body.revision!==null && (typeof body.revision!=='string' || !/^[a-f0-9]{64}$/.test(body.revision)))))
|
||||
return json(res,428,{success:false,kod:'VERSION_REQUIRED',error:'Güncel kayıt sürümü gerekli. Sayfayı yenileyip tekrar deneyin.'});
|
||||
if(k==='telegram')return json(res,403,{success:false,error:'Telegram bağlantısını doğrulama ekranından yönetin.'});
|
||||
const revision=store.setData(user.email, k, body.deger, protectedKey ? body.revision : undefined);
|
||||
return json(res, 200, { success: true, ...(protectedKey ? {revision} : {}) });
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user