Merge branch 'main' into fix/mobile-view
Run Tests on Branches / Detect Changes (push) Successful in 15s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 2m33s
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Run Tests on Branches / Detect Changes (push) Successful in 15s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 2m33s
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
This commit is contained in:
@@ -24,5 +24,16 @@ EXPO_ACCESS_TOKEN=
|
||||
# Genera una cadena aleatoria fuerte, p.ej.: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
||||
INGEST_API_KEY=dev-ingest-key-change-me
|
||||
|
||||
# SMTP for password reset / forgot username emails
|
||||
# Development: use Mailpit (docker) — no auth needed
|
||||
SMTP_HOST=localhost
|
||||
SMTP_PORT=1025
|
||||
SMTP_USER=
|
||||
SMTP_PASS=
|
||||
SMTP_FROM=noreply@farmafinder.com
|
||||
|
||||
# Base URL for reset links in emails (your frontend URL)
|
||||
APP_URL=http://localhost:3000
|
||||
|
||||
# Parapharmacy API
|
||||
PARAPHARMACY_API_URL=http://localhost:3002
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
FROM node:24-alpine
|
||||
FROM node:slim
|
||||
WORKDIR /app
|
||||
COPY apps/backend/package*.json ./
|
||||
RUN apk add --no-cache python3 make g++ && npm ci --omit=dev
|
||||
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
|
||||
RUN npm install
|
||||
RUN npm ci --omit=dev
|
||||
COPY apps/backend/ .
|
||||
COPY apps/API/ /API/
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<coverage generated="1785151771806" clover="3.2.0">
|
||||
<project timestamp="1785151771806" name="All files">
|
||||
<metrics statements="56" coveredstatements="56" conditionals="71" coveredconditionals="64" methods="5" coveredmethods="5" elements="132" coveredelements="125" complexity="0" loc="56" ncloc="56" packages="1" files="1" classes="1"/>
|
||||
<file name="hours.js" path="/home/f80ans0/Projects/Webs/FarmaFinder/apps/backend/src/hours.js">
|
||||
<metrics statements="56" coveredstatements="56" conditionals="71" coveredconditionals="64" methods="5" coveredmethods="5"/>
|
||||
<line num="15" count="1" type="stmt"/>
|
||||
<line num="18" count="40" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="19" count="34" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="20" count="4" type="stmt"/>
|
||||
<line num="21" count="4" type="stmt"/>
|
||||
<line num="23" count="2" type="stmt"/>
|
||||
<line num="28" count="26" type="cond" truecount="1" falsecount="1"/>
|
||||
<line num="29" count="26" type="stmt"/>
|
||||
<line num="30" count="26" type="cond" truecount="1" falsecount="1"/>
|
||||
<line num="31" count="26" type="stmt"/>
|
||||
<line num="32" count="26" type="stmt"/>
|
||||
<line num="33" count="26" type="cond" truecount="3" falsecount="1"/>
|
||||
<line num="34" count="26" type="cond" truecount="2" falsecount="2"/>
|
||||
<line num="35" count="26" type="cond" truecount="5" falsecount="1"/>
|
||||
<line num="36" count="26" type="stmt"/>
|
||||
<line num="40" count="4" type="stmt"/>
|
||||
<line num="41" count="11" type="stmt"/>
|
||||
<line num="42" count="11" type="stmt"/>
|
||||
<line num="43" count="11" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="44" count="3" type="stmt"/>
|
||||
<line num="47" count="1" type="stmt"/>
|
||||
<line num="51" count="22" type="stmt"/>
|
||||
<line num="52" count="22" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="53" count="18" type="stmt"/>
|
||||
<line num="54" count="48" type="stmt"/>
|
||||
<line num="55" count="48" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="56" count="36" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="58" count="5" type="stmt"/>
|
||||
<line num="62" count="18" type="stmt"/>
|
||||
<line num="63" count="18" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="65" count="14" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="66" count="3" type="stmt"/>
|
||||
<line num="69" count="11" type="stmt"/>
|
||||
<line num="70" count="11" type="stmt"/>
|
||||
<line num="72" count="11" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="73" count="2" type="stmt"/>
|
||||
<line num="76" count="9" type="stmt"/>
|
||||
<line num="77" count="9" type="stmt"/>
|
||||
<line num="78" count="9" type="cond" truecount="3" falsecount="1"/>
|
||||
<line num="80" count="9" type="stmt"/>
|
||||
<line num="84" count="9" type="stmt"/>
|
||||
<line num="85" count="9" type="stmt"/>
|
||||
<line num="86" count="9" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="87" count="4" type="stmt"/>
|
||||
<line num="88" count="4" type="stmt"/>
|
||||
<line num="89" count="4" type="cond" truecount="6" falsecount="0"/>
|
||||
<line num="90" count="1" type="stmt"/>
|
||||
<line num="95" count="8" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="96" count="2" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="97" count="1" type="stmt"/>
|
||||
<line num="99" count="1" type="stmt"/>
|
||||
<line num="102" count="6" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="103" count="2" type="stmt"/>
|
||||
<line num="105" count="4" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="106" count="2" type="stmt"/>
|
||||
<line num="108" count="2" type="stmt"/>
|
||||
</file>
|
||||
</project>
|
||||
</coverage>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,224 @@
|
||||
body, html {
|
||||
margin:0; padding: 0;
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
font-family: Helvetica Neue, Helvetica, Arial;
|
||||
font-size: 14px;
|
||||
color:#333;
|
||||
}
|
||||
.small { font-size: 12px; }
|
||||
*, *:after, *:before {
|
||||
-webkit-box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
h1 { font-size: 20px; margin: 0;}
|
||||
h2 { font-size: 14px; }
|
||||
pre {
|
||||
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-moz-tab-size: 2;
|
||||
-o-tab-size: 2;
|
||||
tab-size: 2;
|
||||
}
|
||||
a { color:#0074D9; text-decoration:none; }
|
||||
a:hover { text-decoration:underline; }
|
||||
.strong { font-weight: bold; }
|
||||
.space-top1 { padding: 10px 0 0 0; }
|
||||
.pad2y { padding: 20px 0; }
|
||||
.pad1y { padding: 10px 0; }
|
||||
.pad2x { padding: 0 20px; }
|
||||
.pad2 { padding: 20px; }
|
||||
.pad1 { padding: 10px; }
|
||||
.space-left2 { padding-left:55px; }
|
||||
.space-right2 { padding-right:20px; }
|
||||
.center { text-align:center; }
|
||||
.clearfix { display:block; }
|
||||
.clearfix:after {
|
||||
content:'';
|
||||
display:block;
|
||||
height:0;
|
||||
clear:both;
|
||||
visibility:hidden;
|
||||
}
|
||||
.fl { float: left; }
|
||||
@media only screen and (max-width:640px) {
|
||||
.col3 { width:100%; max-width:100%; }
|
||||
.hide-mobile { display:none!important; }
|
||||
}
|
||||
|
||||
.quiet {
|
||||
color: #7f7f7f;
|
||||
color: rgba(0,0,0,0.5);
|
||||
}
|
||||
.quiet a { opacity: 0.7; }
|
||||
|
||||
.fraction {
|
||||
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
||||
font-size: 10px;
|
||||
color: #555;
|
||||
background: #E8E8E8;
|
||||
padding: 4px 5px;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.path a:link, div.path a:visited { color: #333; }
|
||||
table.coverage {
|
||||
border-collapse: collapse;
|
||||
margin: 10px 0 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table.coverage td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
table.coverage td.line-count {
|
||||
text-align: right;
|
||||
padding: 0 5px 0 20px;
|
||||
}
|
||||
table.coverage td.line-coverage {
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
min-width:20px;
|
||||
}
|
||||
|
||||
table.coverage td span.cline-any {
|
||||
display: inline-block;
|
||||
padding: 0 5px;
|
||||
width: 100%;
|
||||
}
|
||||
.missing-if-branch {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
border-radius: 3px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #333;
|
||||
color: yellow;
|
||||
}
|
||||
|
||||
.skip-if-branch {
|
||||
display: none;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #ccc;
|
||||
color: white;
|
||||
}
|
||||
.missing-if-branch .typ, .skip-if-branch .typ {
|
||||
color: inherit !important;
|
||||
}
|
||||
.coverage-summary {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
.coverage-summary tr { border-bottom: 1px solid #bbb; }
|
||||
.keyline-all { border: 1px solid #ddd; }
|
||||
.coverage-summary td, .coverage-summary th { padding: 10px; }
|
||||
.coverage-summary tbody { border: 1px solid #bbb; }
|
||||
.coverage-summary td { border-right: 1px solid #bbb; }
|
||||
.coverage-summary td:last-child { border-right: none; }
|
||||
.coverage-summary th {
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.coverage-summary th.file { border-right: none !important; }
|
||||
.coverage-summary th.pct { }
|
||||
.coverage-summary th.pic,
|
||||
.coverage-summary th.abs,
|
||||
.coverage-summary td.pct,
|
||||
.coverage-summary td.abs { text-align: right; }
|
||||
.coverage-summary td.file { white-space: nowrap; }
|
||||
.coverage-summary td.pic { min-width: 120px !important; }
|
||||
.coverage-summary tfoot td { }
|
||||
|
||||
.coverage-summary .sorter {
|
||||
height: 10px;
|
||||
width: 7px;
|
||||
display: inline-block;
|
||||
margin-left: 0.5em;
|
||||
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
||||
}
|
||||
.coverage-summary .sorted .sorter {
|
||||
background-position: 0 -20px;
|
||||
}
|
||||
.coverage-summary .sorted-desc .sorter {
|
||||
background-position: 0 -10px;
|
||||
}
|
||||
.status-line { height: 10px; }
|
||||
/* yellow */
|
||||
.cbranch-no { background: yellow !important; color: #111; }
|
||||
/* dark red */
|
||||
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
|
||||
.low .chart { border:1px solid #C21F39 }
|
||||
.highlighted,
|
||||
.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
|
||||
background: #C21F39 !important;
|
||||
}
|
||||
/* medium red */
|
||||
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
|
||||
/* light red */
|
||||
.low, .cline-no { background:#FCE1E5 }
|
||||
/* light green */
|
||||
.high, .cline-yes { background:rgb(230,245,208) }
|
||||
/* medium green */
|
||||
.cstat-yes { background:rgb(161,215,106) }
|
||||
/* dark green */
|
||||
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
|
||||
.high .chart { border:1px solid rgb(77,146,33) }
|
||||
/* dark yellow (gold) */
|
||||
.status-line.medium, .medium .cover-fill { background: #f9cd0b; }
|
||||
.medium .chart { border:1px solid #f9cd0b; }
|
||||
/* light yellow */
|
||||
.medium { background: #fff4c2; }
|
||||
|
||||
.cstat-skip { background: #ddd; color: #111; }
|
||||
.fstat-skip { background: #ddd; color: #111 !important; }
|
||||
.cbranch-skip { background: #ddd !important; color: #111; }
|
||||
|
||||
span.cline-neutral { background: #eaeaea; }
|
||||
|
||||
.coverage-summary td.empty {
|
||||
opacity: .5;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
line-height: 1;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.cover-fill, .cover-empty {
|
||||
display:inline-block;
|
||||
height: 12px;
|
||||
}
|
||||
.chart {
|
||||
line-height: 0;
|
||||
}
|
||||
.cover-empty {
|
||||
background: white;
|
||||
}
|
||||
.cover-full {
|
||||
border-right: none !important;
|
||||
}
|
||||
pre.prettyprint {
|
||||
border: none !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
}
|
||||
.com { color: #999 !important; }
|
||||
.ignore-none { color: #999; font-weight: normal; }
|
||||
|
||||
.wrapper {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
margin: 0 auto -48px;
|
||||
}
|
||||
.footer, .push {
|
||||
height: 48px;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/* eslint-disable */
|
||||
var jumpToCode = (function init() {
|
||||
// Classes of code we would like to highlight in the file view
|
||||
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
|
||||
|
||||
// Elements to highlight in the file listing view
|
||||
var fileListingElements = ['td.pct.low'];
|
||||
|
||||
// We don't want to select elements that are direct descendants of another match
|
||||
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
|
||||
|
||||
// Selector that finds elements on the page to which we can jump
|
||||
var selector =
|
||||
fileListingElements.join(', ') +
|
||||
', ' +
|
||||
notSelector +
|
||||
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
|
||||
|
||||
// The NodeList of matching elements
|
||||
var missingCoverageElements = document.querySelectorAll(selector);
|
||||
|
||||
var currentIndex;
|
||||
|
||||
function toggleClass(index) {
|
||||
missingCoverageElements
|
||||
.item(currentIndex)
|
||||
.classList.remove('highlighted');
|
||||
missingCoverageElements.item(index).classList.add('highlighted');
|
||||
}
|
||||
|
||||
function makeCurrent(index) {
|
||||
toggleClass(index);
|
||||
currentIndex = index;
|
||||
missingCoverageElements.item(index).scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
inline: 'center'
|
||||
});
|
||||
}
|
||||
|
||||
function goToPrevious() {
|
||||
var nextIndex = 0;
|
||||
if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
||||
nextIndex = missingCoverageElements.length - 1;
|
||||
} else if (missingCoverageElements.length > 1) {
|
||||
nextIndex = currentIndex - 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
function goToNext() {
|
||||
var nextIndex = 0;
|
||||
|
||||
if (
|
||||
typeof currentIndex === 'number' &&
|
||||
currentIndex < missingCoverageElements.length - 1
|
||||
) {
|
||||
nextIndex = currentIndex + 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
return function jump(event) {
|
||||
if (
|
||||
document.getElementById('fileSearch') === document.activeElement &&
|
||||
document.activeElement != null
|
||||
) {
|
||||
// if we're currently focused on the search input, we don't want to navigate
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.which) {
|
||||
case 78: // n
|
||||
case 74: // j
|
||||
goToNext();
|
||||
break;
|
||||
case 66: // b
|
||||
case 75: // k
|
||||
case 80: // p
|
||||
goToPrevious();
|
||||
break;
|
||||
}
|
||||
};
|
||||
})();
|
||||
window.addEventListener('keydown', jumpToCode);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 445 B |
@@ -0,0 +1,412 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Code coverage report for hours.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1><a href="index.html">All files</a> hours.js</h1>
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">91.3% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>63/69</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">90.14% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>64/71</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>5/5</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>56/56</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
<template id="filterTemplate">
|
||||
<div class="quiet">
|
||||
Filter:
|
||||
<input type="search" id="fileSearch">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a>
|
||||
<a name='L21'></a><a href='#L21'>21</a>
|
||||
<a name='L22'></a><a href='#L22'>22</a>
|
||||
<a name='L23'></a><a href='#L23'>23</a>
|
||||
<a name='L24'></a><a href='#L24'>24</a>
|
||||
<a name='L25'></a><a href='#L25'>25</a>
|
||||
<a name='L26'></a><a href='#L26'>26</a>
|
||||
<a name='L27'></a><a href='#L27'>27</a>
|
||||
<a name='L28'></a><a href='#L28'>28</a>
|
||||
<a name='L29'></a><a href='#L29'>29</a>
|
||||
<a name='L30'></a><a href='#L30'>30</a>
|
||||
<a name='L31'></a><a href='#L31'>31</a>
|
||||
<a name='L32'></a><a href='#L32'>32</a>
|
||||
<a name='L33'></a><a href='#L33'>33</a>
|
||||
<a name='L34'></a><a href='#L34'>34</a>
|
||||
<a name='L35'></a><a href='#L35'>35</a>
|
||||
<a name='L36'></a><a href='#L36'>36</a>
|
||||
<a name='L37'></a><a href='#L37'>37</a>
|
||||
<a name='L38'></a><a href='#L38'>38</a>
|
||||
<a name='L39'></a><a href='#L39'>39</a>
|
||||
<a name='L40'></a><a href='#L40'>40</a>
|
||||
<a name='L41'></a><a href='#L41'>41</a>
|
||||
<a name='L42'></a><a href='#L42'>42</a>
|
||||
<a name='L43'></a><a href='#L43'>43</a>
|
||||
<a name='L44'></a><a href='#L44'>44</a>
|
||||
<a name='L45'></a><a href='#L45'>45</a>
|
||||
<a name='L46'></a><a href='#L46'>46</a>
|
||||
<a name='L47'></a><a href='#L47'>47</a>
|
||||
<a name='L48'></a><a href='#L48'>48</a>
|
||||
<a name='L49'></a><a href='#L49'>49</a>
|
||||
<a name='L50'></a><a href='#L50'>50</a>
|
||||
<a name='L51'></a><a href='#L51'>51</a>
|
||||
<a name='L52'></a><a href='#L52'>52</a>
|
||||
<a name='L53'></a><a href='#L53'>53</a>
|
||||
<a name='L54'></a><a href='#L54'>54</a>
|
||||
<a name='L55'></a><a href='#L55'>55</a>
|
||||
<a name='L56'></a><a href='#L56'>56</a>
|
||||
<a name='L57'></a><a href='#L57'>57</a>
|
||||
<a name='L58'></a><a href='#L58'>58</a>
|
||||
<a name='L59'></a><a href='#L59'>59</a>
|
||||
<a name='L60'></a><a href='#L60'>60</a>
|
||||
<a name='L61'></a><a href='#L61'>61</a>
|
||||
<a name='L62'></a><a href='#L62'>62</a>
|
||||
<a name='L63'></a><a href='#L63'>63</a>
|
||||
<a name='L64'></a><a href='#L64'>64</a>
|
||||
<a name='L65'></a><a href='#L65'>65</a>
|
||||
<a name='L66'></a><a href='#L66'>66</a>
|
||||
<a name='L67'></a><a href='#L67'>67</a>
|
||||
<a name='L68'></a><a href='#L68'>68</a>
|
||||
<a name='L69'></a><a href='#L69'>69</a>
|
||||
<a name='L70'></a><a href='#L70'>70</a>
|
||||
<a name='L71'></a><a href='#L71'>71</a>
|
||||
<a name='L72'></a><a href='#L72'>72</a>
|
||||
<a name='L73'></a><a href='#L73'>73</a>
|
||||
<a name='L74'></a><a href='#L74'>74</a>
|
||||
<a name='L75'></a><a href='#L75'>75</a>
|
||||
<a name='L76'></a><a href='#L76'>76</a>
|
||||
<a name='L77'></a><a href='#L77'>77</a>
|
||||
<a name='L78'></a><a href='#L78'>78</a>
|
||||
<a name='L79'></a><a href='#L79'>79</a>
|
||||
<a name='L80'></a><a href='#L80'>80</a>
|
||||
<a name='L81'></a><a href='#L81'>81</a>
|
||||
<a name='L82'></a><a href='#L82'>82</a>
|
||||
<a name='L83'></a><a href='#L83'>83</a>
|
||||
<a name='L84'></a><a href='#L84'>84</a>
|
||||
<a name='L85'></a><a href='#L85'>85</a>
|
||||
<a name='L86'></a><a href='#L86'>86</a>
|
||||
<a name='L87'></a><a href='#L87'>87</a>
|
||||
<a name='L88'></a><a href='#L88'>88</a>
|
||||
<a name='L89'></a><a href='#L89'>89</a>
|
||||
<a name='L90'></a><a href='#L90'>90</a>
|
||||
<a name='L91'></a><a href='#L91'>91</a>
|
||||
<a name='L92'></a><a href='#L92'>92</a>
|
||||
<a name='L93'></a><a href='#L93'>93</a>
|
||||
<a name='L94'></a><a href='#L94'>94</a>
|
||||
<a name='L95'></a><a href='#L95'>95</a>
|
||||
<a name='L96'></a><a href='#L96'>96</a>
|
||||
<a name='L97'></a><a href='#L97'>97</a>
|
||||
<a name='L98'></a><a href='#L98'>98</a>
|
||||
<a name='L99'></a><a href='#L99'>99</a>
|
||||
<a name='L100'></a><a href='#L100'>100</a>
|
||||
<a name='L101'></a><a href='#L101'>101</a>
|
||||
<a name='L102'></a><a href='#L102'>102</a>
|
||||
<a name='L103'></a><a href='#L103'>103</a>
|
||||
<a name='L104'></a><a href='#L104'>104</a>
|
||||
<a name='L105'></a><a href='#L105'>105</a>
|
||||
<a name='L106'></a><a href='#L106'>106</a>
|
||||
<a name='L107'></a><a href='#L107'>107</a>
|
||||
<a name='L108'></a><a href='#L108'>108</a>
|
||||
<a name='L109'></a><a href='#L109'>109</a>
|
||||
<a name='L110'></a><a href='#L110'>110</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">40x</span>
|
||||
<span class="cline-any cline-yes">34x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">22x</span>
|
||||
<span class="cline-any cline-yes">22x</span>
|
||||
<span class="cline-any cline-yes">18x</span>
|
||||
<span class="cline-any cline-yes">48x</span>
|
||||
<span class="cline-any cline-yes">48x</span>
|
||||
<span class="cline-any cline-yes">36x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">18x</span>
|
||||
<span class="cline-any cline-yes">18x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">14x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">11x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">8x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/**
|
||||
* Compute "open now" / "always open" for a pharmacy whose opening_hours is
|
||||
* stored as JSON in the { mon, tue, ..., sun } shape produced by
|
||||
* apps/API/opening-hours-osm.js.
|
||||
*
|
||||
* 24/7 is internally represented as every day ["00:00", "24:00"]. The
|
||||
* literal "24:00" is not valid HH:mm ISO; we accept it as 1440 minutes
|
||||
* (00:00 of the next day) so range math works, and treat a 24h week as
|
||||
* the dedicated `kind: '24h'` result.
|
||||
*
|
||||
* Midnight-crossing ranges (close <= open) are detected by comparing
|
||||
* the previous day's range when "now" is in the early hours.
|
||||
*/
|
||||
|
||||
const DAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
||||
|
||||
function parse(raw) {
|
||||
if (raw == null || raw === '') return null;
|
||||
if (typeof raw === 'object') return raw;
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function toMin(hm) {
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (hm == null) <span class="cstat-no" title="statement not covered" >return null;</span>
|
||||
const parts = String(hm).split(':');
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (parts.length !== 2) <span class="cstat-no" title="statement not covered" >return null;</span>
|
||||
const h = Number(parts[0]);
|
||||
const m = Number(parts[1]);
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (!Number.isFinite(h) || !Number.isFinite(m)) <span class="cstat-no" title="statement not covered" >return null;</span>
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (h === 24 && <span class="branch-1 cbranch-no" title="branch not covered" >m === 0)</span> <span class="cstat-no" title="statement not covered" >return 1440;</span>
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (h < 0 || h > 24 || m < 0 || m >= 60) <span class="cstat-no" title="statement not covered" >return null;</span>
|
||||
return h * 60 + m;
|
||||
}
|
||||
|
||||
function findNextOpen(h, now) {
|
||||
for (let off = 1; off <= 7; off++) {
|
||||
const key = DAYS[(now.getDay() + off) % 7];
|
||||
const r = h[key];
|
||||
if (Array.isArray(r) && r.length === 2) {
|
||||
return { day: key, time: r[0] };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isAlwaysOpen(rawHours) {
|
||||
const h = parse(rawHours);
|
||||
if (!h || typeof h !== 'object') return false;
|
||||
for (const d of DAYS) {
|
||||
const r = h[d];
|
||||
if (!Array.isArray(r) || r.length !== 2) return false;
|
||||
if (r[0] !== '00:00' || r[1] !== '24:00') return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function isOpenNow(rawHours, now = new Date()) {
|
||||
const h = parse(rawHours);
|
||||
if (!h) return null;
|
||||
|
||||
if (isAlwaysOpen(h)) {
|
||||
return { isOpen: true, kind: '24h' };
|
||||
}
|
||||
|
||||
const dayKey = DAYS[now.getDay()];
|
||||
const range = h[dayKey];
|
||||
|
||||
if (!Array.isArray(range) || range.length !== 2) {
|
||||
return { isOpen: false, kind: 'closed', nextOpen: findNextOpen(h, now) };
|
||||
}
|
||||
|
||||
const openM = toMin(range[0]);
|
||||
const closeM = toMin(range[1]);
|
||||
<span class="missing-if-branch" title="if path not taken" >I</span>if (openM == null || closeM == null) <span class="cstat-no" title="statement not covered" >return null;</span>
|
||||
|
||||
const nowM = now.getHours() * 60 + now.getMinutes();
|
||||
|
||||
// First: is "now" still inside yesterday's midnight-crossing range?
|
||||
// (Today is irrelevant while we're still in the previous day's after-midnight tail.)
|
||||
const yestKey = DAYS[(now.getDay() + 6) % 7];
|
||||
const yest = h[yestKey];
|
||||
if (Array.isArray(yest) && yest.length === 2) {
|
||||
const yOpen = toMin(yest[0]);
|
||||
const yClose = toMin(yest[1]);
|
||||
if (yOpen != null && yClose != null && yClose <= yOpen && nowM < yClose) {
|
||||
return { isOpen: true, kind: 'open', closesAt: yest[1] };
|
||||
}
|
||||
}
|
||||
|
||||
// Midnight-crossing: today's range spans past 24:00.
|
||||
if (closeM <= openM) {
|
||||
if (nowM >= openM) {
|
||||
return { isOpen: true, kind: 'open', closesAt: range[1] };
|
||||
}
|
||||
return { isOpen: false, kind: 'before-open', opensAt: range[0], nextOpen: null };
|
||||
}
|
||||
|
||||
if (nowM < openM) {
|
||||
return { isOpen: false, kind: 'before-open', opensAt: range[0], nextOpen: null };
|
||||
}
|
||||
if (nowM >= closeM) {
|
||||
return { isOpen: false, kind: 'after-close', nextOpen: findNextOpen(h, now) };
|
||||
}
|
||||
return { isOpen: true, kind: 'open', closesAt: range[1] };
|
||||
}
|
||||
</pre></td></tr></table></pre>
|
||||
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
||||
at 2026-07-27T11:29:31.802Z
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
prettyPrint();
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Code coverage report for All files</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>All files</h1>
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">91.3% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>63/69</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">90.14% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>64/71</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>5/5</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>56/56</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
<template id="filterTemplate">
|
||||
<div class="quiet">
|
||||
Filter:
|
||||
<input type="search" id="fileSearch">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<div class="pad1">
|
||||
<table class="coverage-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td class="file high" data-value="hours.js"><a href="hours.js.html">hours.js</a></td>
|
||||
<td data-value="91.3" class="pic high">
|
||||
<div class="chart"><div class="cover-fill" style="width: 91%"></div><div class="cover-empty" style="width: 9%"></div></div>
|
||||
</td>
|
||||
<td data-value="91.3" class="pct high">91.3%</td>
|
||||
<td data-value="69" class="abs high">63/69</td>
|
||||
<td data-value="90.14" class="pct high">90.14%</td>
|
||||
<td data-value="71" class="abs high">64/71</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="5" class="abs high">5/5</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="56" class="abs high">56/56</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
||||
at 2026-07-27T11:29:31.802Z
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
prettyPrint();
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
@@ -0,0 +1,210 @@
|
||||
/* eslint-disable */
|
||||
var addSorting = (function() {
|
||||
'use strict';
|
||||
var cols,
|
||||
currentSort = {
|
||||
index: 0,
|
||||
desc: false
|
||||
};
|
||||
|
||||
// returns the summary table element
|
||||
function getTable() {
|
||||
return document.querySelector('.coverage-summary');
|
||||
}
|
||||
// returns the thead element of the summary table
|
||||
function getTableHeader() {
|
||||
return getTable().querySelector('thead tr');
|
||||
}
|
||||
// returns the tbody element of the summary table
|
||||
function getTableBody() {
|
||||
return getTable().querySelector('tbody');
|
||||
}
|
||||
// returns the th element for nth column
|
||||
function getNthColumn(n) {
|
||||
return getTableHeader().querySelectorAll('th')[n];
|
||||
}
|
||||
|
||||
function onFilterInput() {
|
||||
const searchValue = document.getElementById('fileSearch').value;
|
||||
const rows = document.getElementsByTagName('tbody')[0].children;
|
||||
|
||||
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
||||
// it will be treated as a plain text search
|
||||
let searchRegex;
|
||||
try {
|
||||
searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
|
||||
} catch (error) {
|
||||
searchRegex = null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
let isMatch = false;
|
||||
|
||||
if (searchRegex) {
|
||||
// If a valid regex was created, use it for matching
|
||||
isMatch = searchRegex.test(row.textContent);
|
||||
} else {
|
||||
// Otherwise, fall back to the original plain text search
|
||||
isMatch = row.textContent
|
||||
.toLowerCase()
|
||||
.includes(searchValue.toLowerCase());
|
||||
}
|
||||
|
||||
row.style.display = isMatch ? '' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// loads the search box
|
||||
function addSearchBox() {
|
||||
var template = document.getElementById('filterTemplate');
|
||||
var templateClone = template.content.cloneNode(true);
|
||||
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
||||
template.parentElement.appendChild(templateClone);
|
||||
}
|
||||
|
||||
// loads all columns
|
||||
function loadColumns() {
|
||||
var colNodes = getTableHeader().querySelectorAll('th'),
|
||||
colNode,
|
||||
cols = [],
|
||||
col,
|
||||
i;
|
||||
|
||||
for (i = 0; i < colNodes.length; i += 1) {
|
||||
colNode = colNodes[i];
|
||||
col = {
|
||||
key: colNode.getAttribute('data-col'),
|
||||
sortable: !colNode.getAttribute('data-nosort'),
|
||||
type: colNode.getAttribute('data-type') || 'string'
|
||||
};
|
||||
cols.push(col);
|
||||
if (col.sortable) {
|
||||
col.defaultDescSort = col.type === 'number';
|
||||
colNode.innerHTML =
|
||||
colNode.innerHTML + '<span class="sorter"></span>';
|
||||
}
|
||||
}
|
||||
return cols;
|
||||
}
|
||||
// attaches a data attribute to every tr element with an object
|
||||
// of data values keyed by column name
|
||||
function loadRowData(tableRow) {
|
||||
var tableCols = tableRow.querySelectorAll('td'),
|
||||
colNode,
|
||||
col,
|
||||
data = {},
|
||||
i,
|
||||
val;
|
||||
for (i = 0; i < tableCols.length; i += 1) {
|
||||
colNode = tableCols[i];
|
||||
col = cols[i];
|
||||
val = colNode.getAttribute('data-value');
|
||||
if (col.type === 'number') {
|
||||
val = Number(val);
|
||||
}
|
||||
data[col.key] = val;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// loads all row data
|
||||
function loadData() {
|
||||
var rows = getTableBody().querySelectorAll('tr'),
|
||||
i;
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
rows[i].data = loadRowData(rows[i]);
|
||||
}
|
||||
}
|
||||
// sorts the table using the data for the ith column
|
||||
function sortByIndex(index, desc) {
|
||||
var key = cols[index].key,
|
||||
sorter = function(a, b) {
|
||||
a = a.data[key];
|
||||
b = b.data[key];
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
},
|
||||
finalSorter = sorter,
|
||||
tableBody = document.querySelector('.coverage-summary tbody'),
|
||||
rowNodes = tableBody.querySelectorAll('tr'),
|
||||
rows = [],
|
||||
i;
|
||||
|
||||
if (desc) {
|
||||
finalSorter = function(a, b) {
|
||||
return -1 * sorter(a, b);
|
||||
};
|
||||
}
|
||||
|
||||
for (i = 0; i < rowNodes.length; i += 1) {
|
||||
rows.push(rowNodes[i]);
|
||||
tableBody.removeChild(rowNodes[i]);
|
||||
}
|
||||
|
||||
rows.sort(finalSorter);
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
tableBody.appendChild(rows[i]);
|
||||
}
|
||||
}
|
||||
// removes sort indicators for current column being sorted
|
||||
function removeSortIndicators() {
|
||||
var col = getNthColumn(currentSort.index),
|
||||
cls = col.className;
|
||||
|
||||
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
||||
col.className = cls;
|
||||
}
|
||||
// adds sort indicators for current column being sorted
|
||||
function addSortIndicators() {
|
||||
getNthColumn(currentSort.index).className += currentSort.desc
|
||||
? ' sorted-desc'
|
||||
: ' sorted';
|
||||
}
|
||||
// adds event listeners for all sorter widgets
|
||||
function enableUI() {
|
||||
var i,
|
||||
el,
|
||||
ithSorter = function ithSorter(i) {
|
||||
var col = cols[i];
|
||||
|
||||
return function() {
|
||||
var desc = col.defaultDescSort;
|
||||
|
||||
if (currentSort.index === i) {
|
||||
desc = !currentSort.desc;
|
||||
}
|
||||
sortByIndex(i, desc);
|
||||
removeSortIndicators();
|
||||
currentSort.index = i;
|
||||
currentSort.desc = desc;
|
||||
addSortIndicators();
|
||||
};
|
||||
};
|
||||
for (i = 0; i < cols.length; i += 1) {
|
||||
if (cols[i].sortable) {
|
||||
// add the click event handler on the th so users
|
||||
// dont have to click on those tiny arrows
|
||||
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
||||
if (el.addEventListener) {
|
||||
el.addEventListener('click', ithSorter(i));
|
||||
} else {
|
||||
el.attachEvent('onclick', ithSorter(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// adds sorting functionality to the UI
|
||||
return function() {
|
||||
if (!getTable()) {
|
||||
return;
|
||||
}
|
||||
cols = loadColumns();
|
||||
loadData();
|
||||
addSearchBox();
|
||||
addSortIndicators();
|
||||
enableUI();
|
||||
};
|
||||
})();
|
||||
|
||||
window.addEventListener('load', addSorting);
|
||||
@@ -0,0 +1,146 @@
|
||||
TN:
|
||||
SF:src/hours.js
|
||||
FN:17,parse
|
||||
FN:27,toMin
|
||||
FN:39,findNextOpen
|
||||
FN:50,isAlwaysOpen
|
||||
FN:61,isOpenNow
|
||||
FNF:5
|
||||
FNH:5
|
||||
FNDA:40,parse
|
||||
FNDA:26,toMin
|
||||
FNDA:4,findNextOpen
|
||||
FNDA:22,isAlwaysOpen
|
||||
FNDA:18,isOpenNow
|
||||
DA:15,1
|
||||
DA:18,40
|
||||
DA:19,34
|
||||
DA:20,4
|
||||
DA:21,4
|
||||
DA:23,2
|
||||
DA:28,26
|
||||
DA:29,26
|
||||
DA:30,26
|
||||
DA:31,26
|
||||
DA:32,26
|
||||
DA:33,26
|
||||
DA:34,26
|
||||
DA:35,26
|
||||
DA:36,26
|
||||
DA:40,4
|
||||
DA:41,11
|
||||
DA:42,11
|
||||
DA:43,11
|
||||
DA:44,3
|
||||
DA:47,1
|
||||
DA:51,22
|
||||
DA:52,22
|
||||
DA:53,18
|
||||
DA:54,48
|
||||
DA:55,48
|
||||
DA:56,36
|
||||
DA:58,5
|
||||
DA:62,18
|
||||
DA:63,18
|
||||
DA:65,14
|
||||
DA:66,3
|
||||
DA:69,11
|
||||
DA:70,11
|
||||
DA:72,11
|
||||
DA:73,2
|
||||
DA:76,9
|
||||
DA:77,9
|
||||
DA:78,9
|
||||
DA:80,9
|
||||
DA:84,9
|
||||
DA:85,9
|
||||
DA:86,9
|
||||
DA:87,4
|
||||
DA:88,4
|
||||
DA:89,4
|
||||
DA:90,1
|
||||
DA:95,8
|
||||
DA:96,2
|
||||
DA:97,1
|
||||
DA:99,1
|
||||
DA:102,6
|
||||
DA:103,2
|
||||
DA:105,4
|
||||
DA:106,2
|
||||
DA:108,2
|
||||
LF:56
|
||||
LH:56
|
||||
BRDA:18,0,0,6
|
||||
BRDA:18,0,1,34
|
||||
BRDA:18,1,0,40
|
||||
BRDA:18,1,1,36
|
||||
BRDA:19,2,0,30
|
||||
BRDA:19,2,1,4
|
||||
BRDA:28,3,0,0
|
||||
BRDA:28,3,1,26
|
||||
BRDA:30,4,0,0
|
||||
BRDA:30,4,1,26
|
||||
BRDA:33,5,0,0
|
||||
BRDA:33,5,1,26
|
||||
BRDA:33,6,0,26
|
||||
BRDA:33,6,1,26
|
||||
BRDA:34,7,0,0
|
||||
BRDA:34,7,1,26
|
||||
BRDA:34,8,0,26
|
||||
BRDA:34,8,1,0
|
||||
BRDA:35,9,0,0
|
||||
BRDA:35,9,1,26
|
||||
BRDA:35,10,0,26
|
||||
BRDA:35,10,1,26
|
||||
BRDA:35,10,2,26
|
||||
BRDA:35,10,3,26
|
||||
BRDA:43,11,0,3
|
||||
BRDA:43,11,1,8
|
||||
BRDA:43,12,0,11
|
||||
BRDA:43,12,1,3
|
||||
BRDA:52,13,0,4
|
||||
BRDA:52,13,1,18
|
||||
BRDA:52,14,0,22
|
||||
BRDA:52,14,1,18
|
||||
BRDA:55,15,0,12
|
||||
BRDA:55,15,1,36
|
||||
BRDA:55,16,0,48
|
||||
BRDA:55,16,1,36
|
||||
BRDA:56,17,0,1
|
||||
BRDA:56,17,1,35
|
||||
BRDA:56,18,0,36
|
||||
BRDA:56,18,1,36
|
||||
BRDA:61,19,0,4
|
||||
BRDA:63,20,0,4
|
||||
BRDA:63,20,1,14
|
||||
BRDA:65,21,0,3
|
||||
BRDA:65,21,1,11
|
||||
BRDA:72,22,0,2
|
||||
BRDA:72,22,1,9
|
||||
BRDA:72,23,0,11
|
||||
BRDA:72,23,1,9
|
||||
BRDA:78,24,0,0
|
||||
BRDA:78,24,1,9
|
||||
BRDA:78,25,0,9
|
||||
BRDA:78,25,1,9
|
||||
BRDA:86,26,0,4
|
||||
BRDA:86,26,1,5
|
||||
BRDA:86,27,0,9
|
||||
BRDA:86,27,1,4
|
||||
BRDA:89,28,0,1
|
||||
BRDA:89,28,1,3
|
||||
BRDA:89,29,0,4
|
||||
BRDA:89,29,1,4
|
||||
BRDA:89,29,2,4
|
||||
BRDA:89,29,3,2
|
||||
BRDA:95,30,0,2
|
||||
BRDA:95,30,1,6
|
||||
BRDA:96,31,0,1
|
||||
BRDA:96,31,1,1
|
||||
BRDA:102,32,0,2
|
||||
BRDA:102,32,1,4
|
||||
BRDA:105,33,0,2
|
||||
BRDA:105,33,1,2
|
||||
BRF:71
|
||||
BRH:64
|
||||
end_of_record
|
||||
@@ -40,6 +40,7 @@
|
||||
"express-rate-limit": "^8.5.2",
|
||||
"express-session": "^1.17.3",
|
||||
"multer": "^2.2.0",
|
||||
"nodemailer": "^6.10.1",
|
||||
"pg": "^8.13.0",
|
||||
"pino": "^9.4.0",
|
||||
"pino-http": "^10.3.0",
|
||||
|
||||
@@ -25,9 +25,11 @@ import pinoHttp from 'pino-http';
|
||||
import multer from 'multer';
|
||||
import { searchMedicines, getMedicineDetails, searchOTC } from './cima-service.js';
|
||||
import { runFarmaciaWebhookImport, DEFAULT_FARMACIAS_WEBHOOK, importPharmaciesFromRows } from './farmacias-webhook-import.js';
|
||||
import { sendPasswordResetEmail, sendForgotUsernameEmail } from './src/email.js';
|
||||
import { fetchPharmaciesExternal } from '../API/index.js';
|
||||
import { validateProductionEnv } from './src/config/required-env.js';
|
||||
import { isOpenNow, isAlwaysOpen } from './src/hours.js';
|
||||
import crypto from 'crypto';
|
||||
|
||||
validateProductionEnv();
|
||||
|
||||
@@ -119,6 +121,7 @@ const searchLimiter = rateLimit({ windowMs: 60_000, max: 30, standardHeaders: tr
|
||||
const loginLimiter = rateLimit({ windowMs: 60_000, max: 5, standardHeaders: true, legacyHeaders: false, handler: limitHandler('login') });
|
||||
const registerLimiter = rateLimit({ windowMs: 60 * 60_000, max: 10, standardHeaders: true, legacyHeaders: false, handler: limitHandler('register') });
|
||||
const geocodeLimiter = rateLimit({ windowMs: 60_000, max: 10, standardHeaders: true, legacyHeaders: false, handler: limitHandler('geocode') });
|
||||
const forgotPasswordLimiter = rateLimit({ windowMs: 60_000, max: 3, standardHeaders: true, legacyHeaders: false, handler: limitHandler('forgot-password') });
|
||||
|
||||
const VAPID_PUBLIC_KEY = process.env.VAPID_PUBLIC_KEY || '';
|
||||
const VAPID_PRIVATE_KEY = process.env.VAPID_PRIVATE_KEY || '';
|
||||
@@ -602,6 +605,33 @@ if (!pgPool) {
|
||||
)
|
||||
`);
|
||||
}
|
||||
// Password reset tokens table
|
||||
if (pgPool) {
|
||||
await pgPool.query(`
|
||||
CREATE TABLE IF NOT EXISTS password_reset_tokens (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
used INTEGER NOT NULL DEFAULT 0,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
)
|
||||
`);
|
||||
await pgPool.query(`CREATE INDEX IF NOT EXISTS idx_pwd_reset_token ON password_reset_tokens(token)`);
|
||||
} else {
|
||||
await dbRun(`
|
||||
CREATE TABLE IF NOT EXISTS password_reset_tokens (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
used INTEGER NOT NULL DEFAULT 0,
|
||||
expires_at DATETIME NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
)
|
||||
`);
|
||||
await dbRun(`CREATE INDEX IF NOT EXISTS idx_pwd_reset_token ON password_reset_tokens(token)`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('initDatabase failed:', err);
|
||||
throw err;
|
||||
@@ -1204,6 +1234,86 @@ app.post('/api/auth/logout', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Forgot username — send username to user's email
|
||||
app.post('/api/auth/forgot-username', forgotPasswordLimiter, async (req, res) => {
|
||||
try {
|
||||
const { email } = req.body || {};
|
||||
if (!email || !String(email).trim()) {
|
||||
return res.status(400).json({ error: 'Email is required' });
|
||||
}
|
||||
const user = await userDbGet('SELECT username, email FROM users WHERE email = ?', [String(email).trim()]);
|
||||
if (user) {
|
||||
try {
|
||||
await sendForgotUsernameEmail(user.email, user.username);
|
||||
} catch (err) {
|
||||
console.error('Error sending forgot-username email:', err);
|
||||
}
|
||||
}
|
||||
res.json({ message: 'If the email exists, you will receive a message with your username.' });
|
||||
} catch (error) {
|
||||
console.error('Error in forgot-username:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Forgot password — generate reset token and send email
|
||||
app.post('/api/auth/forgot-password', forgotPasswordLimiter, async (req, res) => {
|
||||
try {
|
||||
const { email } = req.body || {};
|
||||
if (!email || !String(email).trim()) {
|
||||
return res.status(400).json({ error: 'Email is required' });
|
||||
}
|
||||
const user = await userDbGet('SELECT id, username, email FROM users WHERE email = ?', [String(email).trim()]);
|
||||
if (user) {
|
||||
const token = crypto.randomBytes(32).toString('hex');
|
||||
const expiresAt = new Date(Date.now() + 60 * 60 * 1000); // 1 hour
|
||||
await userDbRun(
|
||||
'INSERT INTO password_reset_tokens (user_id, token, expires_at) VALUES (?, ?, ?)',
|
||||
[user.id, token, expiresAt.toISOString()]
|
||||
);
|
||||
try {
|
||||
await sendPasswordResetEmail(user.email, user.username, token);
|
||||
} catch (err) {
|
||||
console.error('Error sending password reset email:', err);
|
||||
}
|
||||
}
|
||||
res.json({ message: 'If the email exists, you will receive a password reset link.' });
|
||||
} catch (error) {
|
||||
console.error('Error in forgot-password:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Reset password — validate token and update password
|
||||
app.post('/api/auth/reset-password', forgotPasswordLimiter, async (req, res) => {
|
||||
try {
|
||||
const { token, password } = req.body || {};
|
||||
if (!token) return res.status(400).json({ error: 'Token is required' });
|
||||
if (!password || String(password).length < 8) {
|
||||
return res.status(400).json({ error: 'Password must be at least 8 characters' });
|
||||
}
|
||||
|
||||
const row = await userDbGet(
|
||||
'SELECT id, user_id, used, expires_at FROM password_reset_tokens WHERE token = ?',
|
||||
[token]
|
||||
);
|
||||
if (!row) return res.status(400).json({ error: 'Invalid or expired token' });
|
||||
if (row.used) return res.status(400).json({ error: 'Token already used' });
|
||||
|
||||
const expiresAt = new Date(row.expires_at);
|
||||
if (isNaN(expiresAt.getTime()) || expiresAt < new Date()) return res.status(400).json({ error: 'Token has expired' });
|
||||
|
||||
const passwordHash = await bcrypt.hash(String(password), 10);
|
||||
await userDbRun('UPDATE users SET password_hash = ? WHERE id = ?', [passwordHash, row.user_id]);
|
||||
await userDbRun('UPDATE password_reset_tokens SET used = 1 WHERE id = ?', [row.id]);
|
||||
|
||||
res.json({ message: 'Password updated successfully.' });
|
||||
} catch (error) {
|
||||
console.error('Error in reset-password:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Check authentication status — reads fresh user record so profile fields stay current
|
||||
app.get('/api/auth/check', async (req, res) => {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
const SMTP_HOST = process.env.SMTP_HOST || 'localhost';
|
||||
const SMTP_PORT = parseInt(process.env.SMTP_PORT || '1025', 10);
|
||||
const SMTP_USER = process.env.SMTP_USER || '';
|
||||
const SMTP_PASS = process.env.SMTP_PASS || '';
|
||||
const SMTP_FROM = process.env.SMTP_FROM || 'noreply@farmafinder.com';
|
||||
const APP_URL = process.env.APP_URL || 'http://localhost:3000';
|
||||
|
||||
let transporter = null;
|
||||
|
||||
function getTransporter() {
|
||||
if (transporter) return transporter;
|
||||
const auth = SMTP_USER && SMTP_PASS ? { user: SMTP_USER, pass: SMTP_PASS } : undefined;
|
||||
transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
secure: SMTP_PORT === 465,
|
||||
auth,
|
||||
ignoreTLS: SMTP_PORT !== 465 && !SMTP_USER,
|
||||
});
|
||||
return transporter;
|
||||
}
|
||||
|
||||
export async function sendPasswordResetEmail(email, username, token) {
|
||||
const resetUrl = `${APP_URL}/reset-password?token=${token}`;
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset="utf-8"></head>
|
||||
<body style="font-family: sans-serif; max-width: 480px; margin: 0 auto; padding: 24px;">
|
||||
<h2>Restablecer contraseña — FarmaFinder</h2>
|
||||
<p>Hola <strong>${username}</strong>,</p>
|
||||
<p>Has solicitado restablecer tu contraseña. Haz clic en el siguiente enlace para crear una nueva:</p>
|
||||
<p style="text-align: center; margin: 32px 0;">
|
||||
<a href="${resetUrl}"
|
||||
style="background: #2563eb; color: #fff; padding: 12px 24px; border-radius: 6px; text-decoration: none; display: inline-block;">
|
||||
Restablecer contraseña
|
||||
</a>
|
||||
</p>
|
||||
<p>Si no has solicitado este cambio, ignora este mensaje.</p>
|
||||
<p>El enlace caduca en 1 hora.</p>
|
||||
<hr style="margin-top: 32px; border: none; border-top: 1px solid #e5e7eb;">
|
||||
<p style="color: #6b7280; font-size: 12px;">FarmaFinder — Encuentra tus medicamentos en farmacias cercanas</p>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
const text = `Restablecer contraseña — FarmaFinder\n\nHola ${username},\n\nHas solicitado restablecer tu contraseña. Abre este enlace para crear una nueva:\n${resetUrl}\n\nSi no has solicitado este cambio, ignora este mensaje.\nEl enlace caduca en 1 hora.`;
|
||||
|
||||
await getTransporter().sendMail({
|
||||
from: SMTP_FROM,
|
||||
to: email,
|
||||
subject: 'Restablece tu contraseña — FarmaFinder',
|
||||
text,
|
||||
html,
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendForgotUsernameEmail(email, username) {
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset="utf-8"></head>
|
||||
<body style="font-family: sans-serif; max-width: 480px; margin: 0 auto; padding: 24px;">
|
||||
<h2>Tu usuario — FarmaFinder</h2>
|
||||
<p>Has solicitado recordar tu nombre de usuario.</p>
|
||||
<p style="font-size: 20px; text-align: center; padding: 16px; background: #f3f4f6; border-radius: 6px; margin: 24px 0;">
|
||||
<strong>${username}</strong>
|
||||
</p>
|
||||
<p>Puedes iniciar sesión con este usuario y tu contraseña.</p>
|
||||
<p>Si no has solicitado este dato, ignora este mensaje.</p>
|
||||
<hr style="margin-top: 32px; border: none; border-top: 1px solid #e5e7eb;">
|
||||
<p style="color: #6b7280; font-size: 12px;">FarmaFinder — Encuentra tus medicamentos en farmacias cercanas</p>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
const text = `Tu usuario — FarmaFinder\n\nHas solicitado recordar tu nombre de usuario.\n\nTu usuario es: ${username}\n\nSi no has solicitado este dato, ignora este mensaje.`;
|
||||
|
||||
await getTransporter().sendMail({
|
||||
from: SMTP_FROM,
|
||||
to: email,
|
||||
subject: 'Tu nombre de usuario — FarmaFinder',
|
||||
text,
|
||||
html,
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import AlertsView from './views/AlertsView';
|
||||
import ProfileView from './views/ProfileView';
|
||||
import AdminView from './views/AdminView';
|
||||
import LoginModal from './components/LoginModal';
|
||||
import ForgotPasswordModal from './components/ForgotPasswordModal';
|
||||
import ResetPasswordView from './views/ResetPasswordView';
|
||||
import SavedNotifications from './components/SavedNotifications';
|
||||
import BottomNav from './components/BottomNav';
|
||||
import { getFaro } from './utils/faro';
|
||||
@@ -17,6 +19,9 @@ function App() {
|
||||
const [currentUser, setCurrentUser] = useState(null);
|
||||
const [authChecked, setAuthChecked] = useState(false);
|
||||
const [showLogin, setShowLogin] = useState(false);
|
||||
const [showForgot, setShowForgot] = useState(false);
|
||||
const [forgotMode, setForgotMode] = useState('password');
|
||||
const [resetToken, setResetToken] = useState(null);
|
||||
const [showSaved, setShowSaved] = useState(false);
|
||||
const [badgeCount, setBadgeCount] = useState(0);
|
||||
const [prescriptionSearch, setPrescriptionSearch] = useState('');
|
||||
@@ -67,6 +72,13 @@ function App() {
|
||||
});
|
||||
};
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const token = params.get('token');
|
||||
if (token) {
|
||||
setResetToken(token);
|
||||
setScreen('reset-password');
|
||||
}
|
||||
|
||||
fetch('/api/auth/check')
|
||||
.then(r => r.json())
|
||||
.then(data => { if (data.authenticated) setCurrentUser(data.user); })
|
||||
@@ -126,6 +138,18 @@ function App() {
|
||||
setCurrentUser(prev => ({ ...prev, ...updated }));
|
||||
}
|
||||
|
||||
function handleForgotPassword(mode) {
|
||||
setForgotMode(mode);
|
||||
setShowLogin(false);
|
||||
setShowForgot(true);
|
||||
}
|
||||
|
||||
function handleResetComplete() {
|
||||
setResetToken(null);
|
||||
setShowLogin(true);
|
||||
window.history.replaceState({}, '', '/');
|
||||
}
|
||||
|
||||
function handleAdminClick() {
|
||||
setScreen('admin');
|
||||
}
|
||||
@@ -211,6 +235,14 @@ function App() {
|
||||
/>
|
||||
);
|
||||
break;
|
||||
case 'reset-password':
|
||||
activeView = (
|
||||
<ResetPasswordView
|
||||
token={resetToken}
|
||||
onReset={handleResetComplete}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
case 'admin':
|
||||
activeView = <AdminView />;
|
||||
break;
|
||||
@@ -243,6 +275,18 @@ function App() {
|
||||
<LoginModal
|
||||
onLogin={handleLogin}
|
||||
onClose={() => setShowLogin(false)}
|
||||
onForgotPassword={handleForgotPassword}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showForgot && (
|
||||
<ForgotPasswordModal
|
||||
initialMode={forgotMode}
|
||||
onClose={() => setShowForgot(false)}
|
||||
onBackToLogin={() => {
|
||||
setShowForgot(false);
|
||||
setShowLogin(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
.forgot-box {
|
||||
max-width: 380px;
|
||||
}
|
||||
|
||||
.forgot-back {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--primary);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
margin-bottom: 1rem;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.forgot-back:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.forgot-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.forgot-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.85rem;
|
||||
background: var(--surface-muted);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: calc(var(--radius) - 4px);
|
||||
padding: 1rem;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.forgot-option:hover {
|
||||
border-color: var(--primary);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.forgot-option-icon {
|
||||
font-size: 1.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.forgot-option-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.forgot-option-desc {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.forgot-sent-icon {
|
||||
text-align: center;
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.forgot-sent-text {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useTranslation } from '../i18n';
|
||||
import './LoginModal.css';
|
||||
import './ForgotPasswordModal.css';
|
||||
|
||||
function ForgotPasswordModal({ onClose, onBackToLogin, initialMode }) {
|
||||
const { t } = useTranslation();
|
||||
const [step, setStep] = useState(initialMode ? 'email' : 'choose'); // choose | email | sent
|
||||
const [mode, setMode] = useState(initialMode || ''); // username | password
|
||||
const [email, setEmail] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const emailRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
emailRef.current?.focus();
|
||||
function handleKey(e) { if (e.key === 'Escape') onClose(); }
|
||||
document.addEventListener('keydown', handleKey);
|
||||
return () => document.removeEventListener('keydown', handleKey);
|
||||
}, [onClose]);
|
||||
|
||||
function handleChoose(m) {
|
||||
setMode(m);
|
||||
setStep('email');
|
||||
setError('');
|
||||
}
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
const em = email.trim();
|
||||
if (!em) return;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const endpoint = mode === 'password'
|
||||
? '/api/auth/forgot-password'
|
||||
: '/api/auth/forgot-username';
|
||||
const res = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: em }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
setError(data.error || t('forgot.error'));
|
||||
return;
|
||||
}
|
||||
setStep('sent');
|
||||
} catch {
|
||||
setError(t('login.networkError'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
if (step === 'email') setStep('choose');
|
||||
else onBackToLogin();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="modal-overlay" onClick={onClose}>
|
||||
<div
|
||||
className="modal-box forgot-box"
|
||||
onClick={e => e.stopPropagation()}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="forgot-title"
|
||||
>
|
||||
{step === 'choose' && (
|
||||
<>
|
||||
<button type="button" className="forgot-back" onClick={onBackToLogin} aria-label={t('forgot.back')}>
|
||||
← {t('forgot.backToLogin')}
|
||||
</button>
|
||||
<h2 id="forgot-title">{t('forgot.title')}</h2>
|
||||
<p className="modal-sub">{t('forgot.subtitle')}</p>
|
||||
<div className="forgot-options">
|
||||
<button
|
||||
type="button"
|
||||
className="forgot-option"
|
||||
onClick={() => handleChoose('password')}
|
||||
>
|
||||
<span className="forgot-option-icon">🔑</span>
|
||||
<span className="forgot-option-text">
|
||||
<strong>{t('forgot.password')}</strong>
|
||||
<span className="forgot-option-desc">{t('forgot.passwordDesc')}</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="forgot-option"
|
||||
onClick={() => handleChoose('username')}
|
||||
>
|
||||
<span className="forgot-option-icon">👤</span>
|
||||
<span className="forgot-option-text">
|
||||
<strong>{t('forgot.username')}</strong>
|
||||
<span className="forgot-option-desc">{t('forgot.usernameDesc')}</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{step === 'email' && (
|
||||
<>
|
||||
<button type="button" className="forgot-back" onClick={handleBack} aria-label={t('forgot.back')}>
|
||||
← {t('forgot.back')}
|
||||
</button>
|
||||
<h2 id="forgot-title">
|
||||
{mode === 'password' ? t('forgot.resetTitle') : t('forgot.usernameTitle')}
|
||||
</h2>
|
||||
<p className="modal-sub">
|
||||
{mode === 'password' ? t('forgot.resetDesc') : t('forgot.usernameDesc2')}
|
||||
</p>
|
||||
<form onSubmit={handleSubmit} noValidate>
|
||||
<div className="modal-field">
|
||||
<label htmlFor="forgot-email">{t('forgot.email')}</label>
|
||||
<input
|
||||
id="forgot-email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={e => setEmail(e.target.value)}
|
||||
autoComplete="email"
|
||||
ref={emailRef}
|
||||
disabled={loading}
|
||||
placeholder={t('forgot.emailPlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="modal-error">{error}</p>}
|
||||
<div className="modal-actions">
|
||||
<button type="button" className="modal-cancel" onClick={handleBack} disabled={loading}>
|
||||
{t('forgot.cancel')}
|
||||
</button>
|
||||
<button type="submit" className="modal-submit" disabled={loading || !email.trim()}>
|
||||
{loading ? t('forgot.sending') : t('forgot.send')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
)}
|
||||
|
||||
{step === 'sent' && (
|
||||
<>
|
||||
<div className="forgot-sent-icon">✅</div>
|
||||
<h2 id="forgot-title">{t('forgot.sentTitle')}</h2>
|
||||
<p className="forgot-sent-text">{t('forgot.sentText')}</p>
|
||||
<div className="modal-actions" style={{ justifyContent: 'center' }}>
|
||||
<button type="button" className="modal-submit" onClick={onClose}>
|
||||
{t('forgot.close')}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ForgotPasswordModal;
|
||||
@@ -171,3 +171,27 @@
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.forgot-links {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.forgot-link {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
padding: 0.2rem 0;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.forgot-link:hover {
|
||||
color: #0a0b0a;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useTranslation } from '../i18n';
|
||||
import './LoginModal.css';
|
||||
|
||||
function LoginModal({ onLogin, onClose, initialMode = 'login' }) {
|
||||
function LoginModal({ onLogin, onClose, initialMode = 'login', onForgotPassword }) {
|
||||
const { t } = useTranslation();
|
||||
const [mode, setMode] = useState(initialMode === 'register' ? 'register' : 'login');
|
||||
const [username, setUsername] = useState('');
|
||||
@@ -148,6 +148,24 @@ function LoginModal({ onLogin, onClose, initialMode = 'login' }) {
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{!isRegister && (
|
||||
<div className="forgot-links">
|
||||
<button
|
||||
type="button"
|
||||
className="forgot-link"
|
||||
onClick={() => onForgotPassword('password')}
|
||||
>
|
||||
{t('forgot.forgotPassword')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="forgot-link"
|
||||
onClick={() => onForgotPassword('username')}
|
||||
>
|
||||
{t('forgot.forgotUsername')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -251,6 +251,45 @@ const ca = {
|
||||
'profile.languageCatalan': 'Català',
|
||||
'profile.languageSpanish': 'Castellà',
|
||||
|
||||
// ForgotPasswordModal
|
||||
'forgot.title': 'Problemes per accedir?',
|
||||
'forgot.subtitle': 'Tria què necessites recuperar',
|
||||
'forgot.password': 'He oblidat la meva contrasenya',
|
||||
'forgot.passwordDesc': 'T\'enviarem un enllaç per crear-ne una de nova',
|
||||
'forgot.username': 'He oblidat el meu usuari',
|
||||
'forgot.usernameDesc': 'T\'enviarem el teu nom d\'usuari',
|
||||
'forgot.resetTitle': 'Restablir contrasenya',
|
||||
'forgot.resetDesc': 'Introdueix el teu correu electrònic i t\'enviarem un enllaç per crear una nova contrasenya.',
|
||||
'forgot.usernameTitle': 'Recuperar usuari',
|
||||
'forgot.usernameDesc2': 'Introdueix el teu correu electrònic i t\'enviarem el teu nom d\'usuari.',
|
||||
'forgot.email': 'Correu electrònic',
|
||||
'forgot.emailPlaceholder': 'el_teu@email.com',
|
||||
'forgot.send': 'Enviar',
|
||||
'forgot.sending': 'Enviant...',
|
||||
'forgot.cancel': 'Cancel·lar',
|
||||
'forgot.back': 'Tornar',
|
||||
'forgot.backToLogin': 'Tornar a iniciar sessió',
|
||||
'forgot.sentTitle': 'Correu enviat',
|
||||
'forgot.sentText': 'Si l\'adreça de correu existeix a la nostra base de dades, rebràs un missatge en uns minuts. Revisa la teva safata d\'entrada.',
|
||||
'forgot.close': 'Tancar',
|
||||
'forgot.error': 'Error en processar la sol·licitud',
|
||||
'forgot.forgotPassword': 'Has oblidat la contrasenya?',
|
||||
'forgot.forgotUsername': 'Has oblidat l\'usuari?',
|
||||
|
||||
// ResetPasswordView
|
||||
'reset.title': 'Crear nova contrasenya',
|
||||
'reset.subtitle': 'Introdueix la teva nova contrasenya',
|
||||
'reset.newPassword': 'Nova contrasenya',
|
||||
'reset.confirmPassword': 'Confirmar contrasenya',
|
||||
'reset.saveBtn': 'Canviar contrasenya',
|
||||
'reset.saving': 'Desant...',
|
||||
'reset.passwordsDontMatch': 'Les contrasenyes no coincideixen',
|
||||
'reset.successTitle': 'Contrasenya actualitzada',
|
||||
'reset.successText': 'La teva contrasenya s\'ha actualitzat correctament. Ja pots iniciar sessió amb la teva nova contrasenya.',
|
||||
'reset.goToLogin': 'Anar a iniciar sessió',
|
||||
'reset.error': 'Error en restablir la contrasenya',
|
||||
'reset.invalidToken': 'Enllaç invàlid o caducat. Sol·licita un nou restabliment de contrasenya.',
|
||||
|
||||
// SavedNotifications
|
||||
'savedNotifications.title': '🔔 Notificacions Desades',
|
||||
'savedNotifications.close': 'Tancar',
|
||||
|
||||
@@ -251,6 +251,45 @@ const es = {
|
||||
'profile.languageCatalan': 'Català',
|
||||
'profile.languageSpanish': 'Castellano',
|
||||
|
||||
// ForgotPasswordModal
|
||||
'forgot.title': '¿Problemas para acceder?',
|
||||
'forgot.subtitle': 'Elige qué necesitas recuperar',
|
||||
'forgot.password': 'He olvidado mi contraseña',
|
||||
'forgot.passwordDesc': 'Te enviaremos un enlace para crear una nueva',
|
||||
'forgot.username': 'He olvidado mi usuario',
|
||||
'forgot.usernameDesc': 'Te enviaremos tu nombre de usuario',
|
||||
'forgot.resetTitle': 'Restablecer contraseña',
|
||||
'forgot.resetDesc': 'Introduce tu correo electrónico y te enviaremos un enlace para crear una nueva contraseña.',
|
||||
'forgot.usernameTitle': 'Recuperar usuario',
|
||||
'forgot.usernameDesc2': 'Introduce tu correo electrónico y te enviaremos tu nombre de usuario.',
|
||||
'forgot.email': 'Correo electrónico',
|
||||
'forgot.emailPlaceholder': 'tu@email.com',
|
||||
'forgot.send': 'Enviar',
|
||||
'forgot.sending': 'Enviando...',
|
||||
'forgot.cancel': 'Cancelar',
|
||||
'forgot.back': 'Volver',
|
||||
'forgot.backToLogin': 'Volver a iniciar sesión',
|
||||
'forgot.sentTitle': 'Correo enviado',
|
||||
'forgot.sentText': 'Si la dirección de correo existe en nuestra base de datos, recibirás un mensaje en unos minutos. Revisa tu bandeja de entrada.',
|
||||
'forgot.close': 'Cerrar',
|
||||
'forgot.error': 'Error al procesar la solicitud',
|
||||
'forgot.forgotPassword': '¿Olvidaste tu contraseña?',
|
||||
'forgot.forgotUsername': '¿Olvidaste tu usuario?',
|
||||
|
||||
// ResetPasswordView
|
||||
'reset.title': 'Crear nueva contraseña',
|
||||
'reset.subtitle': 'Introduce tu nueva contraseña',
|
||||
'reset.newPassword': 'Nueva contraseña',
|
||||
'reset.confirmPassword': 'Confirmar contraseña',
|
||||
'reset.saveBtn': 'Cambiar contraseña',
|
||||
'reset.saving': 'Guardando...',
|
||||
'reset.passwordsDontMatch': 'Las contraseñas no coinciden',
|
||||
'reset.successTitle': 'Contraseña actualizada',
|
||||
'reset.successText': 'Tu contraseña se ha actualizado correctamente. Ya puedes iniciar sesión con tu nueva contraseña.',
|
||||
'reset.goToLogin': 'Ir a iniciar sesión',
|
||||
'reset.error': 'Error al restablecer la contraseña',
|
||||
'reset.invalidToken': 'Enlace inválido o expirado. Solicita un nuevo restablecimiento de contraseña.',
|
||||
|
||||
// SavedNotifications
|
||||
'savedNotifications.title': '🔔 Notificaciones Guardadas',
|
||||
'savedNotifications.close': 'Cerrar',
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
.reset-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.reset-card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 2rem 2.25rem 1.75rem;
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
box-shadow: 0 20px 60px rgba(28, 25, 23, 0.12);
|
||||
}
|
||||
|
||||
.reset-card h2 {
|
||||
margin: 0 0 0.25rem;
|
||||
font-size: 1.35rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.reset-sub {
|
||||
margin: 0 0 1.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.reset-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.reset-field label {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.reset-field input {
|
||||
padding: 0.6rem 0.85rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: calc(var(--radius) - 4px);
|
||||
background: var(--surface-muted);
|
||||
color: var(--text-main);
|
||||
font-size: 0.95rem;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
.reset-field input:focus {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.reset-field input:disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.reset-error {
|
||||
font-size: 0.82rem;
|
||||
color: var(--error);
|
||||
margin: 0.25rem 0 0.75rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
width: 100%;
|
||||
background: var(--primary);
|
||||
border: none;
|
||||
color: var(--on-primary);
|
||||
padding: 0.65rem 1.35rem;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
transition: opacity 0.15s;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.reset-btn:hover:not(:disabled) {
|
||||
opacity: 0.88;
|
||||
}
|
||||
|
||||
.reset-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.reset-icon {
|
||||
text-align: center;
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useTranslation } from '../i18n';
|
||||
import './ResetPasswordView.css';
|
||||
|
||||
function ResetPasswordView({ token, onReset }) {
|
||||
const { t } = useTranslation();
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirm, setConfirm] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) setError(t('reset.invalidToken'));
|
||||
}, [token, t]);
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (password.length < 8) {
|
||||
setError(t('login.passwordError'));
|
||||
return;
|
||||
}
|
||||
if (password !== confirm) {
|
||||
setError(t('reset.passwordsDontMatch'));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const res = await fetch('/api/auth/reset-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token, password }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
setError(data.error || t('reset.error'));
|
||||
return;
|
||||
}
|
||||
setSuccess(true);
|
||||
} catch {
|
||||
setError(t('login.networkError'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
return (
|
||||
<div className="reset-container">
|
||||
<div className="reset-card">
|
||||
<div className="reset-icon">✅</div>
|
||||
<h2>{t('reset.successTitle')}</h2>
|
||||
<p>{t('reset.successText')}</p>
|
||||
<button type="button" className="reset-btn" onClick={onReset}>
|
||||
{t('reset.goToLogin')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="reset-container">
|
||||
<div className="reset-card">
|
||||
<h2>{t('reset.title')}</h2>
|
||||
<p className="reset-sub">{t('reset.subtitle')}</p>
|
||||
<form onSubmit={handleSubmit} noValidate>
|
||||
<div className="reset-field">
|
||||
<label htmlFor="reset-password">{t('reset.newPassword')}</label>
|
||||
<input
|
||||
id="reset-password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
disabled={loading}
|
||||
minLength={8}
|
||||
placeholder="········"
|
||||
/>
|
||||
</div>
|
||||
<div className="reset-field">
|
||||
<label htmlFor="reset-confirm">{t('reset.confirmPassword')}</label>
|
||||
<input
|
||||
id="reset-confirm"
|
||||
type="password"
|
||||
value={confirm}
|
||||
onChange={e => setConfirm(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
disabled={loading}
|
||||
minLength={8}
|
||||
placeholder="········"
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="reset-error">{error}</p>}
|
||||
<button
|
||||
type="submit"
|
||||
className="reset-btn"
|
||||
disabled={loading || !password || !confirm}
|
||||
>
|
||||
{loading ? t('reset.saving') : t('reset.saveBtn')}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ResetPasswordView;
|
||||
Reference in New Issue
Block a user