芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/app.optimyar.com/backend/api/captcha/services/captcha.js
'use strict'; let svgCaptcha = require('svg-captcha'); /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/services.html#core-services) * to customize this service */ module.exports = { async make(phoneNo = null) { let captcha = svgCaptcha.create({ size: 5, noise: 0, fontSize: 48, charPreset: '123456789', height: 64 }); const saved = await strapi.services.captcha.create({ relatedPhoneNo: phoneNo ? phoneNo.toString() : null, value: captcha.text, isValid: true }); return { id: saved.id, data: captcha.data, value: phoneNo ? captcha.text : null }; }, // sendToPhone(phoneNo) { // return new Promise(async (resolve, reject) => { // const result = await this.make(phoneNo); // // // }); // }, async isExist(captchaId, captcha, phoneNo = null) { const byId = await strapi.query('captcha').findOne({id: captchaId}); return byId.value === captcha && (phoneNo == null || byId.relatedPhoneNo === phoneNo.toString()); }, async isValid(captchaId, captcha, phoneNo = null) { const byId = await strapi.query('captcha').findOne({id: captchaId}); if (byId.value === captcha && byId.isValid && (phoneNo == null || byId.relatedPhoneNo === phoneNo.toString())) { let after5Min = byId.createdAt; after5Min.setMinutes(after5Min.getMinutes() + 2); if (after5Min >= new Date()) { await strapi.query('captcha').update({ id: captchaId }, { isValid: false }); return true; } } else { return false; } } };