mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-02-17 08:59:46 +03:00
add new site accepts duration
This commit is contained in:
parent
e83a362e75
commit
1e1ec187dc
6 changed files with 38 additions and 7 deletions
|
@ -34,7 +34,7 @@ pub mod routes {
|
|||
impl Docs {
|
||||
pub const fn new() -> Self {
|
||||
Docs {
|
||||
home: "/docs",
|
||||
home: "/docs/",
|
||||
spec: "/docs/openapi.json",
|
||||
assets: "/docs/{_:.*}",
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ pub struct IndexPage<'a> {
|
|||
pub levels: usize,
|
||||
pub form_title: &'a str,
|
||||
pub form_description: &'a str,
|
||||
pub form_duration: usize,
|
||||
}
|
||||
|
||||
const COMPONENT: &str = "Add Site Key";
|
||||
|
@ -40,6 +41,7 @@ impl<'a> Default for IndexPage<'a> {
|
|||
levels: 1,
|
||||
form_description: "",
|
||||
form_title: "Add Site Key",
|
||||
form_duration: 30,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,20 @@
|
|||
/>
|
||||
</label>
|
||||
|
||||
<label class="sitekey-form__label" for="duration">
|
||||
Cooldown Duratoin(in seconds)
|
||||
<input
|
||||
class="sitekey-form__input"
|
||||
type="number"
|
||||
name="duration"
|
||||
id="duration"
|
||||
min=0
|
||||
required
|
||||
value="<.= form_duration .>"
|
||||
/>
|
||||
</label>
|
||||
|
||||
|
||||
<. for level in 1..=levels { .>
|
||||
<. if level == levels { .>
|
||||
<. include!("./add-level.html"); .>
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import CONST from './const';
|
||||
import getNumLevels from './levels/getNumLevels';
|
||||
import {LEVELS} from './levels';
|
||||
|
||||
import isBlankString from '../../utils/isBlankString';
|
||||
import getFormUrl from '../../utils/getFormUrl';
|
||||
import genJsonPayload from '../../utils/genJsonPayload';
|
||||
import {LEVELS} from './levels';
|
||||
import isNumber from '../../utils/isNumber';
|
||||
|
||||
import VIEWS from '../../views/v1/routes';
|
||||
|
||||
|
@ -55,11 +55,24 @@ const validateDescription = (e: Event) => {
|
|||
isBlankString(val, filed, e);
|
||||
};
|
||||
|
||||
const validateDuration = (e: Event) => {
|
||||
const duartionElement = <HTMLInputElement>document.getElementById('duration');
|
||||
const duration = parseInt(duartionElement.value);
|
||||
if (!isNumber(duration) || Number.isNaN(duration)) {
|
||||
throw new Error('duration can contain nubers only');
|
||||
}
|
||||
|
||||
if (duration <= 0) {
|
||||
throw new Error('duration must be greater than zero');
|
||||
}
|
||||
return duration;
|
||||
};
|
||||
|
||||
const submit = async (e: Event) => {
|
||||
e.preventDefault();
|
||||
|
||||
validateDescription(e);
|
||||
// validateLevels(e);
|
||||
const duration = validateDuration(e);
|
||||
|
||||
const formUrl = getFormUrl(FORM);
|
||||
|
||||
|
@ -68,6 +81,7 @@ const submit = async (e: Event) => {
|
|||
|
||||
const payload = {
|
||||
levels: levels,
|
||||
duration,
|
||||
};
|
||||
|
||||
console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`);
|
||||
|
|
|
@ -34,11 +34,11 @@ const getLevelFields = (id: number) => {
|
|||
const visitor_threshold = parseInt(visitorElement.value);
|
||||
const difficulty_factor = parseInt(difficultyElement.value);
|
||||
|
||||
if (!isNumber(visitor_threshold) || Number.isNaN(visitor_threshold)) {
|
||||
if (Number.isNaN(visitor_threshold)) {
|
||||
throw new Error('visitor can contain nubers only');
|
||||
}
|
||||
|
||||
if (!isNumber(difficulty_factor) || Number.isNaN(difficulty_factor)) {
|
||||
if (Number.isNaN(difficulty_factor)) {
|
||||
throw new Error('difficulty can contain nubers only');
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ export const LEVELS = (function() {
|
|||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue