@spinajs/rbac-http 1.2.211 → 2.0.15
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/lib/controllers/LoginController.d.ts +3 -3
- package/lib/controllers/LoginController.js +21 -23
- package/lib/controllers/LoginController.js.map +1 -1
- package/lib/controllers/UserAdminController.d.ts +0 -0
- package/lib/controllers/UserAdminController.js +82 -0
- package/lib/controllers/UserAdminController.js.map +1 -0
- package/lib/controllers/UserController.d.ts +10 -0
- package/lib/controllers/UserController.js +115 -0
- package/lib/controllers/UserController.js.map +1 -0
- package/lib/controllers/UserMetadata.d.ts +6 -0
- package/lib/controllers/UserMetadata.js +66 -0
- package/lib/controllers/UserMetadata.js.map +1 -0
- package/lib/decorators.d.ts +8 -1
- package/lib/decorators.js +13 -3
- package/lib/decorators.js.map +1 -1
- package/lib/dto/login-dto.d.ts +1 -1
- package/lib/dto/login-dto.js +2 -2
- package/lib/dto/login-dto.js.map +1 -1
- package/lib/dto/password-dto.d.ts +6 -0
- package/lib/dto/password-dto.js +2 -1
- package/lib/dto/password-dto.js.map +1 -1
- package/lib/dto/user-dto.d.ts +0 -23
- package/lib/dto/user-dto.js +0 -5
- package/lib/dto/user-dto.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +7 -0
- package/lib/middlewares.d.ts +4 -4
- package/lib/middlewares.js +10 -14
- package/lib/middlewares.js.map +1 -1
- package/lib/policies.js +1 -1
- package/lib/policies.js.map +1 -1
- package/lib/route-args.d.ts +9 -2
- package/lib/route-args.js +15 -3
- package/lib/route-args.js.map +1 -1
- package/package.json +11 -10
- package/lib/augumentation.d.ts +0 -7
- package/lib/augumentation.js +0 -4
- package/lib/augumentation.js.map +0 -1
- package/lib/controllers/UsersController.d.ts +0 -15
- package/lib/controllers/UsersController.js +0 -197
- package/lib/controllers/UsersController.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { LoginDto } from './../dto/login-dto';
|
|
2
|
-
import { BaseController, Ok, CookieResponse, Unauthorized } from '@spinajs/http';
|
|
3
|
-
import { AuthProvider, SessionProvider } from '@spinajs/rbac';
|
|
2
|
+
import { BaseController, Ok, CookieResponse, Unauthorized, NotAllowed } from '@spinajs/http';
|
|
3
|
+
import { AuthProvider, SessionProvider, User as UserModel } from '@spinajs/rbac';
|
|
4
4
|
import { Configuration } from '@spinajs/configuration';
|
|
5
5
|
export declare class LoginController extends BaseController {
|
|
6
6
|
protected Configuration: Configuration;
|
|
7
7
|
protected AuthProvider: AuthProvider;
|
|
8
8
|
protected SessionProvider: SessionProvider;
|
|
9
9
|
protected SessionExpirationTime: number;
|
|
10
|
-
login(credentials: LoginDto): Promise<Unauthorized | CookieResponse>;
|
|
10
|
+
login(credentials: LoginDto, logged: UserModel): Promise<Unauthorized | CookieResponse | NotAllowed>;
|
|
11
11
|
logout(ssid: string): Promise<Ok | CookieResponse>;
|
|
12
12
|
}
|
|
@@ -11,6 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
14
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
18
|
exports.LoginController = void 0;
|
|
16
19
|
const login_dto_1 = require("./../dto/login-dto");
|
|
@@ -18,9 +21,13 @@ const http_1 = require("@spinajs/http");
|
|
|
18
21
|
const rbac_1 = require("@spinajs/rbac");
|
|
19
22
|
const di_1 = require("@spinajs/di");
|
|
20
23
|
const configuration_1 = require("@spinajs/configuration");
|
|
21
|
-
const
|
|
24
|
+
const decorators_1 = require("./../decorators");
|
|
25
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
22
26
|
let LoginController = class LoginController extends http_1.BaseController {
|
|
23
|
-
async login(credentials) {
|
|
27
|
+
async login(credentials, logged) {
|
|
28
|
+
if (logged) {
|
|
29
|
+
return new http_1.NotAllowed('User already logged in. Please logout before trying to authorize.');
|
|
30
|
+
}
|
|
24
31
|
const user = await this.AuthProvider.authenticate(credentials.Login, credentials.Password);
|
|
25
32
|
if (!user) {
|
|
26
33
|
return new http_1.Unauthorized({
|
|
@@ -29,29 +36,19 @@ let LoginController = class LoginController extends http_1.BaseController {
|
|
|
29
36
|
},
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Id: user.Id,
|
|
40
|
-
};
|
|
41
|
-
const session = new rbac_1.Session({
|
|
42
|
-
Data: uObject,
|
|
43
|
-
Expiration: lifetime,
|
|
44
|
-
});
|
|
45
|
-
await this.SessionProvider.updateSession(session);
|
|
46
|
-
// sessionExpiration time is in minutes
|
|
47
|
-
// coockie maxAge is in seconds
|
|
48
|
-
return new http_1.CookieResponse('ssid', session.SessionId, this.SessionExpirationTime * 60, uObject, { httpOnly: true });
|
|
39
|
+
await user.Metadata.populate();
|
|
40
|
+
const session = new rbac_1.Session();
|
|
41
|
+
const sData = user.dehydrate();
|
|
42
|
+
session.Data.set('User', sData);
|
|
43
|
+
await this.SessionProvider.save(session);
|
|
44
|
+
// BEWARE: httpOnly coockie, only accesible via http method in browser
|
|
45
|
+
return new http_1.CookieResponse('ssid', session.SessionId, this.SessionExpirationTime, true, lodash_1.default.omit(sData, ['Id']), { httpOnly: true });
|
|
49
46
|
}
|
|
50
47
|
async logout(ssid) {
|
|
51
48
|
if (!ssid) {
|
|
52
49
|
return new http_1.Ok();
|
|
53
50
|
}
|
|
54
|
-
await this.SessionProvider.
|
|
51
|
+
await this.SessionProvider.delete(ssid);
|
|
55
52
|
// send empty cookie to confirm session deletion
|
|
56
53
|
return new http_1.CookieResponse('ssid', null, this.SessionExpirationTime);
|
|
57
54
|
}
|
|
@@ -69,14 +66,15 @@ __decorate([
|
|
|
69
66
|
__metadata("design:type", rbac_1.SessionProvider)
|
|
70
67
|
], LoginController.prototype, "SessionProvider", void 0);
|
|
71
68
|
__decorate([
|
|
72
|
-
(0, configuration_1.Config)('rbac.session.expiration',
|
|
69
|
+
(0, configuration_1.Config)('rbac.session.expiration', 120),
|
|
73
70
|
__metadata("design:type", Number)
|
|
74
71
|
], LoginController.prototype, "SessionExpirationTime", void 0);
|
|
75
72
|
__decorate([
|
|
76
73
|
(0, http_1.Post)(),
|
|
77
74
|
__param(0, (0, http_1.Body)()),
|
|
75
|
+
__param(1, (0, decorators_1.User)()),
|
|
78
76
|
__metadata("design:type", Function),
|
|
79
|
-
__metadata("design:paramtypes", [login_dto_1.LoginDto]),
|
|
77
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto, rbac_1.User]),
|
|
80
78
|
__metadata("design:returntype", Promise)
|
|
81
79
|
], LoginController.prototype, "login", null);
|
|
82
80
|
__decorate([
|
|
@@ -87,7 +85,7 @@ __decorate([
|
|
|
87
85
|
__metadata("design:returntype", Promise)
|
|
88
86
|
], LoginController.prototype, "logout", null);
|
|
89
87
|
LoginController = __decorate([
|
|
90
|
-
(0, http_1.BasePath)('auth')
|
|
88
|
+
(0, http_1.BasePath)('user/auth')
|
|
91
89
|
], LoginController);
|
|
92
90
|
exports.LoginController = LoginController;
|
|
93
91
|
//# sourceMappingURL=LoginController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoginController.js","sourceRoot":"","sources":["../../src/controllers/LoginController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LoginController.js","sourceRoot":"","sources":["../../src/controllers/LoginController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,kDAA8C;AAC9C,wCAAgI;AAChI,wCAA0F;AAC1F,oCAAyC;AACzC,0D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BAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACtE,CAAC;CACF,CAAA;AAnDC;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;sDAAC;AAGvC;IADC,IAAA,eAAU,GAAE;8BACW,mBAAY;qDAAC;AAGrC;IADC,IAAA,eAAU,GAAE;8BACc,sBAAe;wDAAC;AAG3C;IADC,IAAA,sBAAM,EAAC,yBAAyB,EAAE,GAAG,CAAC;;8DACC;AAGxC;IADC,IAAA,WAAI,GAAE;IACa,WAAA,IAAA,WAAI,GAAE,CAAA;IAAyB,WAAA,IAAA,iBAAI,GAAE,CAAA;;qCAAjB,oBAAQ,EAAkB,WAAS;;4CA0B1E;AAGD;IADC,IAAA,UAAG,GAAE;IACe,WAAA,IAAA,aAAM,GAAE,CAAA;;;;6CAS5B;AApDU,eAAe;IAD3B,IAAA,eAAQ,EAAC,WAAW,CAAC;GACT,eAAe,CAqD3B;AArDY,0CAAe"}
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// import { InvalidArgument } from '@spinajs/exceptions';
|
|
2
|
+
// import { BaseController, Body, Get, NotFound, Ok, Patch, Post, Query, Req, Param } from '@spinajs/http';
|
|
3
|
+
// import { DateTime, RawQuery } from '@spinajs/orm';
|
|
4
|
+
// import { PasswordProvider, User } from '@spinajs/rbac';
|
|
5
|
+
// import { Permission, Resource } from './../decorators';
|
|
6
|
+
// import { UserDto } from '../dto/user-dto';
|
|
7
|
+
// import { BasePath } from 'http/lib';
|
|
8
|
+
// @Resource('user')
|
|
9
|
+
// @BasePath('user')
|
|
10
|
+
// export class UsersController extends BaseController {
|
|
11
|
+
// @Get('/')
|
|
12
|
+
// @Permission('readAny')
|
|
13
|
+
// public async listUsers(@Query() search: string, @Query({ type: 'number', minimum: 1 }) page: number, @Query({ type: 'number', minimum: 1 }) perPage: number, @Query() order: string, @Query(OrderSchema) orderDirection: SORT_ORDER, @Req() request: express.Request) {
|
|
14
|
+
// /**
|
|
15
|
+
// * implement include query param
|
|
16
|
+
// * do not return internal id
|
|
17
|
+
// *
|
|
18
|
+
// */
|
|
19
|
+
// const query = User.all()
|
|
20
|
+
// .whereNull('DeletedAt')
|
|
21
|
+
// .skip((page - 1) * perPage)
|
|
22
|
+
// .take(perPage)
|
|
23
|
+
// .order(order, orderDirection)
|
|
24
|
+
// .populate('Metadata');
|
|
25
|
+
// const countQuery = User.query().select(new RawQuery('count(*) as count')).whereNull('DeletedAt');
|
|
26
|
+
// if (search) {
|
|
27
|
+
// const searchFunc = function () {
|
|
28
|
+
// this.where('Email', 'like', `%${search}%`);
|
|
29
|
+
// this.orWhere('NiceName', 'like', `%${search}%`);
|
|
30
|
+
// };
|
|
31
|
+
// query.where(searchFunc);
|
|
32
|
+
// countQuery.where(searchFunc);
|
|
33
|
+
// }
|
|
34
|
+
// const r = await query;
|
|
35
|
+
// const c = await countQuery.asRaw<Array<{ count: number }>>();
|
|
36
|
+
// if (r.length === 0) {
|
|
37
|
+
// return new NotFound('no users met search criteria');
|
|
38
|
+
// }
|
|
39
|
+
// return new Ok(
|
|
40
|
+
// this.DataTransformer.transform(
|
|
41
|
+
// {
|
|
42
|
+
// Data: r.map((u) => u.dehydrate()),
|
|
43
|
+
// Total: c[0].count,
|
|
44
|
+
// },
|
|
45
|
+
// request,
|
|
46
|
+
// ),
|
|
47
|
+
// );
|
|
48
|
+
// }
|
|
49
|
+
// // @Post('/')
|
|
50
|
+
// // public async addUser(@Body() user: UserDto) {
|
|
51
|
+
// // const password = this._container.resolve<PasswordProvider>(PasswordProvider);
|
|
52
|
+
// // if (user.Password !== user.ConfirmPassword) {
|
|
53
|
+
// // throw new InvalidArgument('password does not match');
|
|
54
|
+
// // }
|
|
55
|
+
// // let hashedPassword = '';
|
|
56
|
+
// // let userPassword = user.Password;
|
|
57
|
+
// // if (!userPassword) {
|
|
58
|
+
// // userPassword = password.generate();
|
|
59
|
+
// // }
|
|
60
|
+
// // hashedPassword = await password.hash(userPassword);
|
|
61
|
+
// // const entity = new User({
|
|
62
|
+
// // Email: user.Email,
|
|
63
|
+
// // Login: user.Login,
|
|
64
|
+
// // NiceName: user.NiceName,
|
|
65
|
+
// // Password: hashedPassword,
|
|
66
|
+
// // CreatedAt: DateTime.now(),
|
|
67
|
+
// // Role: user.Role,
|
|
68
|
+
// // });
|
|
69
|
+
// // await entity.insert();
|
|
70
|
+
// // return new Ok({ Id: entity.Id });
|
|
71
|
+
// // }
|
|
72
|
+
// // @Patch('role/add/:login/:role')
|
|
73
|
+
// // @Permission('updateAny')
|
|
74
|
+
// // public async addRole(@Param() login: string, @Param() role: string) {}
|
|
75
|
+
// // @Patch('role/revoke/:login/:role')
|
|
76
|
+
// // @Permission('updateAny')
|
|
77
|
+
// // public async revokeRole(@Param() login: string, @Param() role: string) {}
|
|
78
|
+
// // @Patch('update/:login')
|
|
79
|
+
// // @Permission('updateAny')
|
|
80
|
+
// // public async update(@Param() login: string, @Body() data: any) {}
|
|
81
|
+
// }
|
|
82
|
+
//# sourceMappingURL=UserAdminController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserAdminController.js","sourceRoot":"","sources":["../../src/controllers/UserAdminController.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,2GAA2G;AAC3G,qDAAqD;AACrD,0DAA0D;AAC1D,0DAA0D;AAC1D,6CAA6C;AAC7C,uCAAuC;AAEvC,oBAAoB;AACpB,oBAAoB;AACpB,wDAAwD;AACxD,cAAc;AACd,2BAA2B;AAC3B,4QAA4Q;AAC5Q,UAAU;AACV,uCAAuC;AACvC,mCAAmC;AACnC,SAAS;AACT,UAAU;AAEV,+BAA+B;AAC/B,gCAAgC;AAChC,oCAAoC;AACpC,uBAAuB;AACvB,sCAAsC;AACtC,+BAA+B;AAC/B,wGAAwG;AAExG,oBAAoB;AACpB,yCAAyC;AACzC,sDAAsD;AACtD,2DAA2D;AAC3D,WAAW;AAEX,iCAAiC;AACjC,sCAAsC;AACtC,QAAQ;AAER,6BAA6B;AAC7B,oEAAoE;AAEpE,4BAA4B;AAC5B,6DAA6D;AAC7D,QAAQ;AAER,qBAAqB;AACrB,wCAAwC;AACxC,YAAY;AACZ,+CAA+C;AAC/C,+BAA+B;AAC/B,aAAa;AACb,mBAAmB;AACnB,WAAW;AACX,SAAS;AACT,MAAM;AAEN,kBAAkB;AAClB,qDAAqD;AACrD,uFAAuF;AACvF,uDAAuD;AACvD,iEAAiE;AACjE,WAAW;AAEX,kCAAkC;AAClC,2CAA2C;AAE3C,8BAA8B;AAC9B,+CAA+C;AAC/C,WAAW;AAEX,6DAA6D;AAC7D,mCAAmC;AACnC,8BAA8B;AAC9B,8BAA8B;AAC9B,oCAAoC;AACpC,qCAAqC;AACrC,sCAAsC;AACtC,4BAA4B;AAC5B,aAAa;AAEb,gCAAgC;AAEhC,2CAA2C;AAC3C,SAAS;AAET,uCAAuC;AACvC,gCAAgC;AAChC,8EAA8E;AAE9E,0CAA0C;AAC1C,gCAAgC;AAChC,iFAAiF;AAEjF,+BAA+B;AAC/B,gCAAgC;AAChC,yEAAyE;AACzE,IAAI"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PasswordDto } from '../dto/password-dto';
|
|
2
|
+
import { User as UserModel, PasswordProvider, SessionProvider } from '@spinajs/rbac';
|
|
3
|
+
import { BaseController, Ok } from '@spinajs/http';
|
|
4
|
+
export declare class UserController extends BaseController {
|
|
5
|
+
protected PasswordProvider: PasswordProvider;
|
|
6
|
+
protected CoockieSecret: string;
|
|
7
|
+
protected SessionProvider: SessionProvider;
|
|
8
|
+
refresh(user: UserModel, ssid: string): Promise<Ok>;
|
|
9
|
+
newPassword(login: string, pwd: PasswordDto): Promise<Ok>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
35
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.UserController = void 0;
|
|
42
|
+
const password_dto_1 = require("../dto/password-dto");
|
|
43
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
44
|
+
const http_1 = require("@spinajs/http");
|
|
45
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
46
|
+
const di_1 = require("@spinajs/di");
|
|
47
|
+
const decorators_1 = require("../decorators");
|
|
48
|
+
const http_2 = require("@spinajs/http");
|
|
49
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
50
|
+
const cs = __importStar(require("cookie-signature"));
|
|
51
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
52
|
+
let UserController = class UserController extends http_1.BaseController {
|
|
53
|
+
async refresh(user, ssid) {
|
|
54
|
+
// get user data from db
|
|
55
|
+
await user.refresh();
|
|
56
|
+
// refresh session data from DB
|
|
57
|
+
const sId = cs.unsign(ssid, this.CoockieSecret);
|
|
58
|
+
if (sId) {
|
|
59
|
+
const session = await this.SessionProvider.restore(sId);
|
|
60
|
+
if (session) {
|
|
61
|
+
session.Data.set('User', user.dehydrate());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new http_1.Ok(lodash_1.default.omit(user.dehydrate(), ['Id']));
|
|
65
|
+
}
|
|
66
|
+
async newPassword(login, pwd) {
|
|
67
|
+
if (pwd.Password !== pwd.ConfirmPassword) {
|
|
68
|
+
throw new exceptions_1.InvalidArgument('password does not match');
|
|
69
|
+
}
|
|
70
|
+
const user = await rbac_1.User.where({ Login: login }).firstOrFail();
|
|
71
|
+
const isValid = await this.PasswordProvider.verify(user.Password, pwd.OldPassword);
|
|
72
|
+
if (!isValid) {
|
|
73
|
+
throw new exceptions_1.Forbidden('Invalid login or password');
|
|
74
|
+
}
|
|
75
|
+
const hashedPassword = await this.PasswordProvider.hash(pwd.Password);
|
|
76
|
+
user.Password = hashedPassword;
|
|
77
|
+
await user.update();
|
|
78
|
+
return new http_1.Ok();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, di_1.Autoinject)(),
|
|
83
|
+
__metadata("design:type", rbac_1.PasswordProvider)
|
|
84
|
+
], UserController.prototype, "PasswordProvider", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, configuration_1.Config)('http.cookie.secret'),
|
|
87
|
+
__metadata("design:type", String)
|
|
88
|
+
], UserController.prototype, "CoockieSecret", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, di_1.Autoinject)(),
|
|
91
|
+
__metadata("design:type", rbac_1.SessionProvider)
|
|
92
|
+
], UserController.prototype, "SessionProvider", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, http_1.Get)(),
|
|
95
|
+
(0, decorators_1.Permission)('readOwn'),
|
|
96
|
+
__param(0, (0, decorators_1.User)()),
|
|
97
|
+
__param(1, (0, http_2.Cookie)()),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [rbac_1.User, String]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], UserController.prototype, "refresh", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, http_1.Patch)('/password/:login'),
|
|
104
|
+
__param(0, (0, http_1.Param)()),
|
|
105
|
+
__param(1, (0, http_1.Body)()),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [String, password_dto_1.PasswordDto]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], UserController.prototype, "newPassword", null);
|
|
110
|
+
UserController = __decorate([
|
|
111
|
+
(0, http_1.BasePath)('user'),
|
|
112
|
+
(0, decorators_1.Resource)('user')
|
|
113
|
+
], UserController);
|
|
114
|
+
exports.UserController = UserController;
|
|
115
|
+
//# sourceMappingURL=UserController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserController.js","sourceRoot":"","sources":["../../src/controllers/UserController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAkD;AAClD,wCAAqF;AACrF,wCAAsF;AACtF,oDAAiE;AACjE,oCAAyC;AACzC,8CAA2D;AAC3D,wCAAuC;AACvC,0DAAgD;AAChD,qDAAuC;AACvC,oDAAuB;AAIvB,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,qBAAc;IAYzC,KAAK,CAAC,OAAO,CAAS,IAAe,EAAY,IAAY;QAClE,wBAAwB;QACxB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,+BAA+B;QAC/B,MAAM,GAAG,GAAmB,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAChE,IAAI,GAAG,EAAE;YACP,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxD,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aAC5C;SACF;QAED,OAAO,IAAI,SAAE,CAAC,gBAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAGM,KAAK,CAAC,WAAW,CAAU,KAAa,EAAU,GAAgB;QACvE,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,eAAe,EAAE;YACxC,MAAM,IAAI,4BAAe,CAAC,yBAAyB,CAAC,CAAC;SACtD;QAED,MAAM,IAAI,GAAG,MAAM,WAAS,CAAC,KAAK,CAAC,EAAE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{
|
|
4
|
+
addMetadata(logged: UserModel, user: UserModel, meta: UserMetadata): Promise<Ok>;
|
|
5
|
+
updateMetadata(logged: UserModel, user: UserModel, meta: UserMetadata): Promise<Ok>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserMetaController = void 0;
|
|
16
|
+
const http_1 = require("@spinajs/http");
|
|
17
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
18
|
+
const decorators_1 = require("./../decorators");
|
|
19
|
+
const decorators_2 = require("../decorators");
|
|
20
|
+
const orm_http_1 = require("@spinajs/orm-http");
|
|
21
|
+
let UserMetaController = class UserMetaController {
|
|
22
|
+
async addMetadata(logged, user, meta) {
|
|
23
|
+
if (logged.Id !== user.Id) {
|
|
24
|
+
throw new http_1.Forbidden('cannot add metadata to another user');
|
|
25
|
+
}
|
|
26
|
+
await user.Metadata.add(meta);
|
|
27
|
+
return new http_1.Ok(meta);
|
|
28
|
+
}
|
|
29
|
+
async updateMetadata(logged, user, meta) {
|
|
30
|
+
if (logged.Id !== user.Id) {
|
|
31
|
+
throw new http_1.Forbidden('cannot add metadata to another user');
|
|
32
|
+
}
|
|
33
|
+
await meta.User.populate();
|
|
34
|
+
if (meta.User.Value.Id !== logged.Id) {
|
|
35
|
+
throw new http_1.Forbidden('cannot edit metadata that is not own by user');
|
|
36
|
+
}
|
|
37
|
+
await meta.update();
|
|
38
|
+
return new http_1.Ok();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, http_1.Post)(),
|
|
43
|
+
(0, decorators_2.Permission)('updateOwn'),
|
|
44
|
+
__param(0, (0, decorators_2.User)()),
|
|
45
|
+
__param(1, (0, orm_http_1.FromModel)()),
|
|
46
|
+
__param(2, (0, orm_http_1.AsModel)()),
|
|
47
|
+
__metadata("design:type", Function),
|
|
48
|
+
__metadata("design:paramtypes", [rbac_1.User, rbac_1.User, rbac_1.UserMetadata]),
|
|
49
|
+
__metadata("design:returntype", Promise)
|
|
50
|
+
], UserMetaController.prototype, "addMetadata", null);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, http_1.Patch)('user/:user/metadata/:meta'),
|
|
53
|
+
(0, decorators_2.Permission)('updateOwn'),
|
|
54
|
+
__param(0, (0, decorators_2.User)()),
|
|
55
|
+
__param(1, (0, orm_http_1.FromModel)()),
|
|
56
|
+
__param(2, (0, orm_http_1.FromModel)()),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", [rbac_1.User, rbac_1.User, rbac_1.UserMetadata]),
|
|
59
|
+
__metadata("design:returntype", Promise)
|
|
60
|
+
], UserMetaController.prototype, "updateMetadata", null);
|
|
61
|
+
UserMetaController = __decorate([
|
|
62
|
+
(0, http_1.BasePath)('user/:user/metadata'),
|
|
63
|
+
(0, decorators_1.Resource)('user.metadata')
|
|
64
|
+
], UserMetaController);
|
|
65
|
+
exports.UserMetaController = UserMetaController;
|
|
66
|
+
//# sourceMappingURL=UserMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserMetadata.js","sourceRoot":"","sources":["../../src/controllers/UserMetadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wCAAqE;AACrE,wCAAgE;AAChE,gDAA2C;AAC3C,8CAAiD;AACjD,gDAAuD;AAIvD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAGtB,KAAK,CAAC,WAAW,CAAS,MAAiB,EAAe,IAAe,EAAa,IAAkB;QAC7G,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE;YACzB,MAAM,IAAI,gBAAS,CAAC,qCAAqC,CAAC,CAAC;SAC5D;QAED,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,SAAE,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAIM,KAAK,CAAC,cAAc,CAAS,MAAiB,EAAe,IAAe,EAAe,IAAkB;QAClH,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE;YACzB,MAAM,IAAI,gBAAS,CAAC,qCAAqC,CAAC,CAAC;SAC5D;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,EAAE;YACpC,MAAM,IAAI,gBAAS,CAAC,8CAA8C,CAAC,CAAC;SACrE;QAED,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAEpB,OAAO,IAAI,SAAE,EAAE,CAAC;IAClB,CAAC;CACF,CAAA;AAzBC;IAFC,IAAA,WAAI,GAAE;IACN,IAAA,uBAAU,EAAC,WAAW,CAAC;IACE,WAAA,IAAA,iBAAI,GAAE,CAAA;IAAqB,WAAA,IAAA,oBAAS,GAAE,CAAA;IAAmB,WAAA,IAAA,kBAAO,GAAE,CAAA;;qCAAnD,WAAS,EAAqB,WAAS,EAAmB,mBAAY;;qDAO9G;AAID;IAFC,IAAA,YAAK,EAAC,2BAA2B,CAAC;IAClC,IAAA,uBAAU,EAAC,WAAW,CAAC;IACK,WAAA,IAAA,iBAAI,GAAE,CAAA;IAAqB,WAAA,IAAA,oBAAS,GAAE,CAAA;IAAmB,WAAA,IAAA,oBAAS,GAAE,CAAA;;qCAArD,WAAS,EAAqB,WAAS,EAAqB,mBAAY;;wDAanH;AA3BU,kBAAkB;IAF9B,IAAA,eAAQ,EAAC,qBAAqB,CAAC;IAC/B,IAAA,qBAAQ,EAAC,eAAe,CAAC;GACb,kBAAkB,CA4B9B;AA5BY,gDAAkB"}
|
package/lib/decorators.d.ts
CHANGED
|
@@ -15,4 +15,11 @@ export declare function Resource(resource: string, permission?: PermissionType):
|
|
|
15
15
|
* @param permission - permission to set
|
|
16
16
|
*/
|
|
17
17
|
export declare function Permission(permission?: PermissionType): any;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves user from session if is logged in
|
|
20
|
+
*/
|
|
21
|
+
export declare function User(): (target: any, propertyKey?: string | symbol, indexOrDescriptor?: number | PropertyDescriptor) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Extract args from user session
|
|
24
|
+
*/
|
|
25
|
+
export declare function Session(): (target: any, propertyKey?: string | symbol, indexOrDescriptor?: number | PropertyDescriptor) => void;
|
package/lib/decorators.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Session = exports.User = exports.Permission = exports.Resource = exports.setRbacMetadata = exports.ACL_CONTROLLER_DESCRIPTOR = void 0;
|
|
4
4
|
const http_1 = require("@spinajs/http");
|
|
5
5
|
const policies_1 = require("./policies");
|
|
6
6
|
exports.ACL_CONTROLLER_DESCRIPTOR = Symbol('ACL_CONTROLLER_DESCRIPTOR_SYMBOL');
|
|
@@ -73,8 +73,18 @@ function Permission(permission = 'readOwn') {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
exports.Permission = Permission;
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves user from session if is logged in
|
|
78
|
+
*/
|
|
79
|
+
function User() {
|
|
77
80
|
return (0, http_1.Route)((0, http_1.Parameter)('UserArg'));
|
|
78
81
|
}
|
|
79
|
-
exports.
|
|
82
|
+
exports.User = User;
|
|
83
|
+
/**
|
|
84
|
+
* Extract args from user session
|
|
85
|
+
*/
|
|
86
|
+
function Session() {
|
|
87
|
+
return (0, http_1.Route)((0, http_1.Parameter)('SessionArg'));
|
|
88
|
+
}
|
|
89
|
+
exports.Session = Session;
|
|
80
90
|
//# sourceMappingURL=decorators.js.map
|
package/lib/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AACA,wCAAyD;AACzD,yCAAwC;AAE3B,QAAA,yBAAyB,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAEpF,SAAgB,eAAe,CAAC,MAAW,EAAE,QAAyC;IACpF,IAAI,QAAQ,GAAoB,OAAO,CAAC,WAAW,CAAC,iCAAyB,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;IAC3G,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG;YACT,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,IAAI,GAAG,EAA0C;YACzD,UAAU,EAAE,SAAS;SACtB,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,iCAAyB,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;KACzF;IAED,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACpB;AACH,CAAC;AAfD,0CAeC;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,aAAM,EAAC,qBAAU,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC;AAlBD,gCAkBC;AAED;;GAEG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAA,YAAK,EAAC,IAAA,gBAAS,EAAC,SAAS,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,oBAEC;AAED;;GAEG;AACH,SAAgB,OAAO;IACrB,OAAO,IAAA,YAAK,EAAC,IAAA,gBAAS,EAAC,YAAY,CAAC,CAAC,CAAC;AACxC,CAAC;AAFD,0BAEC"}
|
package/lib/dto/login-dto.d.ts
CHANGED
package/lib/dto/login-dto.js
CHANGED
|
@@ -16,10 +16,10 @@ exports.LoginDtoSchema = {
|
|
|
16
16
|
title: 'User login DTO',
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
|
-
Login: { type: 'string',
|
|
19
|
+
Login: { type: 'string', format: 'email' },
|
|
20
20
|
Password: { type: 'string', maxLength: 32 },
|
|
21
21
|
},
|
|
22
|
-
required: ['
|
|
22
|
+
required: ['Email', 'Password'],
|
|
23
23
|
};
|
|
24
24
|
let LoginDto = class LoginDto {
|
|
25
25
|
constructor(data) {
|
package/lib/dto/login-dto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-dto.js","sourceRoot":"","sources":["../../src/dto/login-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"login-dto.js","sourceRoot":"","sources":["../../src/dto/login-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE;QAC1C,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;KAC5C;IACD,QAAQ,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;CAChC,CAAC;AAGF,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAKnB,YAAY,IAAS;QACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AARY,QAAQ;IADpB,IAAA,mBAAM,EAAC,sBAAc,CAAC;;GACV,QAAQ,CAQpB;AARY,4BAAQ"}
|
|
@@ -3,6 +3,11 @@ export declare const PasswordDtoSchema: {
|
|
|
3
3
|
title: string;
|
|
4
4
|
type: string;
|
|
5
5
|
properties: {
|
|
6
|
+
OldPassword: {
|
|
7
|
+
type: string;
|
|
8
|
+
maxLength: number;
|
|
9
|
+
minLength: number;
|
|
10
|
+
};
|
|
6
11
|
Password: {
|
|
7
12
|
type: string;
|
|
8
13
|
maxLength: number;
|
|
@@ -17,6 +22,7 @@ export declare const PasswordDtoSchema: {
|
|
|
17
22
|
required: string[];
|
|
18
23
|
};
|
|
19
24
|
export declare class PasswordDto {
|
|
25
|
+
OldPassword: string;
|
|
20
26
|
Password: string;
|
|
21
27
|
ConfirmPassword: string;
|
|
22
28
|
constructor(data: any);
|
package/lib/dto/password-dto.js
CHANGED
|
@@ -16,10 +16,11 @@ exports.PasswordDtoSchema = {
|
|
|
16
16
|
title: 'User password DTO',
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
|
+
OldPassword: { type: 'string', maxLength: 32, minLength: 6 },
|
|
19
20
|
Password: { type: 'string', maxLength: 32, minLength: 6 },
|
|
20
21
|
ConfirmPassword: { type: 'string', maxLength: 32, minLength: 6 },
|
|
21
22
|
},
|
|
22
|
-
required: ['Password', 'ConfirmPassword'],
|
|
23
|
+
required: ['OldPassword', 'Password', 'ConfirmPassword'],
|
|
23
24
|
};
|
|
24
25
|
let PasswordDto = class PasswordDto {
|
|
25
26
|
constructor(data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-dto.js","sourceRoot":"","sources":["../../src/dto/password-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,mBAAmB;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QACzD,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;KACjE;IACD,QAAQ,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"password-dto.js","sourceRoot":"","sources":["../../src/dto/password-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,mBAAmB;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QAC5D,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QACzD,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;KACjE;IACD,QAAQ,EAAE,CAAC,aAAa,EAAE,UAAU,EAAE,iBAAiB,CAAC;CACzD,CAAC;AAGF,IAAa,WAAW,GAAxB,MAAa,WAAW;IAOtB,YAAY,IAAS;QACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAVY,WAAW;IADvB,IAAA,mBAAM,EAAC,yBAAiB,CAAC;;GACb,WAAW,CAUvB;AAVY,kCAAW"}
|
package/lib/dto/user-dto.d.ts
CHANGED
|
@@ -3,9 +3,6 @@ export declare const UserDtoSchema: {
|
|
|
3
3
|
title: string;
|
|
4
4
|
type: string;
|
|
5
5
|
properties: {
|
|
6
|
-
Id: {
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
6
|
Email: {
|
|
10
7
|
type: string;
|
|
11
8
|
format: string;
|
|
@@ -15,30 +12,10 @@ export declare const UserDtoSchema: {
|
|
|
15
12
|
type: string;
|
|
16
13
|
maxLength: number;
|
|
17
14
|
};
|
|
18
|
-
ConfirmPassword: {
|
|
19
|
-
type: string;
|
|
20
|
-
maxLength: number;
|
|
21
|
-
minLength: number;
|
|
22
|
-
};
|
|
23
|
-
Password: {
|
|
24
|
-
type: string;
|
|
25
|
-
maxLength: number;
|
|
26
|
-
minLength: number;
|
|
27
|
-
};
|
|
28
|
-
NiceName: {
|
|
29
|
-
type: string;
|
|
30
|
-
maxLength: number;
|
|
31
|
-
};
|
|
32
15
|
};
|
|
33
|
-
required: string[];
|
|
34
16
|
};
|
|
35
17
|
export declare class UserDto {
|
|
36
|
-
Idsss?: number;
|
|
37
18
|
Email: string;
|
|
38
19
|
Login: string;
|
|
39
|
-
Password: string;
|
|
40
|
-
ConfirmPassword: string;
|
|
41
|
-
NiceName: string;
|
|
42
|
-
Role: string;
|
|
43
20
|
constructor(data: any);
|
|
44
21
|
}
|
package/lib/dto/user-dto.js
CHANGED
|
@@ -16,14 +16,9 @@ exports.UserDtoSchema = {
|
|
|
16
16
|
title: 'User DTO',
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
|
-
Id: { type: 'number' },
|
|
20
19
|
Email: { type: 'string', format: 'email', maxLength: 64 },
|
|
21
20
|
Login: { type: 'string', maxLength: 64 },
|
|
22
|
-
ConfirmPassword: { type: 'string', maxLength: 32, minLength: 6 },
|
|
23
|
-
Password: { type: 'string', maxLength: 32, minLength: 6 },
|
|
24
|
-
NiceName: { type: 'string', maxLength: 64 },
|
|
25
21
|
},
|
|
26
|
-
required: ['Email', 'NiceName'],
|
|
27
22
|
};
|
|
28
23
|
let UserDto = class UserDto {
|
|
29
24
|
constructor(data) {
|
package/lib/dto/user-dto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-dto.js","sourceRoot":"","sources":["../../src/dto/user-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAChC,QAAA,aAAa,GAAG;IAC3B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,
|
|
1
|
+
{"version":3,"file":"user-dto.js","sourceRoot":"","sources":["../../src/dto/user-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAChC,QAAA,aAAa,GAAG;IAC3B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;QACzD,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;KACzC;CACF,CAAC;AAGF,IAAa,OAAO,GAApB,MAAa,OAAO;IAKlB,YAAY,IAAS;QACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AARY,OAAO;IADnB,IAAA,mBAAM,EAAC,qBAAa,CAAC;;GACT,OAAO,CAQnB;AARY,0BAAO"}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export * from './interfaces';
|
|
|
3
3
|
export * from './middlewares';
|
|
4
4
|
export * from './policies';
|
|
5
5
|
export * from './controllers/LoginController';
|
|
6
|
-
export * from './controllers/
|
|
6
|
+
export * from './controllers/UserController';
|
|
7
7
|
export * from './transformers';
|
|
8
8
|
export * from './route-args';
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ __exportStar(require("./interfaces"), exports);
|
|
|
19
19
|
__exportStar(require("./middlewares"), exports);
|
|
20
20
|
__exportStar(require("./policies"), exports);
|
|
21
21
|
__exportStar(require("./controllers/LoginController"), exports);
|
|
22
|
-
__exportStar(require("./controllers/
|
|
22
|
+
__exportStar(require("./controllers/UserController"), exports);
|
|
23
23
|
__exportStar(require("./transformers"), exports);
|
|
24
24
|
__exportStar(require("./route-args"), exports);
|
|
25
25
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,6CAA2B;AAC3B,gEAA8C;AAC9C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,6CAA2B;AAC3B,gEAA8C;AAC9C,+DAA6C;AAC7C,iDAA+B;AAC/B,+CAA6B"}
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { User, ISession } from '@spinajs/rbac';
|
|
1
2
|
export declare type PermissionType = 'readAny' | 'readOwn' | 'updateAny' | 'updateOwn' | 'deleteAny' | 'deleteOwn' | 'createAny' | 'createOwn';
|
|
3
|
+
declare module '@spinajs/http' {
|
|
4
|
+
interface IActionLocalStoregeContext {
|
|
5
|
+
user: User | null;
|
|
6
|
+
session: ISession;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
export interface IRbacDescriptor {
|
|
3
10
|
/**
|
|
4
11
|
* Resource name
|
package/lib/middlewares.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SessionProvider } from '@spinajs/rbac';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import * as express from 'express';
|
|
4
|
-
import { ServerMiddleware } from '@spinajs/http';
|
|
5
|
-
export declare class
|
|
4
|
+
import { Request as sRequest, ServerMiddleware } from '@spinajs/http';
|
|
5
|
+
export declare class RbacMiddleware extends ServerMiddleware {
|
|
6
6
|
protected CoockieSecret: string;
|
|
7
7
|
protected SessionProvider: SessionProvider;
|
|
8
8
|
resolveAsync(): Promise<void>;
|
|
9
|
-
before(): (req:
|
|
10
|
-
after(): (req:
|
|
9
|
+
before(): (req: sRequest, res: express.Response, next: express.NextFunction) => void;
|
|
10
|
+
after(): (req: sRequest, res: express.Response, next: express.NextFunction) => void;
|
|
11
11
|
}
|
package/lib/middlewares.js
CHANGED
|
@@ -32,15 +32,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
32
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
35
|
+
exports.RbacMiddleware = void 0;
|
|
36
36
|
const rbac_1 = require("@spinajs/rbac");
|
|
37
37
|
const di_1 = require("@spinajs/di");
|
|
38
38
|
require("reflect-metadata");
|
|
39
39
|
const configuration_1 = require("@spinajs/configuration");
|
|
40
40
|
const cs = __importStar(require("cookie-signature"));
|
|
41
|
-
const luxon_1 = require("luxon");
|
|
42
41
|
const http_1 = require("@spinajs/http");
|
|
43
|
-
let
|
|
42
|
+
let RbacMiddleware = class RbacMiddleware extends http_1.ServerMiddleware {
|
|
44
43
|
async resolveAsync() {
|
|
45
44
|
if (!this.CoockieSecret) {
|
|
46
45
|
throw new Error('http.cookie.secres is not set, cannot start UserFromSessionMiddleware. Set this value in configuration file !');
|
|
@@ -52,13 +51,10 @@ let UserFromSessionMiddleware = class UserFromSessionMiddleware extends http_1.S
|
|
|
52
51
|
if (req.cookies.ssid) {
|
|
53
52
|
const ssid = cs.unsign(req.cookies.ssid, this.CoockieSecret);
|
|
54
53
|
if (ssid) {
|
|
55
|
-
const session =
|
|
54
|
+
const session = await this.SessionProvider.restore(ssid);
|
|
56
55
|
if (session) {
|
|
57
|
-
req.storage.user = new rbac_1.User(session.Data);
|
|
58
|
-
|
|
59
|
-
if (liveTimeDiff.minutes < 30) {
|
|
60
|
-
await this.SessionProvider.refreshSession(session);
|
|
61
|
-
}
|
|
56
|
+
req.storage.user = new rbac_1.User(session.Data.get('User'));
|
|
57
|
+
req.storage.session = session;
|
|
62
58
|
}
|
|
63
59
|
else {
|
|
64
60
|
req.storage.user = null;
|
|
@@ -82,13 +78,13 @@ let UserFromSessionMiddleware = class UserFromSessionMiddleware extends http_1.S
|
|
|
82
78
|
__decorate([
|
|
83
79
|
(0, configuration_1.Config)('http.cookie.secret'),
|
|
84
80
|
__metadata("design:type", String)
|
|
85
|
-
],
|
|
81
|
+
], RbacMiddleware.prototype, "CoockieSecret", void 0);
|
|
86
82
|
__decorate([
|
|
87
83
|
(0, di_1.Autoinject)(),
|
|
88
84
|
__metadata("design:type", rbac_1.SessionProvider)
|
|
89
|
-
],
|
|
90
|
-
|
|
85
|
+
], RbacMiddleware.prototype, "SessionProvider", void 0);
|
|
86
|
+
RbacMiddleware = __decorate([
|
|
91
87
|
(0, di_1.Injectable)(http_1.ServerMiddleware)
|
|
92
|
-
],
|
|
93
|
-
exports.
|
|
88
|
+
], RbacMiddleware);
|
|
89
|
+
exports.RbacMiddleware = RbacMiddleware;
|
|
94
90
|
//# sourceMappingURL=middlewares.js.map
|
package/lib/middlewares.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAsD;AACtD,oCAAqD;AACrD,4BAA0B;AAE1B,0DAAgD;AAChD,qDAAuC;AACvC,wCAAsE;AAGtE,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,uBAAgB;IAO3C,KAAK,CAAC,YAAY;QACvB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,+GAA+G,CAAC,CAAC;SAClI;IACH,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,EAAE,GAAa,EAAE,IAAsB,EAAE,IAA0B,EAAE,EAAE;YACjF,IAAI;gBACF,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;oBACpB,MAAM,IAAI,GAAmB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC7E,IAAI,IAAI,EAAE;wBACR,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;wBACzD,IAAI,OAAO,EAAE;4BACX,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;4BACtD,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;yBAC/B;6BAAM;4BACL,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;yBACzB;qBACF;yBAAM;wBACL,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;qBACzB;iBACF;gBACD,IAAI,EAAE,CAAC;aACR;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,GAAG,CAAC,CAAC;aACX;QACH,CAAC,CAAC;IACJ,CAAC;IACM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AArCC;IADC,IAAA,sBAAM,EAAC,oBAAoB,CAAC;;qDACG;AAGhC;IADC,IAAA,eAAU,GAAE;8BACc,sBAAe;uDAAC;AALhC,cAAc;IAD1B,IAAA,eAAU,EAAC,uBAAgB,CAAC;GAChB,cAAc,CAuC1B;AAvCY,wCAAc"}
|
package/lib/policies.js
CHANGED
|
@@ -44,7 +44,7 @@ function checkUserPermission(user, resource, permission) {
|
|
|
44
44
|
if (!user) {
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
|
-
return ac.can(user.Role
|
|
47
|
+
return ac.can(user.Role)[permission](resource);
|
|
48
48
|
}
|
|
49
49
|
exports.checkUserPermission = checkUserPermission;
|
|
50
50
|
function checkRoutePermission(req, resource, permission) {
|
package/lib/policies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../src/policies.ts"],"names":[],"mappings":";;;AACA,wCAAqF;AACrF,oDAAgD;AAChD,6CAAyD;AAEzD,oCAAiC;AAGjC,MAAa,UAAW,SAAQ,iBAAU;IAGxC;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,EAAE,GAAG,OAAE,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAEM,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,0BAA0B;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAa,EAAE,MA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
|
|
2
|
-
import
|
|
2
|
+
import { Request } from '@spinajs/http';
|
|
3
3
|
export declare class UserArg extends RouteArgs {
|
|
4
4
|
get SupportedType(): ParameterType;
|
|
5
|
-
extract(callData: IRouteCall, _param: IRouteParameter, req:
|
|
5
|
+
extract(callData: IRouteCall, _param: IRouteParameter, req: Request): Promise<{
|
|
6
6
|
CallData: IRouteCall;
|
|
7
7
|
Args: import("@spinajs/rbac/lib").User;
|
|
8
8
|
}>;
|
|
9
9
|
}
|
|
10
|
+
export declare class SessionArg extends RouteArgs {
|
|
11
|
+
get SupportedType(): string;
|
|
12
|
+
extract(callData: IRouteCall, param: IRouteParameter, req: Request): Promise<{
|
|
13
|
+
CallData: IRouteCall;
|
|
14
|
+
Args: unknown;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
package/lib/route-args.js
CHANGED
|
@@ -6,19 +6,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.UserArg = void 0;
|
|
9
|
+
exports.SessionArg = exports.UserArg = void 0;
|
|
10
10
|
const http_1 = require("@spinajs/http");
|
|
11
11
|
const di_1 = require("@spinajs/di");
|
|
12
12
|
let UserArg = class UserArg extends http_1.RouteArgs {
|
|
13
13
|
get SupportedType() {
|
|
14
|
-
return http_1.ParameterType.
|
|
14
|
+
return http_1.ParameterType.Other;
|
|
15
15
|
}
|
|
16
16
|
async extract(callData, _param, req) {
|
|
17
|
-
return { CallData: callData, Args: req.
|
|
17
|
+
return { CallData: callData, Args: req.storage.user };
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
UserArg = __decorate([
|
|
21
21
|
(0, di_1.Injectable)()
|
|
22
22
|
], UserArg);
|
|
23
23
|
exports.UserArg = UserArg;
|
|
24
|
+
let SessionArg = class SessionArg extends http_1.RouteArgs {
|
|
25
|
+
get SupportedType() {
|
|
26
|
+
throw new Error('Method not implemented.');
|
|
27
|
+
}
|
|
28
|
+
async extract(callData, param, req) {
|
|
29
|
+
return { CallData: callData, Args: req.storage.session ? req.storage.session.Data.get(param.Name) : undefined };
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
SessionArg = __decorate([
|
|
33
|
+
(0, di_1.Injectable)()
|
|
34
|
+
], SessionArg);
|
|
35
|
+
exports.SessionArg = SessionArg;
|
|
24
36
|
//# sourceMappingURL=route-args.js.map
|
package/lib/route-args.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-args.js","sourceRoot":"","sources":["../src/route-args.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wCAAsF;
|
|
1
|
+
{"version":3,"file":"route-args.js","sourceRoot":"","sources":["../src/route-args.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wCAAsF;AACtF,oCAAyC;AAIzC,IAAa,OAAO,GAApB,MAAa,OAAQ,SAAQ,gBAAS;IACpC,IAAW,aAAa;QACtB,OAAO,oBAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,QAAoB,EAAE,MAAuB,EAAE,GAAY;QAC9E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACxD,CAAC;CACF,CAAA;AARY,OAAO;IADnB,IAAA,eAAU,GAAE;GACA,OAAO,CAQnB;AARY,0BAAO;AAWpB,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,gBAAS;IACvC,IAAI,aAAa;QACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACM,KAAK,CAAC,OAAO,CAAC,QAAoB,EAAE,KAAsB,EAAE,GAAY;QAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAClH,CAAC;CACF,CAAA;AAPY,UAAU;IADtB,IAAA,eAAU,GAAE;GACA,UAAU,CAOtB;AAPY,gCAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spinajs/rbac-http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "HTTP API for user session & permissions",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -38,18 +38,19 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/spinajs/main#readme",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@spinajs/configuration": "^
|
|
42
|
-
"@spinajs/di": "^
|
|
43
|
-
"@spinajs/exceptions": "^
|
|
44
|
-
"@spinajs/log": "^
|
|
45
|
-
"@spinajs/orm": "^
|
|
46
|
-
"@spinajs/
|
|
47
|
-
"@spinajs/
|
|
41
|
+
"@spinajs/configuration": "^2.0.12",
|
|
42
|
+
"@spinajs/di": "^2.0.12",
|
|
43
|
+
"@spinajs/exceptions": "^2.0.12",
|
|
44
|
+
"@spinajs/log": "^2.0.14",
|
|
45
|
+
"@spinajs/orm": "^2.0.14",
|
|
46
|
+
"@spinajs/orm-http": "^2.0.15",
|
|
47
|
+
"@spinajs/rbac": "^2.0.14",
|
|
48
|
+
"@spinajs/reflection": "^2.0.14",
|
|
48
49
|
"accesscontrol": "^2.2.1",
|
|
49
50
|
"luxon": "^2.4.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@spinajs/orm-sqlite": "^
|
|
53
|
+
"@spinajs/orm-sqlite": "^2.0.14"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "accb5cda01f335933f681eec75e32ca25fdb8dc7"
|
|
55
56
|
}
|
package/lib/augumentation.d.ts
DELETED
package/lib/augumentation.js
DELETED
package/lib/augumentation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"augumentation.js","sourceRoot":"","sources":["../src/augumentation.ts"],"names":[],"mappings":";;AAAA,yBAAuB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PasswordDto } from './../dto/password-dto';
|
|
2
|
-
import { UserDto } from './../dto/user-dto';
|
|
3
|
-
import * as express from 'express';
|
|
4
|
-
import { BaseController, Ok, NotFound } from '@spinajs/http';
|
|
5
|
-
import { UserDataTransformer, IUserResult } from '../transformers';
|
|
6
|
-
import { SORT_ORDER } from '@spinajs/orm/lib/enums';
|
|
7
|
-
export declare class UsersController extends BaseController {
|
|
8
|
-
protected DataTransformer: UserDataTransformer<IUserResult>;
|
|
9
|
-
listUsers(search: string, page: number, perPage: number, order: string, orderDirection: SORT_ORDER, request: express.Request): Promise<NotFound | Ok>;
|
|
10
|
-
getUser(id: number): Promise<Ok>;
|
|
11
|
-
addUser(user: UserDto): Promise<Ok>;
|
|
12
|
-
deleteUser(id: number): Promise<Ok>;
|
|
13
|
-
updateUser(id: number, user: UserDto): Promise<Ok>;
|
|
14
|
-
updateUserPassword(id: number, pwd: PasswordDto): Promise<Ok>;
|
|
15
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
-
};
|
|
34
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
35
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.UsersController = void 0;
|
|
39
|
-
const password_dto_1 = require("./../dto/password-dto");
|
|
40
|
-
const user_dto_1 = require("./../dto/user-dto");
|
|
41
|
-
const rbac_1 = require("@spinajs/rbac");
|
|
42
|
-
const express = __importStar(require("express"));
|
|
43
|
-
const http_1 = require("@spinajs/http");
|
|
44
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
45
|
-
const orm_1 = require("@spinajs/orm");
|
|
46
|
-
const di_1 = require("@spinajs/di");
|
|
47
|
-
const transformers_1 = require("../transformers");
|
|
48
|
-
const enums_1 = require("@spinajs/orm/lib/enums");
|
|
49
|
-
const luxon_1 = require("luxon");
|
|
50
|
-
const OrderSchema = {
|
|
51
|
-
type: 'string',
|
|
52
|
-
enum: ['asc', 'desc'],
|
|
53
|
-
};
|
|
54
|
-
let UsersController = class UsersController extends http_1.BaseController {
|
|
55
|
-
async listUsers(search, page, perPage, order, orderDirection, request) {
|
|
56
|
-
const query = rbac_1.User.all()
|
|
57
|
-
.whereNull('DeletedAt')
|
|
58
|
-
.skip((page - 1) * perPage)
|
|
59
|
-
.take(perPage)
|
|
60
|
-
.order(order, orderDirection)
|
|
61
|
-
.populate('Metadata');
|
|
62
|
-
const countQuery = rbac_1.User.query().select(new orm_1.RawQuery('count(*) as count')).whereNull('DeletedAt');
|
|
63
|
-
if (search) {
|
|
64
|
-
const searchFunc = function () {
|
|
65
|
-
this.where('Email', 'like', `%${search}%`);
|
|
66
|
-
this.orWhere('Login', 'like', `${search}%`);
|
|
67
|
-
this.orWhere('NiceName', 'like', `%${search}%`);
|
|
68
|
-
};
|
|
69
|
-
query.where(searchFunc);
|
|
70
|
-
countQuery.where(searchFunc);
|
|
71
|
-
}
|
|
72
|
-
const r = await query;
|
|
73
|
-
const c = await countQuery.asRaw();
|
|
74
|
-
if (r.length === 0) {
|
|
75
|
-
return new http_1.NotFound('no users met search criteria');
|
|
76
|
-
}
|
|
77
|
-
return new http_1.Ok(this.DataTransformer.transform({
|
|
78
|
-
Data: r.map((u) => u.dehydrate()),
|
|
79
|
-
Total: c[0].count,
|
|
80
|
-
}, request));
|
|
81
|
-
}
|
|
82
|
-
async getUser(id) {
|
|
83
|
-
const user = await rbac_1.User.where({
|
|
84
|
-
Id: id,
|
|
85
|
-
})
|
|
86
|
-
.whereNull('DeletedAt')
|
|
87
|
-
.populate('Metadata')
|
|
88
|
-
.firstOrFail();
|
|
89
|
-
return new http_1.Ok(user);
|
|
90
|
-
}
|
|
91
|
-
async addUser(user) {
|
|
92
|
-
const password = this._container.resolve(rbac_1.PasswordProvider);
|
|
93
|
-
if (user.Password !== user.ConfirmPassword) {
|
|
94
|
-
throw new exceptions_1.InvalidArgument('password does not match');
|
|
95
|
-
}
|
|
96
|
-
let hashedPassword = '';
|
|
97
|
-
let userPassword = user.Password;
|
|
98
|
-
if (!userPassword) {
|
|
99
|
-
userPassword = password.generate();
|
|
100
|
-
}
|
|
101
|
-
hashedPassword = await password.hash(userPassword);
|
|
102
|
-
const entity = new rbac_1.User({
|
|
103
|
-
Email: user.Email,
|
|
104
|
-
Login: user.Login,
|
|
105
|
-
NiceName: user.NiceName,
|
|
106
|
-
Password: hashedPassword,
|
|
107
|
-
CreatedAt: luxon_1.DateTime.now(),
|
|
108
|
-
Role: user.Role,
|
|
109
|
-
});
|
|
110
|
-
await entity.insert();
|
|
111
|
-
return new http_1.Ok({ Id: entity.Id });
|
|
112
|
-
}
|
|
113
|
-
async deleteUser(id) {
|
|
114
|
-
const entity = await rbac_1.User.getOrFail(id);
|
|
115
|
-
await entity.destroy();
|
|
116
|
-
return new http_1.Ok();
|
|
117
|
-
}
|
|
118
|
-
async updateUser(id, user) {
|
|
119
|
-
var _a;
|
|
120
|
-
const entity = await rbac_1.User.getOrFail(id);
|
|
121
|
-
entity.Email = user.Email;
|
|
122
|
-
entity.NiceName = user.NiceName;
|
|
123
|
-
entity.Login = user.Login;
|
|
124
|
-
entity.Role = (_a = user.Role) !== null && _a !== void 0 ? _a : entity.Role;
|
|
125
|
-
await entity.update();
|
|
126
|
-
return new http_1.Ok();
|
|
127
|
-
}
|
|
128
|
-
async updateUserPassword(id, pwd) {
|
|
129
|
-
if (pwd.Password !== pwd.ConfirmPassword) {
|
|
130
|
-
throw new exceptions_1.InvalidArgument('password does not match');
|
|
131
|
-
}
|
|
132
|
-
const entity = await rbac_1.User.getOrFail(id);
|
|
133
|
-
const password = this._container.resolve(rbac_1.PasswordProvider);
|
|
134
|
-
const hashedPassword = await password.hash(pwd.Password);
|
|
135
|
-
entity.Password = hashedPassword;
|
|
136
|
-
await entity.update();
|
|
137
|
-
return new http_1.Ok();
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
__decorate([
|
|
141
|
-
(0, di_1.Autoinject)(),
|
|
142
|
-
__metadata("design:type", transformers_1.UserDataTransformer)
|
|
143
|
-
], UsersController.prototype, "DataTransformer", void 0);
|
|
144
|
-
__decorate([
|
|
145
|
-
(0, http_1.Get)('/'),
|
|
146
|
-
__param(0, (0, http_1.Query)()),
|
|
147
|
-
__param(1, (0, http_1.Query)({ type: 'number', minimum: 1 })),
|
|
148
|
-
__param(2, (0, http_1.Query)({ type: 'number', minimum: 1 })),
|
|
149
|
-
__param(3, (0, http_1.Query)()),
|
|
150
|
-
__param(4, (0, http_1.Query)(OrderSchema)),
|
|
151
|
-
__param(5, (0, http_1.Req)()),
|
|
152
|
-
__metadata("design:type", Function),
|
|
153
|
-
__metadata("design:paramtypes", [String, Number, Number, String, String, Object]),
|
|
154
|
-
__metadata("design:returntype", Promise)
|
|
155
|
-
], UsersController.prototype, "listUsers", null);
|
|
156
|
-
__decorate([
|
|
157
|
-
(0, http_1.Get)(':id'),
|
|
158
|
-
__param(0, (0, http_1.PKey)()),
|
|
159
|
-
__metadata("design:type", Function),
|
|
160
|
-
__metadata("design:paramtypes", [Number]),
|
|
161
|
-
__metadata("design:returntype", Promise)
|
|
162
|
-
], UsersController.prototype, "getUser", null);
|
|
163
|
-
__decorate([
|
|
164
|
-
(0, http_1.Post)('/'),
|
|
165
|
-
__param(0, (0, http_1.Body)()),
|
|
166
|
-
__metadata("design:type", Function),
|
|
167
|
-
__metadata("design:paramtypes", [user_dto_1.UserDto]),
|
|
168
|
-
__metadata("design:returntype", Promise)
|
|
169
|
-
], UsersController.prototype, "addUser", null);
|
|
170
|
-
__decorate([
|
|
171
|
-
(0, http_1.Del)(':id'),
|
|
172
|
-
__param(0, (0, http_1.PKey)()),
|
|
173
|
-
__metadata("design:type", Function),
|
|
174
|
-
__metadata("design:paramtypes", [Number]),
|
|
175
|
-
__metadata("design:returntype", Promise)
|
|
176
|
-
], UsersController.prototype, "deleteUser", null);
|
|
177
|
-
__decorate([
|
|
178
|
-
(0, http_1.Put)(':id'),
|
|
179
|
-
__param(0, (0, http_1.PKey)()),
|
|
180
|
-
__param(1, (0, http_1.Body)()),
|
|
181
|
-
__metadata("design:type", Function),
|
|
182
|
-
__metadata("design:paramtypes", [Number, user_dto_1.UserDto]),
|
|
183
|
-
__metadata("design:returntype", Promise)
|
|
184
|
-
], UsersController.prototype, "updateUser", null);
|
|
185
|
-
__decorate([
|
|
186
|
-
(0, http_1.Put)(':id/change-password'),
|
|
187
|
-
__param(0, (0, http_1.PKey)()),
|
|
188
|
-
__param(1, (0, http_1.Body)()),
|
|
189
|
-
__metadata("design:type", Function),
|
|
190
|
-
__metadata("design:paramtypes", [Number, password_dto_1.PasswordDto]),
|
|
191
|
-
__metadata("design:returntype", Promise)
|
|
192
|
-
], UsersController.prototype, "updateUserPassword", null);
|
|
193
|
-
UsersController = __decorate([
|
|
194
|
-
(0, http_1.BasePath)('users')
|
|
195
|
-
], UsersController);
|
|
196
|
-
exports.UsersController = UsersController;
|
|
197
|
-
//# sourceMappingURL=UsersController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UsersController.js","sourceRoot":"","sources":["../../src/controllers/UsersController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAoD;AACpD,gDAA4C;AAC5C,wCAAuD;AACvD,iDAAmC;AACnC,wCAAoH;AACpH,oDAAsD;AACtD,sCAAwC;AACxC,oCAAyC;A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