vona-module-a-mailconfirm 5.0.1
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/LICENSE +21 -0
- package/dist/.metadata/index.d.ts +176 -0
- package/dist/.metadata/this.d.ts +2 -0
- package/dist/bean/cacheRedis.emailConfirm.d.ts +9 -0
- package/dist/bean/cacheRedis.passwordReset.d.ts +8 -0
- package/dist/bean/event.emailConfirmCallback.d.ts +6 -0
- package/dist/bean/event.passwordResetCallback.d.ts +6 -0
- package/dist/config/locale/en-us.d.ts +7 -0
- package/dist/config/locale/mail/en-us.d.ts +4 -0
- package/dist/config/locale/mail/zh-cn.d.ts +4 -0
- package/dist/config/locale/zh-cn.d.ts +7 -0
- package/dist/controller/mail.d.ts +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +232 -0
- package/dist/service/mail.d.ts +6 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present Vona
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { TypeControllerOptionsActions } from 'vona-module-a-openapi';
|
|
2
|
+
/** service: begin */
|
|
3
|
+
export * from '../service/mail.ts';
|
|
4
|
+
import 'vona';
|
|
5
|
+
declare module 'vona-module-a-bean' {
|
|
6
|
+
interface IServiceRecord {
|
|
7
|
+
'a-mailconfirm:mail': never;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare module 'vona-module-a-mailconfirm' {
|
|
11
|
+
interface ServiceMail {
|
|
12
|
+
}
|
|
13
|
+
interface ServiceMail {
|
|
14
|
+
get $beanFullName(): 'a-mailconfirm.service.mail';
|
|
15
|
+
get $onionName(): 'a-mailconfirm:mail';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** service: end */
|
|
19
|
+
/** service: begin */
|
|
20
|
+
import type { ServiceMail } from '../service/mail.ts';
|
|
21
|
+
export interface IModuleService {
|
|
22
|
+
'mail': ServiceMail;
|
|
23
|
+
}
|
|
24
|
+
/** service: end */
|
|
25
|
+
/** service: begin */
|
|
26
|
+
import 'vona';
|
|
27
|
+
declare module 'vona' {
|
|
28
|
+
interface IBeanRecordGeneral {
|
|
29
|
+
'a-mailconfirm.service.mail': ServiceMail;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** service: end */
|
|
33
|
+
/** cacheRedis: begin */
|
|
34
|
+
export * from '../bean/cacheRedis.emailConfirm.ts';
|
|
35
|
+
export * from '../bean/cacheRedis.passwordReset.ts';
|
|
36
|
+
import { type IDecoratorCacheRedisOptions } from 'vona-module-a-cache';
|
|
37
|
+
declare module 'vona-module-a-cache' {
|
|
38
|
+
interface ICacheRedisRecord {
|
|
39
|
+
'a-mailconfirm:emailConfirm': IDecoratorCacheRedisOptions;
|
|
40
|
+
'a-mailconfirm:passwordReset': IDecoratorCacheRedisOptions;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
declare module 'vona-module-a-mailconfirm' {
|
|
44
|
+
interface CacheRedisEmailConfirm {
|
|
45
|
+
}
|
|
46
|
+
interface CacheRedisEmailConfirm {
|
|
47
|
+
get $beanFullName(): 'a-mailconfirm.cacheRedis.emailConfirm';
|
|
48
|
+
get $onionName(): 'a-mailconfirm:emailConfirm';
|
|
49
|
+
}
|
|
50
|
+
interface CacheRedisPasswordReset {
|
|
51
|
+
}
|
|
52
|
+
interface CacheRedisPasswordReset {
|
|
53
|
+
get $beanFullName(): 'a-mailconfirm.cacheRedis.passwordReset';
|
|
54
|
+
get $onionName(): 'a-mailconfirm:passwordReset';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** cacheRedis: end */
|
|
58
|
+
/** cacheRedis: begin */
|
|
59
|
+
import type { CacheRedisEmailConfirm } from '../bean/cacheRedis.emailConfirm.ts';
|
|
60
|
+
import type { CacheRedisPasswordReset } from '../bean/cacheRedis.passwordReset.ts';
|
|
61
|
+
export interface IModuleCacheRedis {
|
|
62
|
+
'emailConfirm': CacheRedisEmailConfirm;
|
|
63
|
+
'passwordReset': CacheRedisPasswordReset;
|
|
64
|
+
}
|
|
65
|
+
/** cacheRedis: end */
|
|
66
|
+
/** event: begin */
|
|
67
|
+
export * from '../bean/event.emailConfirmCallback.ts';
|
|
68
|
+
export * from '../bean/event.passwordResetCallback.ts';
|
|
69
|
+
import 'vona';
|
|
70
|
+
declare module 'vona' {
|
|
71
|
+
}
|
|
72
|
+
declare module 'vona-module-a-mailconfirm' {
|
|
73
|
+
interface EventEmailConfirmCallback {
|
|
74
|
+
}
|
|
75
|
+
interface EventEmailConfirmCallback {
|
|
76
|
+
get $beanFullName(): 'a-mailconfirm.event.emailConfirmCallback';
|
|
77
|
+
get $onionName(): 'a-mailconfirm:emailConfirmCallback';
|
|
78
|
+
}
|
|
79
|
+
interface EventPasswordResetCallback {
|
|
80
|
+
}
|
|
81
|
+
interface EventPasswordResetCallback {
|
|
82
|
+
get $beanFullName(): 'a-mailconfirm.event.passwordResetCallback';
|
|
83
|
+
get $onionName(): 'a-mailconfirm:passwordResetCallback';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** event: end */
|
|
87
|
+
/** event: begin */
|
|
88
|
+
import type { EventEmailConfirmCallback } from '../bean/event.emailConfirmCallback.ts';
|
|
89
|
+
import type { EventPasswordResetCallback } from '../bean/event.passwordResetCallback.ts';
|
|
90
|
+
export interface IModuleEvent {
|
|
91
|
+
'emailConfirmCallback': EventEmailConfirmCallback;
|
|
92
|
+
'passwordResetCallback': EventPasswordResetCallback;
|
|
93
|
+
}
|
|
94
|
+
/** event: end */
|
|
95
|
+
/** event: begin */
|
|
96
|
+
import type { TypeEventEmailConfirmCallbackData, TypeEventEmailConfirmCallbackResult } from '../bean/event.emailConfirmCallback.ts';
|
|
97
|
+
import type { TypeEventPasswordResetCallbackData, TypeEventPasswordResetCallbackResult } from '../bean/event.passwordResetCallback.ts';
|
|
98
|
+
import type { EventOn } from 'vona-module-a-event';
|
|
99
|
+
declare module 'vona-module-a-event' {
|
|
100
|
+
interface IEventRecord {
|
|
101
|
+
'a-mailconfirm:emailConfirmCallback': EventOn<TypeEventEmailConfirmCallbackData, TypeEventEmailConfirmCallbackResult>;
|
|
102
|
+
'a-mailconfirm:passwordResetCallback': EventOn<TypeEventPasswordResetCallbackData, TypeEventPasswordResetCallbackResult>;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** event: end */
|
|
106
|
+
/** controller: begin */
|
|
107
|
+
export * from '../controller/mail.ts';
|
|
108
|
+
import type { IControllerOptionsMail } from '../controller/mail.ts';
|
|
109
|
+
import 'vona';
|
|
110
|
+
declare module 'vona-module-a-web' {
|
|
111
|
+
interface IControllerRecord {
|
|
112
|
+
'a-mailconfirm:mail': IControllerOptionsMail;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
declare module 'vona-module-a-mailconfirm' {
|
|
116
|
+
interface ControllerMail {
|
|
117
|
+
}
|
|
118
|
+
interface ControllerMail {
|
|
119
|
+
get $beanFullName(): 'a-mailconfirm.controller.mail';
|
|
120
|
+
get $onionName(): 'a-mailconfirm:mail';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** controller: end */
|
|
124
|
+
/** controller: begin */
|
|
125
|
+
import '../controller/mail.ts';
|
|
126
|
+
declare module 'vona-module-a-mailconfirm' {
|
|
127
|
+
interface IControllerOptionsMail {
|
|
128
|
+
actions?: TypeControllerOptionsActions<ControllerMail>;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
declare module 'vona-module-a-web' {
|
|
132
|
+
interface IApiPathGetRecord {
|
|
133
|
+
'/mailconfirm/mail/emailConfirmCallback': undefined;
|
|
134
|
+
'/mailconfirm/mail/passwordResetCallback': undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export declare const locales: {
|
|
138
|
+
'en-us': {
|
|
139
|
+
ConfirmationEmailSubject: string;
|
|
140
|
+
ConfirmationEmailBody: string;
|
|
141
|
+
PasswordResetEmailSubject: string;
|
|
142
|
+
PasswordResetEmailBody: string;
|
|
143
|
+
};
|
|
144
|
+
'zh-cn': {
|
|
145
|
+
ConfirmationEmailSubject: string;
|
|
146
|
+
ConfirmationEmailBody: string;
|
|
147
|
+
PasswordResetEmailSubject: string;
|
|
148
|
+
PasswordResetEmailBody: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
/** locale: end */
|
|
152
|
+
/** scope: begin */
|
|
153
|
+
import { BeanScopeBase, type BeanScopeUtil, type TypeModuleLocales, type TypeLocaleBase } from 'vona';
|
|
154
|
+
export declare class ScopeModuleAMailconfirm extends BeanScopeBase {
|
|
155
|
+
}
|
|
156
|
+
export interface ScopeModuleAMailconfirm {
|
|
157
|
+
util: BeanScopeUtil;
|
|
158
|
+
locale: TypeModuleLocales<(typeof locales)[TypeLocaleBase]>;
|
|
159
|
+
service: IModuleService;
|
|
160
|
+
cacheRedis: IModuleCacheRedis;
|
|
161
|
+
event: IModuleEvent;
|
|
162
|
+
}
|
|
163
|
+
import 'vona';
|
|
164
|
+
declare module 'vona' {
|
|
165
|
+
interface IBeanScopeRecord {
|
|
166
|
+
'a-mailconfirm': ScopeModuleAMailconfirm;
|
|
167
|
+
}
|
|
168
|
+
interface IBeanScopeContainer {
|
|
169
|
+
mailconfirm: ScopeModuleAMailconfirm;
|
|
170
|
+
}
|
|
171
|
+
interface IBeanScopeLocale {
|
|
172
|
+
'a-mailconfirm': (typeof locales)[TypeLocaleBase];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `a-mailconfirm::${K}`;
|
|
176
|
+
/** scope: end */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import { BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
3
|
+
export type TCacheRedisEmailConfirmKey = string;
|
|
4
|
+
export interface TCacheRedisEmailConfirmData {
|
|
5
|
+
userId: TableIdentity;
|
|
6
|
+
email: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CacheRedisEmailConfirm extends BeanCacheRedisBase<TCacheRedisEmailConfirmKey, TCacheRedisEmailConfirmData> {
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import { BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
3
|
+
export type TCacheRedisPasswordResetKey = string;
|
|
4
|
+
export interface TCacheRedisPasswordResetData {
|
|
5
|
+
userId: TableIdentity;
|
|
6
|
+
}
|
|
7
|
+
export declare class CacheRedisPasswordReset extends BeanCacheRedisBase<TCacheRedisPasswordResetKey, TCacheRedisPasswordResetData> {
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TCacheRedisEmailConfirmData } from './cacheRedis.emailConfirm.ts';
|
|
2
|
+
import { BeanEventBase } from 'vona-module-a-event';
|
|
3
|
+
export type TypeEventEmailConfirmCallbackData = TCacheRedisEmailConfirmData | null | undefined;
|
|
4
|
+
export type TypeEventEmailConfirmCallbackResult = string;
|
|
5
|
+
export declare class EventEmailConfirmCallback extends BeanEventBase<TypeEventEmailConfirmCallbackData, TypeEventEmailConfirmCallbackResult> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TCacheRedisPasswordResetData } from './cacheRedis.passwordReset.ts';
|
|
2
|
+
import { BeanEventBase } from 'vona-module-a-event';
|
|
3
|
+
export type TypeEventPasswordResetCallbackData = TCacheRedisPasswordResetData | null | undefined;
|
|
4
|
+
export type TypeEventPasswordResetCallbackResult = string;
|
|
5
|
+
export declare class EventPasswordResetCallback extends BeanEventBase<TypeEventPasswordResetCallbackData, TypeEventPasswordResetCallbackResult> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const ConfirmationEmailSubject = "[{{siteName}}] Account Confirmation";
|
|
2
|
+
export declare const ConfirmationEmailBody = "\nHi {{userName}},\n\nWelcome to join us. Please click this link to confirm your email:\n\n{{link}}\n\nRegards,\n{{siteName}} Team\n";
|
|
3
|
+
export declare const PasswordResetEmailSubject = "[{{siteName}}] Password Reset";
|
|
4
|
+
export declare const PasswordResetEmailBody = "\nHi {{userName}},\n\nTo reset your password, visit the following address:\n\n{{link}}\n\nRegards,\n{{siteName}} Team\n";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const ConfirmationEmailSubject = "[{{siteName}}] \u8D26\u53F7\u786E\u8BA4";
|
|
2
|
+
export declare const ConfirmationEmailBody = "\n\u60A8\u597D\uFF0C{{userName}}\uFF0C\n\n\u6B22\u8FCE\u52A0\u5165\u6211\u4EEC\u3002\u8BF7\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u9A8C\u8BC1\u60A8\u7684\u90AE\u4EF6\uFF1A\n\n{{link}}\n\n\u6B64\u81F4\uFF0C\n{{siteName}} \u56E2\u961F\n";
|
|
3
|
+
export declare const PasswordResetEmailSubject = "[{{siteName}}] \u91CD\u7F6E\u5BC6\u7801";
|
|
4
|
+
export declare const PasswordResetEmailBody = "\n\u60A8\u597D\uFF0C{{userName}}\uFF0C\n\n\u8BF7\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u91CD\u7F6E\u5BC6\u7801\uFF1A\n\n{{link}}\n\n\u6B64\u81F4\uFF0C\n{{siteName}} \u56E2\u961F\n";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorControllerOptions } from 'vona-module-a-web';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
export interface IControllerOptionsMail extends IDecoratorControllerOptions {
|
|
4
|
+
}
|
|
5
|
+
export declare class ControllerMail extends BeanBase {
|
|
6
|
+
emailConfirmCallback(token: string): Promise<string>;
|
|
7
|
+
passwordResetCallback(token: string): Promise<string>;
|
|
8
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './.metadata/index.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { BeanInfo, BeanBase, uuidv4, BeanScopeBase } from 'vona';
|
|
2
|
+
import { combineQueries, replaceTemplate } from '@cabloy/utils';
|
|
3
|
+
import { Service, Scope } from 'vona-module-a-bean';
|
|
4
|
+
import { $getUserEmail, $getUserName, Passport } from 'vona-module-a-user';
|
|
5
|
+
import { $apiPath, Controller, Web, Arg } from 'vona-module-a-web';
|
|
6
|
+
import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
7
|
+
import { Event, BeanEventBase } from 'vona-module-a-event';
|
|
8
|
+
|
|
9
|
+
var _dec$6, _dec2$6, _class$6;
|
|
10
|
+
let ServiceMail = (_dec$6 = Service(), _dec2$6 = BeanInfo({
|
|
11
|
+
module: "a-mailconfirm"
|
|
12
|
+
}), _dec$6(_class$6 = _dec2$6(_class$6 = class ServiceMail extends BeanBase {
|
|
13
|
+
async emailConfirm(user) {
|
|
14
|
+
const userId = user.id;
|
|
15
|
+
const email = $getUserEmail(user);
|
|
16
|
+
if (!email) throw new Error(`email should not empty: ${$getUserName(user)}`);
|
|
17
|
+
// link
|
|
18
|
+
const token = uuidv4();
|
|
19
|
+
const callbackURLRelative = $apiPath('/mailconfirm/mail/emailConfirmCallback');
|
|
20
|
+
const callbackURL = this.app.util.getAbsoluteUrlByApiPath(callbackURLRelative);
|
|
21
|
+
const link = combineQueries(callbackURL, {
|
|
22
|
+
token
|
|
23
|
+
});
|
|
24
|
+
// siteName
|
|
25
|
+
const siteName = this.ctx.instance.title || this.app.meta.env.APP_TITLE;
|
|
26
|
+
// email: subject
|
|
27
|
+
const subject = replaceTemplate(this.scope.locale.ConfirmationEmailSubject(), {
|
|
28
|
+
siteName
|
|
29
|
+
});
|
|
30
|
+
// email: body
|
|
31
|
+
const body = replaceTemplate(this.scope.locale.ConfirmationEmailBody(), {
|
|
32
|
+
userName: $getUserName(user),
|
|
33
|
+
link,
|
|
34
|
+
siteName
|
|
35
|
+
});
|
|
36
|
+
// send
|
|
37
|
+
await this.bean.mail.send({
|
|
38
|
+
to: email,
|
|
39
|
+
subject,
|
|
40
|
+
text: body
|
|
41
|
+
});
|
|
42
|
+
// save
|
|
43
|
+
await this.scope.cacheRedis.emailConfirm.set({
|
|
44
|
+
userId,
|
|
45
|
+
email
|
|
46
|
+
}, token);
|
|
47
|
+
}
|
|
48
|
+
async passwordReset(user) {
|
|
49
|
+
const userId = user.id;
|
|
50
|
+
const email = $getUserEmail(user);
|
|
51
|
+
if (!email) throw new Error(`email should not empty: ${$getUserName(user)}`);
|
|
52
|
+
// link
|
|
53
|
+
const token = uuidv4();
|
|
54
|
+
const callbackURLRelative = $apiPath('/mailconfirm/mail/passwordResetCallback');
|
|
55
|
+
const callbackURL = this.app.util.getAbsoluteUrlByApiPath(callbackURLRelative);
|
|
56
|
+
const link = combineQueries(callbackURL, {
|
|
57
|
+
token
|
|
58
|
+
});
|
|
59
|
+
// siteName
|
|
60
|
+
const siteName = this.ctx.instance.title || this.app.meta.env.APP_TITLE;
|
|
61
|
+
// email: subject
|
|
62
|
+
const subject = replaceTemplate(this.scope.locale.PasswordResetEmailSubject(), {
|
|
63
|
+
siteName
|
|
64
|
+
});
|
|
65
|
+
// email: body
|
|
66
|
+
const body = replaceTemplate(this.scope.locale.PasswordResetEmailBody(), {
|
|
67
|
+
userName: $getUserName(user),
|
|
68
|
+
link,
|
|
69
|
+
siteName
|
|
70
|
+
});
|
|
71
|
+
// send
|
|
72
|
+
await this.bean.mail.send({
|
|
73
|
+
to: email,
|
|
74
|
+
subject,
|
|
75
|
+
text: body
|
|
76
|
+
});
|
|
77
|
+
// save
|
|
78
|
+
await this.scope.cacheRedis.passwordReset.set({
|
|
79
|
+
userId
|
|
80
|
+
}, token);
|
|
81
|
+
}
|
|
82
|
+
}) || _class$6) || _class$6);
|
|
83
|
+
|
|
84
|
+
var _dec$5, _dec2$5, _class$5;
|
|
85
|
+
let CacheRedisEmailConfirm = (_dec$5 = CacheRedis({
|
|
86
|
+
ttl: 30 * 60 * 1000 // 30 minutes
|
|
87
|
+
}), _dec2$5 = BeanInfo({
|
|
88
|
+
module: "a-mailconfirm"
|
|
89
|
+
}), _dec$5(_class$5 = _dec2$5(_class$5 = class CacheRedisEmailConfirm extends BeanCacheRedisBase {}) || _class$5) || _class$5);
|
|
90
|
+
|
|
91
|
+
var _dec$4, _dec2$4, _class$4;
|
|
92
|
+
let CacheRedisPasswordReset = (_dec$4 = CacheRedis({
|
|
93
|
+
ttl: 30 * 60 * 1000 // 30 minutes
|
|
94
|
+
}), _dec2$4 = BeanInfo({
|
|
95
|
+
module: "a-mailconfirm"
|
|
96
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class CacheRedisPasswordReset extends BeanCacheRedisBase {}) || _class$4) || _class$4);
|
|
97
|
+
|
|
98
|
+
var _dec$3, _dec2$3, _class$3;
|
|
99
|
+
let EventEmailConfirmCallback = (_dec$3 = Event(), _dec2$3 = BeanInfo({
|
|
100
|
+
module: "a-mailconfirm"
|
|
101
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class EventEmailConfirmCallback extends BeanEventBase {}) || _class$3) || _class$3);
|
|
102
|
+
|
|
103
|
+
var _dec$2, _dec2$2, _class$2;
|
|
104
|
+
let EventPasswordResetCallback = (_dec$2 = Event(), _dec2$2 = BeanInfo({
|
|
105
|
+
module: "a-mailconfirm"
|
|
106
|
+
}), _dec$2(_class$2 = _dec2$2(_class$2 = class EventPasswordResetCallback extends BeanEventBase {}) || _class$2) || _class$2);
|
|
107
|
+
|
|
108
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) {
|
|
109
|
+
var a = {};
|
|
110
|
+
return Object.keys(n).forEach(function (i) {
|
|
111
|
+
a[i] = n[i];
|
|
112
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
|
|
113
|
+
return n(i, e, r) || r;
|
|
114
|
+
}, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var _dec$1, _dec2$1, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _dec1, _dec10, _class$1, _class2;
|
|
118
|
+
let ControllerMail = (_dec$1 = Controller('mail'), _dec2$1 = BeanInfo({
|
|
119
|
+
module: "a-mailconfirm"
|
|
120
|
+
}), _dec3 = Web.get('emailConfirmCallback'), _dec4 = Passport.public(), _dec5 = function (target, key) {
|
|
121
|
+
return Arg.query('token')(target, key, 0);
|
|
122
|
+
}, _dec6 = Reflect.metadata("design:type", Function), _dec7 = Reflect.metadata("design:paramtypes", [String]), _dec8 = Web.get('passwordResetCallback'), _dec9 = Passport.public(), _dec0 = function (target, key) {
|
|
123
|
+
return Arg.query('token')(target, key, 0);
|
|
124
|
+
}, _dec1 = Reflect.metadata("design:type", Function), _dec10 = Reflect.metadata("design:paramtypes", [String]), _dec$1(_class$1 = _dec2$1(_class$1 = (_class2 = class ControllerMail extends BeanBase {
|
|
125
|
+
async emailConfirmCallback(token) {
|
|
126
|
+
// cache
|
|
127
|
+
const data = await this.scope.cacheRedis.emailConfirm.get(token);
|
|
128
|
+
if (data) {
|
|
129
|
+
await this.scope.cacheRedis.emailConfirm.del(token);
|
|
130
|
+
}
|
|
131
|
+
// emit
|
|
132
|
+
return await this.scope.event.emailConfirmCallback.emit(data);
|
|
133
|
+
}
|
|
134
|
+
async passwordResetCallback(token) {
|
|
135
|
+
// cache
|
|
136
|
+
const data = await this.scope.cacheRedis.passwordReset.get(token);
|
|
137
|
+
if (data) {
|
|
138
|
+
await this.scope.cacheRedis.passwordReset.del(token);
|
|
139
|
+
}
|
|
140
|
+
// emit
|
|
141
|
+
return await this.scope.event.passwordResetCallback.emit(data);
|
|
142
|
+
}
|
|
143
|
+
}, _applyDecoratedDescriptor(_class2.prototype, "emailConfirmCallback", [_dec3, _dec4, _dec5, _dec6, _dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "emailConfirmCallback"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "passwordResetCallback", [_dec8, _dec9, _dec0, _dec1, _dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "passwordResetCallback"), _class2.prototype), _class2)) || _class$1) || _class$1);
|
|
144
|
+
|
|
145
|
+
// confirmationEmail
|
|
146
|
+
// subject
|
|
147
|
+
const ConfirmationEmailSubject$1 = '[{{siteName}}] Account Confirmation';
|
|
148
|
+
// body
|
|
149
|
+
const ConfirmationEmailBody$1 = `
|
|
150
|
+
Hi {{userName}},
|
|
151
|
+
|
|
152
|
+
Welcome to join us. Please click this link to confirm your email:
|
|
153
|
+
|
|
154
|
+
{{link}}
|
|
155
|
+
|
|
156
|
+
Regards,
|
|
157
|
+
{{siteName}} Team
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
// passwordResetEmail
|
|
161
|
+
// subject
|
|
162
|
+
const PasswordResetEmailSubject$1 = '[{{siteName}}] Password Reset';
|
|
163
|
+
// body
|
|
164
|
+
const PasswordResetEmailBody$1 = `
|
|
165
|
+
Hi {{userName}},
|
|
166
|
+
|
|
167
|
+
To reset your password, visit the following address:
|
|
168
|
+
|
|
169
|
+
{{link}}
|
|
170
|
+
|
|
171
|
+
Regards,
|
|
172
|
+
{{siteName}} Team
|
|
173
|
+
`;
|
|
174
|
+
|
|
175
|
+
var locale_en_us = {
|
|
176
|
+
ConfirmationEmailSubject: ConfirmationEmailSubject$1,
|
|
177
|
+
ConfirmationEmailBody: ConfirmationEmailBody$1,
|
|
178
|
+
PasswordResetEmailSubject: PasswordResetEmailSubject$1,
|
|
179
|
+
PasswordResetEmailBody: PasswordResetEmailBody$1
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// confirmationEmail
|
|
183
|
+
// subject
|
|
184
|
+
const ConfirmationEmailSubject = '[{{siteName}}] 账号确认';
|
|
185
|
+
// body
|
|
186
|
+
const ConfirmationEmailBody = `
|
|
187
|
+
您好,{{userName}},
|
|
188
|
+
|
|
189
|
+
欢迎加入我们。请点击以下链接验证您的邮件:
|
|
190
|
+
|
|
191
|
+
{{link}}
|
|
192
|
+
|
|
193
|
+
此致,
|
|
194
|
+
{{siteName}} 团队
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
// passwordResetEmail
|
|
198
|
+
// subject
|
|
199
|
+
const PasswordResetEmailSubject = '[{{siteName}}] 重置密码';
|
|
200
|
+
// body
|
|
201
|
+
const PasswordResetEmailBody = `
|
|
202
|
+
您好,{{userName}},
|
|
203
|
+
|
|
204
|
+
请点击以下链接重置密码:
|
|
205
|
+
|
|
206
|
+
{{link}}
|
|
207
|
+
|
|
208
|
+
此致,
|
|
209
|
+
{{siteName}} 团队
|
|
210
|
+
`;
|
|
211
|
+
|
|
212
|
+
var locale_zh_cn = {
|
|
213
|
+
ConfirmationEmailSubject,
|
|
214
|
+
ConfirmationEmailBody,
|
|
215
|
+
PasswordResetEmailSubject,
|
|
216
|
+
PasswordResetEmailBody
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
var _dec, _dec2, _class;
|
|
220
|
+
const locales = {
|
|
221
|
+
'en-us': locale_en_us,
|
|
222
|
+
'zh-cn': locale_zh_cn
|
|
223
|
+
};
|
|
224
|
+
let ScopeModuleAMailconfirm = (_dec = Scope(), _dec2 = BeanInfo({
|
|
225
|
+
module: "a-mailconfirm"
|
|
226
|
+
}), _dec(_class = _dec2(_class = class ScopeModuleAMailconfirm extends BeanScopeBase {}) || _class) || _class);
|
|
227
|
+
function $locale(key) {
|
|
228
|
+
return `a-mailconfirm::${key}`;
|
|
229
|
+
}
|
|
230
|
+
/** scope: end */
|
|
231
|
+
|
|
232
|
+
export { $locale, CacheRedisEmailConfirm, CacheRedisPasswordReset, ControllerMail, EventEmailConfirmCallback, EventPasswordResetCallback, ScopeModuleAMailconfirm, ServiceMail, locales };
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vona-module-a-mailconfirm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "5.0.1",
|
|
5
|
+
"title": "a-mailconfirm",
|
|
6
|
+
"vonaModule": {
|
|
7
|
+
"dependencies": {}
|
|
8
|
+
},
|
|
9
|
+
"description": "",
|
|
10
|
+
"author": "",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"Vona Module"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": [
|
|
17
|
+
"./src/index.ts",
|
|
18
|
+
"./dist/index.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"static"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
30
|
+
"tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
|
|
31
|
+
}
|
|
32
|
+
}
|