create-warlock 1.0.6 → 1.0.8
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/package.json +1 -1
- package/templates/warlock/package.json +1 -1
- package/templates/warlock/src/app/users/controllers/auth/activate-account.ts +49 -48
- package/templates/warlock/src/app/users/controllers/auth/forget-password.ts +39 -39
- package/templates/warlock/src/app/users/repositories/users-repository.ts +29 -28
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@warlock.js/auth": "^1.0.2",
|
|
30
30
|
"@warlock.js/cache": "^1.1.0",
|
|
31
31
|
"@warlock.js/cascade": "^1.0.4",
|
|
32
|
-
"@warlock.js/core": "^1.0.
|
|
32
|
+
"@warlock.js/core": "^1.0.19",
|
|
33
33
|
"@warlock.js/logger": "^1.0.6",
|
|
34
34
|
"@warlock.js/postman": "^1.0.2",
|
|
35
35
|
"dayjs": "^1.11.10"
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import type { Request, Response } from "@warlock.js/core";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
1
|
+
import type { Request, Response } from "@warlock.js/core";
|
|
2
|
+
import usersRepository from "app/users/repositories/users-repository";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default async function activateAccount(
|
|
6
|
+
request: Request,
|
|
7
|
+
response: Response,
|
|
8
|
+
) {
|
|
9
|
+
const currentUser = request.user;
|
|
10
|
+
|
|
11
|
+
currentUser.unset("codeExpiresAt", "activationCode");
|
|
12
|
+
|
|
13
|
+
currentUser.save({
|
|
14
|
+
isActive: true,
|
|
15
|
+
activatedAt: new Date(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const accessToken = await currentUser.generateAccessToken();
|
|
19
|
+
|
|
20
|
+
return response.success({
|
|
21
|
+
user: {
|
|
22
|
+
...(await currentUser.toJSON()),
|
|
23
|
+
accessToken: accessToken,
|
|
24
|
+
userType: currentUser.userType,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
activateAccount.validation = {
|
|
30
|
+
rules: {
|
|
31
|
+
code: ["required"],
|
|
32
|
+
email: ["required", "email"],
|
|
33
|
+
},
|
|
34
|
+
validate: async (request: Request, response: Response) => {
|
|
35
|
+
const user = await usersRepository.first({
|
|
36
|
+
isActive: false,
|
|
37
|
+
email: request.input("email"),
|
|
38
|
+
activationCode: request.int("code"),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!user) {
|
|
42
|
+
return response.notFound({
|
|
43
|
+
error: "Invalid activation code",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
request.user = user;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { Random } from "@mongez/reinforcements";
|
|
2
|
-
import { UniqueRule, type Request, type Response } from "@warlock.js/core";
|
|
3
|
-
import sendForgetPasswordEmail from "app/users/mail/send-forget-password-email";
|
|
4
|
-
import { User } from "app/users/models/user";
|
|
5
|
-
|
|
6
|
-
export default async function forgetPassword(
|
|
7
|
-
request: Request<User>,
|
|
8
|
-
response: Response,
|
|
9
|
-
) {
|
|
10
|
-
const currentUser = request.user;
|
|
11
|
-
|
|
12
|
-
currentUser
|
|
13
|
-
.save({
|
|
14
|
-
activatedAt: new Date(),
|
|
15
|
-
activationCode: Random.int(100000, 999999),
|
|
16
|
-
})
|
|
17
|
-
.then(sendForgetPasswordEmail);
|
|
18
|
-
|
|
19
|
-
return response.success();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
forgetPassword.validation = {
|
|
23
|
-
rules: {
|
|
24
|
-
email: ["required", "email"
|
|
25
|
-
},
|
|
26
|
-
validate: async (request: Request, response: Response) => {
|
|
27
|
-
const user = await User.first({
|
|
28
|
-
email: request.input("email"),
|
|
29
|
-
// if the app requires an active account, uncomment the following line
|
|
30
|
-
// isActive: true,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (!user) {
|
|
34
|
-
return response.notFound();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
request.user = user;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
1
|
+
import { Random } from "@mongez/reinforcements";
|
|
2
|
+
import { UniqueRule, type Request, type Response } from "@warlock.js/core";
|
|
3
|
+
import sendForgetPasswordEmail from "app/users/mail/send-forget-password-email";
|
|
4
|
+
import { User } from "app/users/models/user";
|
|
5
|
+
|
|
6
|
+
export default async function forgetPassword(
|
|
7
|
+
request: Request<User>,
|
|
8
|
+
response: Response,
|
|
9
|
+
) {
|
|
10
|
+
const currentUser = request.user;
|
|
11
|
+
|
|
12
|
+
currentUser
|
|
13
|
+
.save({
|
|
14
|
+
activatedAt: new Date(),
|
|
15
|
+
activationCode: Random.int(100000, 999999),
|
|
16
|
+
})
|
|
17
|
+
.then(sendForgetPasswordEmail);
|
|
18
|
+
|
|
19
|
+
return response.success();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
forgetPassword.validation = {
|
|
23
|
+
rules: {
|
|
24
|
+
email: ["required", "email"],
|
|
25
|
+
},
|
|
26
|
+
validate: async (request: Request, response: Response) => {
|
|
27
|
+
const user = await User.first({
|
|
28
|
+
email: request.input("email"),
|
|
29
|
+
// if the app requires an active account, uncomment the following line
|
|
30
|
+
// isActive: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!user) {
|
|
34
|
+
return response.notFound();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
request.user = user;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import type { FilterByOptions, RepositoryOptions } from "@warlock.js/core";
|
|
2
|
-
import { RepositoryManager } from "@warlock.js/core";
|
|
3
|
-
|
|
4
|
-
import { User } from "../models/user";
|
|
5
|
-
|
|
6
|
-
export class UsersRepository extends RepositoryManager<User> {
|
|
7
|
-
/**
|
|
8
|
-
* {@inheritDoc}
|
|
9
|
-
*/
|
|
10
|
-
public model = User;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* List default options
|
|
14
|
-
*/
|
|
15
|
-
protected defaultOptions: RepositoryOptions = this.withDefaultOptions({});
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Filter By options
|
|
19
|
-
*/
|
|
20
|
-
protected filterBy: FilterByOptions = this.withDefaultFilters({
|
|
21
|
-
name: "like",
|
|
22
|
-
isActive: "bool",
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import type { FilterByOptions, RepositoryOptions } from "@warlock.js/core";
|
|
2
|
+
import { RepositoryManager } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
import { User } from "../models/user";
|
|
5
|
+
|
|
6
|
+
export class UsersRepository extends RepositoryManager<User> {
|
|
7
|
+
/**
|
|
8
|
+
* {@inheritDoc}
|
|
9
|
+
*/
|
|
10
|
+
public model = User;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* List default options
|
|
14
|
+
*/
|
|
15
|
+
protected defaultOptions: RepositoryOptions = this.withDefaultOptions({});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Filter By options
|
|
19
|
+
*/
|
|
20
|
+
protected filterBy: FilterByOptions = this.withDefaultFilters({
|
|
21
|
+
name: "like",
|
|
22
|
+
isActive: "bool",
|
|
23
|
+
activationCode: '='
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const usersRepository = new UsersRepository();
|
|
28
|
+
|
|
29
|
+
export default usersRepository;
|