Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
b1acksun committed Mar 31, 2020
2 parents 6a9edbd + d3dc8b8 commit 742f3f2
Show file tree
Hide file tree
Showing 11 changed files with 656 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ GLS_METRICS_PORT=9777
GLS_CONNECTOR_HOST=0.0.0.0
GLS_CONNECTOR_PORT=3000
GLS_SMS_CONNECT=
GLS_EMAIL_CONNECT=
CYBERWAY_HTTP_URL=
GLS_IS_REG_ENABLED_ON_START=true
SKIP_SMS_VERIFICATION_CODE_SEND=false
GLS_SMS_VERIFY_EXPIRATION_HOURS=1
GLS_SMS_RESEND_CODE_TIMEOUT=45000
GLS_SMS_RESEND_CODE_MAX=3
GLS_EMAIL_RESEND_CODE_TIMEOUT=45000
GLS_EMAIL_RESEND_CODE_MAX=3
GLS_EMAIL_CODE_LENGTH=6
GLS_CAPTCHA_ON=true
WEB_CAPTCHA_SECRET=
IOS_CAPTCHA_SECRET=
Expand Down
192 changes: 190 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,36 @@ onboardingSharedLink: // Шаг процесса онб
}
```

```json
{
"id": 1,
"method": "getState",
"jsonrpc": "2.0",
"params": {
"identity": "<id из oauth-service>"
}
}
```

```json
{
"id": 1,
"method": "getState",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]"
}
}
```

<= Ответ

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"currentState": "(firstStep|verify|setUsername|toBlockChain|registered)"
"currentState": "(firstStep|verify|firstStepEmail|verifyEmail|createIdentity|setUsername|toBlockChain|registered)"
}
}
```
Expand All @@ -78,7 +100,8 @@ onboardingSharedLink: // Шаг процесса онб
"jsonrpc": "2.0",
"params": {
"phone": "+380000000000",
"captcha": "captcha code"
"captcha": "captcha code",
"captchaType": "(web|android|ios)"
}
}
```
Expand Down Expand Up @@ -177,6 +200,117 @@ onboardingSharedLink: // Шаг процесса онб
| 1107 | Try later | Try later |
| 1108 | Too many retries | Too many retries |

### firstStepEmail

=> Запрос

```json
{
"id": 1,
"method": "firstStepEmail",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]",
"captcha": "captcha code",
"captchaType": "(web|android|ios)"
}
}
```

<= Ответ

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"nextEmailRetry": "2019-10-15T07:57:43.879Z",
"currentState": "verifyEmail"
}
}
```

Ошибки

| Code  | Message | Описание  |
| ----- | -------------------------- | ------------------------ |
| 1101 | Account already registered | Аккаунт зарегестрирован |
| 1102 | Invalid step taken | Неверный шаг регистрации |
| 1103 | Recaptcha check failed | Ошибка проверки каптчи |

### verifyEmail

=> Запрос

```json
{
"id": 1,
"method": "verifyEmail",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]",
"code": "<code>"
}
}
```

<= Ответ

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"currentState": "setUsername"
}
}
```

Ошибки

| Code  | Message | Описание  |
| ----- | -------------------------- | ------------------------ |
| 1101 | Account already registered | Аккаунт зарегестрирован |
| 1102 | Invalid step taken | Неверный шаг регистрации |
| 1104 | Wrong activation code | Неверный код верификации |

### resendEmailCode

=> Запрос

```json
{
"id": 1,
"method": "resendEmailCode",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]"
}
}
```

<= Ответ

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"nextEmailRetry": "2019-10-15T07:57:43.879Z",
"currentState": "verifyEmail"
}
}
```

Ошибки

| Code  | Message | Описание  |
| ----- | -------------------------- | ------------------------ |
| 1101 | Account already registered | Аккаунт зарегестрирован |
| 1102 | Invalid step taken | Неверный шаг регистрации |
| 1107 | Try later | Try later |
| 1108 | Too many retries | Too many retries |

### setUsername

=> Запрос
Expand All @@ -193,6 +327,30 @@ onboardingSharedLink: // Шаг процесса онб
}
```

```json
{
"id": 1,
"method": "setUsername",
"jsonrpc": "2.0",
"params": {
"identity": "<id из oauth-service>",
"username": "some-user-name"
}
}
```

```json
{
"id": 1,
"method": "setUsername",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]",
"username": "some-user-name"
}
}
```

<= Ответ

```json
Expand Down Expand Up @@ -233,6 +391,36 @@ onboardingSharedLink: // Шаг процесса онб
}
```

```json
{
"id": 1,
"method": "toBlockChain",
"jsonrpc": "2.0",
"params": {
"identity": "<id из oauth-service>",
"username": "some-user-name",
"userId": "<userId c шага setUsername>",
"publicOwnerKey": "GLS8Bb....",
"publicActiveKey": "GLS35B...."
}
}
```

```json
{
"id": 1,
"method": "toBlockChain",
"jsonrpc": "2.0",
"params": {
"email": "[email protected]",
"username": "some-user-name",
"userId": "<userId c шага setUsername>",
"publicOwnerKey": "GLS8Bb....",
"publicActiveKey": "GLS35B...."
}
}
```

<= Ответ

```json
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.5.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "registration-service",
"version": "1.4.0",
"version": "1.5.0",
"description": "Commun registration service",
"main": "./src/index.js",
"scripts": {
Expand Down
62 changes: 60 additions & 2 deletions src/controllers/Referral.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const core = require('cyberway-core-service');
const { Basic } = core.controllers;
const { Logger } = core.utils;

const User = require('../models/User');
const UserModel = require('../models/User');

class Referral extends Basic {
async getReferralUsers({ offset, limit }, auth, clientInfo) {
Expand All @@ -13,7 +13,7 @@ class Referral extends Basic {
};
}

const user = await User.findOne(
const user = await UserModel.findOne(
{ userId: auth.userId },
{ _id: false, referrals: true },
{ lean: false }
Expand Down Expand Up @@ -41,6 +41,64 @@ class Referral extends Basic {
clientInfo
);
}

async getReferralParent({ userId }) {
const user = await UserModel.findOne(
{
userId,
isRegistered: true,
},
{
_id: false,
userId: true,
username: true,
referralId: true,
},
{
lean: true,
}
);

if (!user) {
throw {
code: 404,
message: 'Requested user is not found',
};
}

if (!user.referralId) {
return {
user,
referralParent: null,
};
}

const referralParent = await UserModel.findOne(
{
userId: user.referralId,
},
{
_id: false,
userId: true,
username: true,
},
{
lean: true,
}
);

if (!referralParent) {
throw {
code: 500,
message: 'Invalid database state',
};
}

return {
user,
referralParent,
};
}
}

module.exports = Referral;
Loading

0 comments on commit 742f3f2

Please sign in to comment.