improve page-create
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
- Keine externe Abhängigkeit, keine Lizenzkosten
|
- Keine externe Abhängigkeit, keine Lizenzkosten
|
||||||
- Client löst SHA256-Challenge (Difficulty 4, ~1-3 Sek)
|
- Client löst SHA256-Challenge (Difficulty 4, ~1-3 Sek)
|
||||||
- Bei Account-Erstellung (immer)
|
- Bei Account-Erstellung (immer)
|
||||||
- Bei Anzeigen-Erstellung (immer)
|
- Bei Anzeigen-Erstellung (nur neue Accounts ohne bisherige Listings)
|
||||||
- Bei Login (nur nach 3+ Fehlversuchen)
|
- Bei Login (nur nach 3+ Fehlversuchen)
|
||||||
- Implementierung: `js/services/pow-captcha.js`, `js/components/pow-captcha.js`
|
- Implementierung: `js/services/pow-captcha.js`, `js/components/pow-captcha.js`
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class PageCreate extends HTMLElement {
|
|||||||
this.imagePreviews = []
|
this.imagePreviews = []
|
||||||
this.categories = []
|
this.categories = []
|
||||||
this.submitting = false
|
this.submitting = false
|
||||||
|
this.isNewAccount = true
|
||||||
}
|
}
|
||||||
|
|
||||||
loadDraft() {
|
loadDraft() {
|
||||||
@@ -60,28 +61,56 @@ class PageCreate extends HTMLElement {
|
|||||||
|
|
||||||
this.hasDraft = !!localStorage.getItem(STORAGE_KEY)
|
this.hasDraft = !!localStorage.getItem(STORAGE_KEY)
|
||||||
await this.loadCategories()
|
await this.loadCategories()
|
||||||
|
await this.checkAccountStatus()
|
||||||
this.render()
|
this.render()
|
||||||
this.unsubscribe = i18n.subscribe(() => this.render())
|
this.unsubscribe = i18n.subscribe(() => this.render())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkAccountStatus() {
|
||||||
|
try {
|
||||||
|
// Check if user has any published listings
|
||||||
|
const user = await auth.getUser()
|
||||||
|
if (user?.id) {
|
||||||
|
const listings = await directus.get('/items/listings', {
|
||||||
|
filter: { user_created: { _eq: user.id } },
|
||||||
|
limit: 1
|
||||||
|
})
|
||||||
|
this.isNewAccount = !listings.data || listings.data.length === 0
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Default to new account (show captcha)
|
||||||
|
this.isNewAccount = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
showLoginRequired() {
|
showLoginRequired() {
|
||||||
|
// Show login modal directly
|
||||||
|
const authModal = document.querySelector('auth-modal')
|
||||||
|
if (authModal) {
|
||||||
|
authModal.show('login')
|
||||||
|
authModal.addEventListener('login', async () => {
|
||||||
|
// After login, load the create page
|
||||||
|
this.hasDraft = !!localStorage.getItem(STORAGE_KEY)
|
||||||
|
await this.loadCategories()
|
||||||
|
this.render()
|
||||||
|
this.unsubscribe = i18n.subscribe(() => this.render())
|
||||||
|
}, { once: true })
|
||||||
|
authModal.addEventListener('close', () => {
|
||||||
|
// If closed without login, go back
|
||||||
|
if (!auth.isLoggedIn()) {
|
||||||
|
router.back()
|
||||||
|
}
|
||||||
|
}, { once: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show minimal loading state while modal is open
|
||||||
this.innerHTML = /* html */`
|
this.innerHTML = /* html */`
|
||||||
<div class="create-page">
|
<div class="create-page">
|
||||||
<div class="login-required">
|
<div class="login-required">
|
||||||
<h2>${t('auth.loginRequired')}</h2>
|
<p>${t('auth.loginRequired')}</p>
|
||||||
<button class="btn btn-primary btn-lg" id="login-btn">${t('auth.login')}</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
this.querySelector('#login-btn')?.addEventListener('click', () => {
|
|
||||||
const authModal = document.querySelector('auth-modal')
|
|
||||||
if (authModal) {
|
|
||||||
authModal.show('login')
|
|
||||||
authModal.addEventListener('login', () => {
|
|
||||||
this.connectedCallback()
|
|
||||||
}, { once: true })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadCategories() {
|
async loadCategories() {
|
||||||
@@ -249,9 +278,11 @@ class PageCreate extends HTMLElement {
|
|||||||
<p class="field-hint">${t('create.moneroHint')}</p>
|
<p class="field-hint">${t('create.moneroHint')}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
${this.isNewAccount ? `
|
||||||
<pow-captcha id="pow-captcha"></pow-captcha>
|
<div class="form-group">
|
||||||
</div>
|
<pow-captcha id="pow-captcha"></pow-captcha>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="button" class="btn btn-outline btn-lg" id="cancel-btn">
|
<button type="button" class="btn btn-outline btn-lg" id="cancel-btn">
|
||||||
@@ -386,11 +417,13 @@ class PageCreate extends HTMLElement {
|
|||||||
|
|
||||||
if (this.submitting) return
|
if (this.submitting) return
|
||||||
|
|
||||||
// Validate PoW Captcha
|
// Validate PoW Captcha (only for new accounts)
|
||||||
const captcha = this.querySelector('#pow-captcha')
|
if (this.isNewAccount) {
|
||||||
if (!captcha?.isSolved()) {
|
const captcha = this.querySelector('#pow-captcha')
|
||||||
this.showError(t('captcha.error'))
|
if (!captcha?.isSolved()) {
|
||||||
return
|
this.showError(t('captcha.error'))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Monero address
|
// Validate Monero address
|
||||||
|
|||||||
Reference in New Issue
Block a user