Fix: check summoner name server side to prevent Firefox error

This commit is contained in:
Valentin Kaelin 2019-09-03 19:56:41 +02:00
parent afd1b0d8f3
commit 1c1dc49c69
4 changed files with 23 additions and 16 deletions

View file

@ -7,7 +7,7 @@
type="text" type="text"
autofocus autofocus
class="input w-full px-2 py-4 rounded-lg outline-none pl-8 pr-16 font-bold" class="input w-full px-2 py-4 rounded-lg outline-none pl-8 pr-16 font-bold"
> />
<div class="absolute right-0 z-30 vertical-center flex items-center h-full mr-2"> <div class="absolute right-0 z-30 vertical-center flex items-center h-full mr-2">
<div <div
@click="dropdown = !dropdown" @click="dropdown = !dropdown"
@ -42,8 +42,7 @@
name="check" name="check"
scale="0.7" scale="0.7"
class="absolute vertical-center offsetIcon" class="absolute vertical-center offsetIcon"
> ></v-icon>
</v-icon>
{{ region }} {{ region }}
</div> </div>
</div> </div>
@ -86,15 +85,9 @@ export default {
} }
}, },
formSubmit() { formSubmit() {
const regexNames = new RegExp('^[0-9\\p{L} _\\.]+$', 'u') const search = this.summoner.split(' ').join('')
if (search.length) {
if(regexNames.exec(this.summoner)) { this.$emit('formSubmit', search, this.selectedRegion.toLowerCase())
this.$emit('formSubmit', this.summoner.split(' ').join(''), this.selectedRegion.toLowerCase())
} else {
this.$store.dispatch('notification/add', {
type: 'error',
message: 'Summoner Name entered is incorrect.'
})
} }
} }
} }

View file

@ -140,6 +140,11 @@ export default {
} else { } else {
this.summonerFound = false this.summonerFound = false
this.loading = false this.loading = false
this.$store.dispatch('notification/add', {
type: 'error',
message: 'Summoner not found.'
})
console.log('Summoner not found') console.log('Summoner not found')
} }
} catch (error) { } catch (error) {

View file

@ -16,7 +16,7 @@ class JaxRequest {
return JSON.parse(resp) return JSON.parse(resp)
} catch ({ statusCode, ...rest }) { } catch ({ statusCode, ...rest }) {
console.log('error: ' + statusCode, rest) console.log('error: ' + statusCode)
} }
} }

View file

@ -42,11 +42,21 @@ app.post('/api', async function (req, res) {
console.log(req.body.summoner, req.body.region) console.log(req.body.summoner, req.body.region)
console.time('all') console.time('all')
/* Check if the summonerName is correct before fetching Riot API */
const regexSummonerName = new RegExp('^[0-9\\p{L} _\\.]+$', 'u')
if (!regexSummonerName.exec(req.body.summoner)) {
return res.send(null)
}
const finalJSON = {} const finalJSON = {}
jax.regionName = req.body.region jax.regionName = req.body.region
try { try {
const account = await jax.Summoner.summonerName(req.body.summoner) const account = await jax.Summoner.summonerName(req.body.summoner)
// Check if the summoner is found
if (!account) return res.send(null)
finalJSON.account = account finalJSON.account = account
const ranked = await jax.League.summonerID(account.id) const ranked = await jax.League.summonerID(account.id)
@ -66,7 +76,6 @@ app.post('/api', async function (req, res) {
console.timeEnd('all') console.timeEnd('all')
} catch (error) { } catch (error) {
console.log('username not found') console.log('username not found')
console.log(error)
res.send(null) res.send(null)
} }
}) })