@midwayjs/captcha 3.14.0 → 3.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.default.d.ts +11 -1
- package/dist/config/config.default.js +21 -13
- package/dist/configuration.js +1 -1
- package/dist/service.d.ts +3 -3
- package/dist/service.js +7 -7
- package/package.json +6 -6
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { CaptchaOptions } from '../interface';
|
|
2
|
-
|
|
2
|
+
declare const _default: {
|
|
3
|
+
captcha: CaptchaOptions;
|
|
4
|
+
cacheManager: {
|
|
5
|
+
clients: {
|
|
6
|
+
captcha: {
|
|
7
|
+
store: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
3
13
|
//# sourceMappingURL=config.default.d.ts.map
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
exports.default = {
|
|
4
|
+
captcha: {
|
|
5
|
+
default: {
|
|
6
|
+
size: 4,
|
|
7
|
+
noise: 1,
|
|
8
|
+
width: 120,
|
|
9
|
+
height: 40,
|
|
10
|
+
},
|
|
11
|
+
image: {
|
|
12
|
+
type: 'mixed',
|
|
13
|
+
},
|
|
14
|
+
formula: {},
|
|
15
|
+
text: {},
|
|
16
|
+
expirationTime: 3600,
|
|
17
|
+
idPrefix: 'midway:vc',
|
|
10
18
|
},
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
cacheManager: {
|
|
20
|
+
clients: {
|
|
21
|
+
captcha: {
|
|
22
|
+
store: 'memory',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
13
25
|
},
|
|
14
|
-
formula: {},
|
|
15
|
-
text: {},
|
|
16
|
-
expirationTime: 3600,
|
|
17
|
-
idPrefix: 'midway:vc',
|
|
18
26
|
};
|
|
19
27
|
//# sourceMappingURL=config.default.js.map
|
package/dist/configuration.js
CHANGED
|
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.CaptchaConfiguration = void 0;
|
|
10
10
|
const core_1 = require("@midwayjs/core");
|
|
11
|
-
const cacheComponent = require("@midwayjs/cache");
|
|
11
|
+
const cacheComponent = require("@midwayjs/cache-manager");
|
|
12
12
|
const DefaultConfig = require("./config/config.default");
|
|
13
13
|
let CaptchaConfiguration = class CaptchaConfiguration {
|
|
14
14
|
};
|
package/dist/service.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MidwayCache } from '@midwayjs/cache-manager';
|
|
2
2
|
import { FormulaCaptchaOptions, ImageCaptchaOptions, TextCaptchaOptions, CaptchaOptions } from './interface';
|
|
3
3
|
export declare class CaptchaService {
|
|
4
|
-
|
|
5
|
-
captcha: CaptchaOptions;
|
|
4
|
+
protected captchaCaching: MidwayCache;
|
|
5
|
+
protected captcha: CaptchaOptions;
|
|
6
6
|
image(options?: ImageCaptchaOptions): Promise<{
|
|
7
7
|
id: string;
|
|
8
8
|
imageBase64: string;
|
package/dist/service.js
CHANGED
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CaptchaService = void 0;
|
|
13
13
|
const core_1 = require("@midwayjs/core");
|
|
14
|
-
const
|
|
14
|
+
const cache_manager_1 = require("@midwayjs/cache-manager");
|
|
15
15
|
const svgCaptcha = require("svg-captcha");
|
|
16
16
|
const svgBase64 = require("mini-svg-data-uri");
|
|
17
17
|
const nanoid_1 = require("nanoid");
|
|
@@ -73,7 +73,7 @@ let CaptchaService = class CaptchaService {
|
|
|
73
73
|
}
|
|
74
74
|
async set(text) {
|
|
75
75
|
const id = (0, nanoid_1.nanoid)();
|
|
76
|
-
await this.
|
|
76
|
+
await this.captchaCaching.set(this.getStoreId(id), (text || '').toLowerCase(), this.captcha.expirationTime * 1000);
|
|
77
77
|
return id;
|
|
78
78
|
}
|
|
79
79
|
async check(id, value) {
|
|
@@ -81,11 +81,11 @@ let CaptchaService = class CaptchaService {
|
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
83
|
const storeId = this.getStoreId(id);
|
|
84
|
-
const storedValue = await this.
|
|
84
|
+
const storedValue = await this.captchaCaching.get(storeId);
|
|
85
85
|
if (value.toLowerCase() !== storedValue) {
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
-
this.
|
|
88
|
+
await this.captchaCaching.del(storeId);
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
getStoreId(id) {
|
|
@@ -96,9 +96,9 @@ let CaptchaService = class CaptchaService {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
__decorate([
|
|
99
|
-
(0, core_1.
|
|
100
|
-
__metadata("design:type",
|
|
101
|
-
], CaptchaService.prototype, "
|
|
99
|
+
(0, core_1.InjectClient)(cache_manager_1.CachingFactory, 'captcha'),
|
|
100
|
+
__metadata("design:type", Object)
|
|
101
|
+
], CaptchaService.prototype, "captchaCaching", void 0);
|
|
102
102
|
__decorate([
|
|
103
103
|
(0, core_1.Config)('captcha'),
|
|
104
104
|
__metadata("design:type", Object)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/captcha",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.4",
|
|
4
4
|
"description": "Midway Component for Captcha(Verification Code)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@midwayjs/cache": "^3.14.
|
|
25
|
+
"@midwayjs/cache-manager": "^3.14.4",
|
|
26
26
|
"mini-svg-data-uri": "1.4.4",
|
|
27
27
|
"nanoid": "3.3.7",
|
|
28
28
|
"svg-captcha": "1.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@midwayjs/core": "^3.14.
|
|
32
|
-
"@midwayjs/koa": "^3.14.
|
|
33
|
-
"@midwayjs/mock": "^3.14.
|
|
31
|
+
"@midwayjs/core": "^3.14.4",
|
|
32
|
+
"@midwayjs/koa": "^3.14.4",
|
|
33
|
+
"@midwayjs/mock": "^3.14.4"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "72aacdfd87ef730f100690557de48dcbd4d806a7"
|
|
36
36
|
}
|