Skip to content

Commit

Permalink
Add ability to customize a notification for individual user. Closes #19
Browse files Browse the repository at this point in the history
Add ability to customize an action verification for individual user.
Refactor common middlewares.
Rename 2fa to google auth.
  • Loading branch information
AlekNS committed Feb 7, 2018
1 parent ba15b27 commit 40c190c
Show file tree
Hide file tree
Showing 29 changed files with 792 additions and 450 deletions.
87 changes: 87 additions & 0 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,93 @@ Authentication attempts with not verified token will result in 401 response.
"error": "User is not found"
}
## Disable notifications [/user/preferences/disableNotifications]
### Disable notifications [POST]
+ disableNotifications (required, array of string). Allowed values: user_signin, user_change_password, user_reset_password.
+ Request (application/json)
+ Headers
Authorization: Bearer token
Accept: application/json
+ Body
{
"disableNotifications": ["user_signin"]
}
+ Response 200 (application/json)
{
"disabledNotifications": ["user_signin"]
}
## Initiate disable of verifications [user/preferences/disableVerifications/initiate]
When verification is disabled the method in { verification : { verificationId: '...', method: 'inline' } will be `inline` only.
For inline method you should pass any code (random) for verify action.
### Initiate disable of verifications [POST]
+ disableVerifications (required, array of string). Allowed values: user_signin, user_change_password, transaction_send.
+ Request (application/json)
+ Headers
Authorization: Bearer token
Accept: application/json
+ Body
{
"disableVerifications": ["user_signin"]
}
+ Response 200 (application/json)
{
"verification": {
"verificationId": "8f9ba03c-e903-459c-adb9-7594865a03a4",
"method": "email"
}
}
## Verify disable of verifications [user/preferences/disableVerifications/verify]
+ verification
+ verificationId `UUID` (required, string)
+ code `000000` (required, string)
### Verify disable of verifications [POST]
+ Request (application/json)
+ Headers
Authorization: Bearer token
Accept: application/json
+ Body
{
"verification": {
"verificationId": "b41498d8-a9db-4bb5-b338-0e8f47582066",
"code": "813365"
}
}
+ Response 200 (application/json)
{
"disabledVerifications": ["user_signin"]
}
## Initiate enable 2FA [/user/enable2fa/initiate]
Expand Down
41 changes: 36 additions & 5 deletions src/controllers/dashboard.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as Joi from 'joi';
import { Request, Response, NextFunction } from 'express';
import { inject } from 'inversify';
import { controller, httpPost, httpGet } from 'inversify-express-utils';
import { NOT_FOUND } from 'http-status';

import { AuthenticatedRequest } from '../interfaces';
import { responseWith } from '../helpers/responses';
import { NOT_FOUND } from 'http-status';

import { DashboardApplicationType, DashboardApplication } from '../services/app/dashboard.app';
import { TransactionApplicationType, TransactionApplication } from '../services/app/transaction.app';
import { commonFlowRequestMiddleware, ethereumAddressValidator } from '../middlewares/request.validation';

/**
* Dashboard controller
Expand All @@ -33,9 +35,18 @@ export class DashboardController {
res.json(await this.dashboardApp.balancesFor(req.app.locals.user));
}

/**
*
* @param req
* @param res
*/
@httpGet(
'/transactionFee',
'TransactionFeeValidation'
(req, res, next) => {
commonFlowRequestMiddleware(Joi.object().keys({
gas: Joi.string().required()
}), req.query, res, next);
}
)
async getCurrentInvestFee(req: Request, res: Response): Promise<void> {
res.json(await this.transactionApp.getTransactionFee(req.query.gas));
Expand All @@ -56,13 +67,17 @@ export class DashboardController {
*/
@httpGet(
'/erc20TokenInfo',
'Erc20TokenInfoValidation'
(req, res, next) => {
commonFlowRequestMiddleware(Joi.object().keys({
contractAddress: ethereumAddressValidator.required()
}), req.query, res, next);
}
)
async getErc20TokenInfo(req: AuthenticatedRequest & Request, res: Response, next: NextFunction): Promise<void> {
const result = await this.dashboardApp.getErc20TokenInfo(req.query.contractAddress);
if (!result) {
responseWith(res, {
message: "Information is unavailable"
message: 'Information is unavailable'
}, NOT_FOUND);
} else {
res.json(result);
Expand All @@ -77,7 +92,17 @@ export class DashboardController {
*/
@httpPost(
'/transaction/initiate',
'TransactionSendValidation'
(req, res, next) => {
commonFlowRequestMiddleware(Joi.object().keys({
to: ethereumAddressValidator.required(),
type: Joi.string().valid('eth_transfer', 'erc20_transfer').required(),
contractAddress: ethereumAddressValidator.optional(),
amount: Joi.number().required().min(1e-10),
gas: Joi.string().optional(),
gasPrice: Joi.string().optional(),
paymentPassword: Joi.string().required()
}), req.body, res, next);
}
)
async transactionInitiate(req: AuthenticatedRequest & Request, res: Response, next: NextFunction): Promise<void> {
res.json({
Expand All @@ -93,6 +118,12 @@ export class DashboardController {
});
}

/**
*
* @param req
* @param res
* @param next
*/
@httpPost(
'/transaction/verify',
'VerificationRequiredValidation'
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/metrics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { PrometheusMetrics } from '../services/metrics/prometheus.service';
'MetricsBasicHttpAuth'
)
export class MetricsController {
/**
*
* @param req
* @param res
*/
@httpGet(
'/prometheus'
)
Expand Down
Loading

0 comments on commit 40c190c

Please sign in to comment.