diff --git a/admin/.env.dist b/admin/.env.dist index 66c84dda8..d7044669a 100644 --- a/admin/.env.dist +++ b/admin/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + GRAPHQL_URI=http://localhost:4000/graphql WALLET_AUTH_URL=http://localhost/authenticate?token={token} WALLET_URL=http://localhost/login diff --git a/admin/.env.template b/admin/.env.template index a965b1bb1..488c9aba4 100644 --- a/admin/.env.template +++ b/admin/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$ADMIN_CONFIG_VERSION + GRAPHQL_URI=$GRAPHQL_URI WALLET_AUTH_URL=$WALLET_AUTH_URL WALLET_URL=$WALLET_URL diff --git a/admin/src/config/index.js b/admin/src/config/index.js index f7d361c12..fe373386d 100644 --- a/admin/src/config/index.js +++ b/admin/src/config/index.js @@ -4,11 +4,20 @@ // Load Package Details for some default values const pkg = require('../../package') +const constants = { + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, +} + const version = { APP_VERSION: pkg.version, BUILD_COMMIT: process.env.BUILD_COMMIT || null, // self reference of `version.BUILD_COMMIT` is not possible at this point, hence the duplicate code - BUILD_COMMIT_SHORT: (process.env.BUILD_COMMIT || '0000000').substr(0, 7), + BUILD_COMMIT_SHORT: (process.env.BUILD_COMMIT || '0000000').slice(0, 7), + PORT: process.env.PORT || 8080, } const environment = { @@ -27,14 +36,24 @@ const debug = { DEBUG_DISABLE_AUTH: process.env.DEBUG_DISABLE_AUTH === 'true' || false, } -const options = {} +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} const CONFIG = { + ...constants, ...version, ...environment, ...endpoints, - ...options, ...debug, } -export default CONFIG +module.exports = CONFIG diff --git a/admin/vue.config.js b/admin/vue.config.js index 4492312a0..8cc1e4b89 100644 --- a/admin/vue.config.js +++ b/admin/vue.config.js @@ -2,11 +2,12 @@ const path = require('path') const webpack = require('webpack') const Dotenv = require('dotenv-webpack') const StatsPlugin = require('stats-webpack-plugin') +const CONFIG = require('./src/config') // vue.config.js module.exports = { devServer: { - port: process.env.PORT || 8080, + port: CONFIG.PORT, }, pluginOptions: { i18n: { @@ -34,7 +35,7 @@ module.exports = { // 'process.env.DOCKER_WORKDIR': JSON.stringify(process.env.DOCKER_WORKDIR), // 'process.env.BUILD_DATE': JSON.stringify(process.env.BUILD_DATE), // 'process.env.BUILD_VERSION': JSON.stringify(process.env.BUILD_VERSION), - 'process.env.BUILD_COMMIT': JSON.stringify(process.env.BUILD_COMMIT), + 'process.env.BUILD_COMMIT': JSON.stringify(CONFIG.BUILD_COMMIT), // 'process.env.PORT': JSON.stringify(process.env.PORT), }), // generate webpack stats to allow analysis of the bundlesize @@ -46,7 +47,7 @@ module.exports = { }, css: { // Enable CSS source maps. - sourceMap: process.env.NODE_ENV !== 'production', + sourceMap: CONFIG.NODE_ENV !== 'production', }, outputDir: path.resolve(__dirname, './dist'), } diff --git a/backend/.env.dist b/backend/.env.dist index 3c93f1576..b8a3d5dbe 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + # Server PORT=4000 JWT_SECRET=secret123 @@ -38,8 +40,8 @@ EMAIL_SENDER=info@gradido.net EMAIL_PASSWORD=xxx EMAIL_SMTP_URL=gmail.com EMAIL_SMTP_PORT=587 -EMAIL_LINK_VERIFICATION=http://localhost/checkEmail/{code} -EMAIL_LINK_SETPASSWORD=http://localhost/reset/{code} +EMAIL_LINK_VERIFICATION=http://localhost/checkEmail/{optin}{code} +EMAIL_LINK_SETPASSWORD=http://localhost/reset/{optin} EMAIL_CODE_VALID_TIME=10 # Webhook diff --git a/backend/.env.template b/backend/.env.template index b3a5eb4c6..454b25d3c 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$BACKEND_CONFIG_VERSION + # Server JWT_SECRET=$JWT_SECRET JWT_EXPIRES_IN=10m diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 754bfbf08..dcfea2bdb 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,6 +12,11 @@ Decimal.set({ const constants = { DB_VERSION: '0033-add_referrer_id', DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0 + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, } const server = { @@ -62,9 +67,9 @@ const email = { EMAIL_SMTP_URL: process.env.EMAIL_SMTP_URL || 'gmail.com', EMAIL_SMTP_PORT: process.env.EMAIL_SMTP_PORT || '587', EMAIL_LINK_VERIFICATION: - process.env.EMAIL_LINK_VERIFICATION || 'http://localhost/checkEmail/{code}', + process.env.EMAIL_LINK_VERIFICATION || 'http://localhost/checkEmail/{optin}{code}', EMAIL_LINK_SETPASSWORD: - process.env.EMAIL_LINK_SETPASSWORD || 'http://localhost/reset-password/{code}', + process.env.EMAIL_LINK_SETPASSWORD || 'http://localhost/reset-password/{optin}', EMAIL_CODE_VALID_TIME: process.env.EMAIL_CODE_VALID_TIME ? parseInt(process.env.EMAIL_CODE_VALID_TIME) || 10 : 10, @@ -78,6 +83,18 @@ const webhook = { // This is needed by graphql-directive-auth process.env.APP_SECRET = server.JWT_SECRET +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} + const CONFIG = { ...constants, ...server, diff --git a/backend/src/graphql/arg/CreateUserArgs.ts b/backend/src/graphql/arg/CreateUserArgs.ts index 0d63e76bb..af915b91a 100644 --- a/backend/src/graphql/arg/CreateUserArgs.ts +++ b/backend/src/graphql/arg/CreateUserArgs.ts @@ -16,4 +16,7 @@ export default class CreateUserArgs { @Field(() => Int, { nullable: true }) publisherId: number + + @Field(() => String, { nullable: true }) + redeemCode?: string | null } diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index f873fd694..53f39668e 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -124,7 +124,10 @@ describe('UserResolver', () => { describe('account activation email', () => { it('sends an account activation email', () => { - const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace(/{code}/g, emailOptIn) + const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( + /{optin}/g, + emailOptIn, + ).replace(/{code}/g, '') expect(sendAccountActivationEmail).toBeCalledWith({ link: activationLink, firstName: 'Peter', diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a56b67945..b24aa1b58 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -7,6 +7,7 @@ import { getConnection, getCustomRepository, QueryRunner } from '@dbTools/typeor import CONFIG from '@/config' import { User } from '@model/User' import { User as DbUser } from '@entity/User' +import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' import { encode } from '@/auth/JWT' import CreateUserArgs from '@arg/CreateUserArgs' import UnsecureLoginArgs from '@arg/UnsecureLoginArgs' @@ -305,7 +306,8 @@ export class UserResolver { @Authorized([RIGHTS.CREATE_USER]) @Mutation(() => User) async createUser( - @Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs, + @Args() + { email, firstName, lastName, language, publisherId, redeemCode = null }: CreateUserArgs, ): Promise { // TODO: wrong default value (should be null), how does graphql work here? Is it an required field? // default int publisher_id = 0; @@ -338,6 +340,12 @@ export class UserResolver { dbUser.language = language dbUser.publisherId = publisherId dbUser.passphrase = passphrase.join(' ') + if (redeemCode) { + const transactionLink = await dbTransactionLink.findOne({ code: redeemCode }) + if (transactionLink) { + dbUser.referrerId = transactionLink.userId + } + } // TODO this field has no null allowed unlike the loginServer table // dbUser.pubKey = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000... // dbUser.pubkey = keyPair[0] @@ -360,9 +368,9 @@ export class UserResolver { const emailOptIn = await createEmailOptIn(dbUser.id, queryRunner) const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( - /{code}/g, + /{optin}/g, emailOptIn.verificationCode.toString(), - ) + ).replace(/{code}/g, redeemCode ? '/' + redeemCode : '') // eslint-disable-next-line @typescript-eslint/no-unused-vars const emailSent = await sendAccountActivationEmail({ @@ -379,6 +387,7 @@ export class UserResolver { console.log(`Account confirmation link: ${activationLink}`) } */ + await queryRunner.commitTransaction() } catch (e) { await queryRunner.rollbackTransaction() @@ -404,7 +413,7 @@ export class UserResolver { const emailOptIn = await createEmailOptIn(user.id, queryRunner) const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( - /{code}/g, + /{optin}/g, emailOptIn.verificationCode.toString(), ) @@ -443,7 +452,7 @@ export class UserResolver { const optInCode = await getOptInCode(user.id) const link = CONFIG.EMAIL_LINK_SETPASSWORD.replace( - /{code}/g, + /{optin}/g, optInCode.verificationCode.toString(), ) diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index f68d983c0..298d56bdb 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -45,6 +45,7 @@ export const createUser = gql` $email: String! $language: String! $publisherId: Int + $redeemCode: String ) { createUser( email: $email @@ -52,6 +53,7 @@ export const createUser = gql` lastName: $lastName language: $language publisherId: $publisherId + redeemCode: $redeemCode ) { id } diff --git a/database/.env.dist b/database/.env.dist index 689e4f509..58362a7b9 100644 --- a/database/.env.dist +++ b/database/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + DB_HOST=localhost DB_PORT=3306 DB_USER=root diff --git a/database/.env.template b/database/.env.template index 5b8554bcf..f2517a397 100644 --- a/database/.env.template +++ b/database/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$DATABASE_CONFIG_VERSION + DB_HOST=localhost DB_PORT=3306 DB_USER=$DB_USER diff --git a/database/src/config/index.ts b/database/src/config/index.ts index 2dde06c96..ba41f11d4 100644 --- a/database/src/config/index.ts +++ b/database/src/config/index.ts @@ -3,6 +3,14 @@ import dotenv from 'dotenv' dotenv.config() +const constants = { + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, +} + const database = { DB_HOST: process.env.DB_HOST || 'localhost', DB_PORT: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306, @@ -15,6 +23,18 @@ const migrations = { MIGRATIONS_TABLE: process.env.MIGRATIONS_TABLE || 'migrations', } -const CONFIG = { ...database, ...migrations } +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} + +const CONFIG = { ...constants, ...database, ...migrations } export default CONFIG diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 9a9d57b4c..ee0ac3cc3 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -18,6 +18,8 @@ WEBHOOK_GITHUB_SECRET=secret WEBHOOK_GITHUB_BRANCH=master # backend +BACKEND_CONFIG_VERSION=v1.2022-03-18 + EMAIL=true EMAIL_USERNAME=peter@lustig.de EMAIL_SENDER=peter@lustig.de @@ -43,6 +45,9 @@ KLICKTIPP_PASSWORD= KLICKTIPP_APIKEY_DE= KLICKTIPP_APIKEY_EN= +# database +DATABASE_CONFIG_VERSION=v1.2022-03-18 + # frontend GRAPHQL_URI=https://stage1.gradido.net/graphql ADMIN_AUTH_URL=https://stage1.gradido.net/admin/authenticate?token={token} diff --git a/frontend/.env.dist b/frontend/.env.dist index 0de8c6252..df3c7cd7e 100644 --- a/frontend/.env.dist +++ b/frontend/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + META_URL=http://localhost META_TITLE_DE="Gradido – Dein Dankbarkeitskonto" META_TITLE_EN="Gradido - Your gratitude account" diff --git a/frontend/.env.template b/frontend/.env.template index 1eef43cef..4e4a86d08 100644 --- a/frontend/.env.template +++ b/frontend/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$FRONTEND_CONFIG_VERSION + META_URL=$META_URL META_TITLE_DE=$META_TITLE_DE META_TITLE_EN=$META_TITLE_EN diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index ec4aff4d3..c1acf9925 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -160,15 +160,18 @@ export default { }, props: { balance: { type: Number, default: 0 }, + email: { type: String, default: '' }, + amount: { type: Number, default: 0 }, + memo: { type: String, default: '' }, }, data() { return { amountFocused: false, emailFocused: false, form: { - email: '', - amount: '', - memo: '', + email: this.email, + amount: this.amount ? String(this.amount) : '', + memo: this.memo, amountValue: 0.0, }, selected: SEND_TYPES.send, diff --git a/frontend/src/components/GddSend/TransactionResultSendError.vue b/frontend/src/components/GddSend/TransactionResultSendError.vue index daa593aec..6a3761092 100644 --- a/frontend/src/components/GddSend/TransactionResultSendError.vue +++ b/frontend/src/components/GddSend/TransactionResultSendError.vue @@ -31,7 +31,7 @@ diff --git a/frontend/src/pages/thx.vue b/frontend/src/pages/thx.vue index 4a86212c9..736e0c70e 100644 --- a/frontend/src/pages/thx.vue +++ b/frontend/src/pages/thx.vue @@ -9,7 +9,11 @@

{{ $t(displaySetup.subtitle) }}


- + + + {{ $t(displaySetup.button) }} + + {{ $t(displaySetup.button) }} diff --git a/frontend/src/routes/router.test.js b/frontend/src/routes/router.test.js index 85f765c69..925b3ffca 100644 --- a/frontend/src/routes/router.test.js +++ b/frontend/src/routes/router.test.js @@ -112,7 +112,7 @@ describe('router', () => { }) describe('thx', () => { - const thx = routes.find((r) => r.path === '/thx/:comingFrom') + const thx = routes.find((r) => r.path === '/thx/:comingFrom/:code?') it('loads the "Thx" page', async () => { const component = await thx.component() @@ -177,7 +177,9 @@ describe('router', () => { describe('checkEmail', () => { it('loads the "CheckEmail" page', async () => { - const component = await routes.find((r) => r.path === '/checkEmail/:optin').component() + const component = await routes + .find((r) => r.path === '/checkEmail/:optin/:code?') + .component() expect(component.default.name).toBe('ResetPassword') }) }) diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index 5e0b09c5e..a6586c201 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -47,7 +47,7 @@ const routes = [ component: () => import('@/pages/Register.vue'), }, { - path: '/thx/:comingFrom', + path: '/thx/:comingFrom/:code?', component: () => import('@/pages/thx.vue'), beforeEnter: (to, from, next) => { const validFrom = ['forgot-password', 'reset-password', 'register', 'login', 'checkEmail'] @@ -79,7 +79,7 @@ const routes = [ component: () => import('@/pages/ResetPassword.vue'), }, { - path: '/checkEmail/:optin', + path: '/checkEmail/:optin/:code?', component: () => import('@/pages/ResetPassword.vue'), }, { diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 4c86a7a6d..573f2a70b 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -3,11 +3,12 @@ const webpack = require('webpack') const Dotenv = require('dotenv-webpack') const StatsPlugin = require('stats-webpack-plugin') const HtmlWebpackPlugin = require('vue-html-webpack-plugin') +const CONFIG = require('./src/config') // vue.config.js module.exports = { devServer: { - port: process.env.PORT || 3000, + port: CONFIG.PORT, }, pluginOptions: { i18n: { @@ -35,7 +36,7 @@ module.exports = { // 'process.env.DOCKER_WORKDIR': JSON.stringify(process.env.DOCKER_WORKDIR), // 'process.env.BUILD_DATE': JSON.stringify(process.env.BUILD_DATE), // 'process.env.BUILD_VERSION': JSON.stringify(process.env.BUILD_VERSION), - 'process.env.BUILD_COMMIT': JSON.stringify(process.env.BUILD_COMMIT), + 'process.env.BUILD_COMMIT': JSON.stringify(CONFIG.BUILD_COMMIT), // 'process.env.PORT': JSON.stringify(process.env.PORT), }), // generate webpack stats to allow analysis of the bundlesize @@ -44,14 +45,14 @@ module.exports = { vue: true, template: 'public/index.html', meta: { - title_de: process.env.META_TITLE_DE, - title_en: process.env.META_TITLE_EN, - description_de: process.env.META_DESCRIPTION_DE, - description_en: process.env.META_DESCRIPTION_EN, - keywords_de: process.env.META_KEYWORDS_DE, - keywords_en: process.env.META_KEYWORDS_EN, - author: process.env.META_AUTHOR, - url: process.env.META_URL, + title_de: CONFIG.META_TITLE_DE, + title_en: CONFIG.META_TITLE_EN, + description_de: CONFIG.META_DESCRIPTION_DE, + description_en: CONFIG.META_DESCRIPTION_EN, + keywords_de: CONFIG.META_KEYWORDS_DE, + keywords_en: CONFIG.META_KEYWORDS_EN, + author: CONFIG.META_AUTHOR, + url: CONFIG.META_URL, }, }), ], @@ -61,7 +62,7 @@ module.exports = { }, css: { // Enable CSS source maps. - sourceMap: process.env.NODE_ENV !== 'production', + sourceMap: CONFIG.NODE_ENV !== 'production', }, outputDir: path.resolve(__dirname, './dist'), }