diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index de7ed6ee6..1e8d53acc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -147,7 +147,7 @@ jobs: ########################################################################## - name: mariadb | Build `test` image run: | - docker build --target mariadb_server_test -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ + docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ docker save "gradido/mariadb:test" > /tmp/mariadb.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -344,7 +344,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 83 + min_coverage: 85 token: ${{ github.token }} ############################################################################## @@ -353,7 +353,7 @@ jobs: unit_test_backend: name: Unit tests - Backend runs-on: ubuntu-latest - needs: [build_test_backend] + needs: [build_test_backend,build_test_mariadb] steps: ########################################################################## # CHECKOUT CODE ########################################################## @@ -363,6 +363,13 @@ jobs: ########################################################################## # DOWNLOAD DOCKER IMAGES ################################################# ########################################################################## + - name: Download Docker Image (Mariadb) + uses: actions/download-artifact@v2 + with: + name: docker-mariadb-test + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/mariadb.tar - name: Download Docker Image (Backend) uses: actions/download-artifact@v2 with: @@ -373,10 +380,11 @@ jobs: ########################################################################## # UNIT TESTS BACKEND ##################################################### ########################################################################## - - name: backend | Unit tests - run: | - docker run -v ~/coverage:/app/coverage --rm gradido/backend:test yarn run test - cp -r ~/coverage ./coverage + - name: backend | docker-compose + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb database + - name: backend Unit tests | test + run: cd database && yarn && cd ../backend && yarn && yarn test + # run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T backend yarn test ########################################################################## # COVERAGE CHECK BACKEND ################################################# ########################################################################## @@ -385,8 +393,8 @@ jobs: with: report_name: Coverage Backend type: lcov - result_path: ./coverage/lcov.info - min_coverage: 1 + result_path: ./backend/coverage/lcov.info + min_coverage: 45 token: ${{ github.token }} ############################################################################## @@ -409,10 +417,16 @@ jobs: --health-timeout=3s --health-retries=4 steps: - - name: Debug service - run: echo "$(docker ps)" - - name: Debug container choosing script - run: echo "$(docker container ls | grep mariadb | awk '{ print $1 }')" + # - name: Debug service + # run: echo "$(docker ps)" + #- name: Debug container choosing script + # run: echo "$(docker container ls | grep mariadb | awk '{ print $1 }')" + - name: get mariadb container id + run: echo "::set-output name=id::$(docker container ls | grep mariadb | awk '{ print $1 }')" + id: mariadb_container + - name: get automatic created network + run: echo "::set-output name=id::$(docker network ls | grep github_network | awk '{ print $1 }')" + id: network ########################################################################## # CHECKOUT CODE ########################################################## ########################################################################## @@ -420,6 +434,11 @@ jobs: uses: actions/checkout@v2 with: submodules: true + # Database migration + - name: Start database migration + run: | + docker build --target production_up -t "gradido/database:production_up" database/ + docker run --network ${{ steps.network.outputs.id }} --name=database --env NODE_ENV=production --env DB_HOST=mariadb --env DB_DATABASE=gradido_community_test -d gradido/database:production_up ########################################################################## # Build Login-Server Test Docker image ################################### ########################################################################## diff --git a/.gitignore b/.gitignore index caed320af..c09811443 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ /node_modules/* .vscode messages.pot -.skeema nbproject .metadata /.env diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..a6dc06683 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "streetsidesoftware.code-spell-checker", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index fe6f2e7f3..ead54701c 100644 --- a/README.md +++ b/README.md @@ -8,33 +8,73 @@ The Gradido model can create global prosperity and peace The Corona crisis has fundamentally changed our world within a very short time. The dominant financial system threatens to fail around the globe, followed by mass insolvencies, record unemployment and abject poverty. Only with a sustainable new monetary system can humanity master these challenges of the 21st century. The Gradido Academy for Bionic Economy has developed such a system. +Find out more about the Project on its [Website](https://gradido.net/). It is offering vast resources about the idea. The remaining document will discuss the gradido software only. ## Software requirements -Currently we only support `docker` as environment to run all services, since many different programming languages and frameworks are used. +Currently we only support `docker` install instructions to run all services, since many different programming languages and frameworks are used. -- [docker](https://www.docker.com/) +- [docker](https://www.docker.com/) +- [docker-compose] + +### For Arch Linux +Install the required packages: +```bash +sudo pacman -S docker +sudo pacman -S docker-compose +``` + +Add group `docker` and then your user to it in order to allow you to run docker without sudo +```bash +sudo groupadd docker # may already exist `groupadd: group 'docker' already exists` +sudo usermod -aG docker $USER +groups # verify you have the group (requires relog) +``` + +Start the docker service: +```bash +sudo systemctrl start docker +``` ## How to run? -1. Clone the repo and pull all submodules - +### 1. Clone Sources +Clone the repo and pull all submodules ```bash git clone git@github.com:gradido/gradido.git git submodule update --recursive --init ``` -2. Run docker compose - 1. Run docker compose for the debug build +### 2. Run docker-compose +Run docker-compose to bring up the development environment +```bash +docker-compose up +``` +### Additional Build options +If you want to build for production you can do this aswell: +```bash +docker-compose -f docker-compose.yml up +``` - ```bash - docker-compose up - ``` +## Services defined in this package - 2. Or run docker compose in production build +- [frontend](./frontend) Wallet frontend +- [backend](./backend) GraphQL & Business logic backend +- [mariadb](./mariadb) Database backend +- [login_server](./login_server) User credential storage & business logic backend +- [community_server](./community_server/) Business logic backend - ```bash - docker-compose -f docker-compose.yml up - ``` +We are currently restructuring the service to reduce dependencies and unify business logic into one place. Furthermore the databases defined for each service will be unified into one. + +### Open the wallet + +Once you have `docker-compose` up and running, you can open [http://localhost/vue](http://localhost/vue) and create yourself a new wallet account. + +## Troubleshooting + +| Problem | Issue | Solution | Description | +| ------- | ----- | -------- | ----------- | +| docker-compose raises database connection errors | [#1062](https://github.com/gradido/gradido/issues/1062) | End `ctrl+c` and restart the `docker-compose up` after a successful build | Several Database connection related errors occur in the docker-compose log. | +| Wallet page is empty | [#1063](https://github.com/gradido/gradido/issues/1063) | Accept Cookies and Local Storage in your Browser | The page stays empty when navigating to [http://localhost/vue](http://localhost/vue) | ## Useful Links diff --git a/backend/Dockerfile b/backend/Dockerfile index 8331f5983..035841c17 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -85,7 +85,7 @@ RUN cd ../database && yarn run build FROM build as test # Run command -CMD /bin/sh -c "yarn run dev" +CMD /bin/sh -c "yarn run start" ################################################################################## # PRODUCTION (Does contain only "binary"- and static-files to reduce image size) # diff --git a/backend/package.json b/backend/package.json index 889143ac3..dda91d754 100644 --- a/backend/package.json +++ b/backend/package.json @@ -13,11 +13,12 @@ "start": "node build/index.js", "dev": "nodemon -w src --ext ts --exec ts-node src/index.ts", "lint": "eslint . --ext .js,.ts", - "test": "jest --coverage" + "test": "jest --runInBand --coverage " }, "dependencies": { "@types/jest": "^27.0.2", "apollo-server-express": "^2.25.2", + "apollo-server-testing": "^2.25.2", "axios": "^0.21.1", "class-validator": "^0.13.1", "cors": "^2.8.5", diff --git a/backend/src/graphql/arg/CheckUsernameArgs.ts b/backend/src/graphql/arg/CheckUsernameArgs.ts index 6aaed6d0b..64265b64e 100644 --- a/backend/src/graphql/arg/CheckUsernameArgs.ts +++ b/backend/src/graphql/arg/CheckUsernameArgs.ts @@ -4,7 +4,4 @@ import { ArgsType, Field } from 'type-graphql' export default class CheckUsernameArgs { @Field(() => String) username: string - - @Field(() => Number, { nullable: true }) - groupId?: number } diff --git a/backend/src/graphql/model/CheckUsernameResponse.ts b/backend/src/graphql/model/CheckUsernameResponse.ts deleted file mode 100644 index b3186ffcf..000000000 --- a/backend/src/graphql/model/CheckUsernameResponse.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { ObjectType, Field } from 'type-graphql' - -@ObjectType() -export class CheckUsernameResponse { - constructor(json: any) { - this.state = json.state - this.msg = json.msg - this.groupId = json.group_id - } - - @Field(() => String) - state: string - - @Field(() => String) - msg?: string - - @Field(() => Number) - groupId?: number -} diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts new file mode 100644 index 000000000..20a06c2b8 --- /dev/null +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -0,0 +1,123 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import { createTestClient } from 'apollo-server-testing' +import createServer from '../../server/createServer' +import CONFIG from '../../config' + +jest.mock('../../config') + +let query: any + +// to do: We need a setup for the tests that closes the connection +let con: any + +beforeAll(async () => { + const server = await createServer({}) + con = server.con + query = createTestClient(server.apollo).query +}) + +afterAll(async () => { + await con.close() +}) + +describe('CommunityResolver', () => { + const getCommunityInfoQuery = ` + query { + getCommunityInfo { + name + description + url + registerUrl + } + } + ` + + const communities = ` + query { + communities { + id + name + url + description + registerUrl + } + } + ` + + describe('getCommunityInfo', () => { + it('returns the default values', async () => { + expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({ + data: { + getCommunityInfo: { + name: 'Gradido Entwicklung', + description: 'Die lokale Entwicklungsumgebung von Gradido.', + url: 'http://localhost/vue/', + registerUrl: 'http://localhost/vue/register', + }, + }, + }) + }) + }) + + describe('communities', () => { + describe('PRODUCTION = false', () => { + beforeEach(() => { + CONFIG.PRODUCTION = false + }) + + it('returns three communities', async () => { + expect(query({ query: communities })).resolves.toMatchObject({ + data: { + communities: [ + { + id: 1, + name: 'Gradido Entwicklung', + description: 'Die lokale Entwicklungsumgebung von Gradido.', + url: 'http://localhost/vue/', + registerUrl: 'http://localhost/vue/register-community', + }, + { + id: 2, + name: 'Gradido Staging', + description: 'Der Testserver der Gradido-Akademie.', + url: 'https://stage1.gradido.net/vue/', + registerUrl: 'https://stage1.gradido.net/vue/register-community', + }, + { + id: 3, + name: 'Gradido-Akademie', + description: 'Freies Institut für Wirtschaftsbionik.', + url: 'https://gradido.net', + registerUrl: 'https://gdd1.gradido.com/vue/register-community', + }, + ], + }, + }) + }) + }) + + describe('PRODUCTION = true', () => { + beforeEach(() => { + CONFIG.PRODUCTION = true + }) + + it('returns one community', async () => { + expect(query({ query: communities })).resolves.toMatchObject({ + data: { + communities: [ + { + id: 3, + name: 'Gradido-Akademie', + description: 'Freies Institut für Wirtschaftsbionik.', + url: 'https://gradido.net', + registerUrl: 'https://gdd1.gradido.com/vue/register-community', + }, + ], + }, + }) + }) + }) + }) +}) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 33949197c..f6eccd7e8 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -3,8 +3,8 @@ import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql' import { from_hex as fromHex } from 'libsodium-wrappers' +import { getCustomRepository } from 'typeorm' import CONFIG from '../../config' -import { CheckUsernameResponse } from '../model/CheckUsernameResponse' import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode' import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse' import { UpdateUserInfosResponse } from '../model/UpdateUserInfosResponse' @@ -22,10 +22,10 @@ import { klicktippNewsletterStateMiddleware, } from '../../middleware/klicktippMiddleware' import { CheckEmailResponse } from '../model/CheckEmailResponse' -import { getCustomRepository } from 'typeorm' import { UserSettingRepository } from '../../typeorm/repository/UserSettingRepository' import { Setting } from '../enum/Setting' import { UserRepository } from '../../typeorm/repository/User' +import { LoginUser } from '@entity/LoginUser' @Resolver() export class UserResolver { @@ -275,15 +275,27 @@ export class UserResolver { return response } - @Query(() => CheckUsernameResponse) - async checkUsername( - @Args() { username, groupId = 1 }: CheckUsernameArgs, - ): Promise { - const response = await apiGet( - CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`, - ) - if (!response.success) throw new Error(response.data) - return new CheckUsernameResponse(response.data) + @Query(() => Boolean) + async checkUsername(@Args() { username }: CheckUsernameArgs): Promise { + // Username empty? + if (username === '') { + throw new Error('Username must be set.') + } + + // Do we fullfil the minimum character length? + const MIN_CHARACTERS_USERNAME = 2 + if (username.length < MIN_CHARACTERS_USERNAME) { + throw new Error(`Username must be at minimum ${MIN_CHARACTERS_USERNAME} characters long.`) + } + + const usersFound = await LoginUser.count({ username }) + + // Username already present? + if (usersFound !== 0) { + throw new Error(`Username "${username}" already taken.`) + } + + return true } @Query(() => CheckEmailResponse) diff --git a/backend/src/graphql/schema.ts b/backend/src/graphql/schema.ts index 0a570ae82..02caf2784 100644 --- a/backend/src/graphql/schema.ts +++ b/backend/src/graphql/schema.ts @@ -6,7 +6,7 @@ import isAuthorized from './directive/isAuthorized' const schema = async (): Promise => { return buildSchema({ - resolvers: [path.join(__dirname, 'resolver', `*.{js,ts}`)], + resolvers: [path.join(__dirname, 'resolver', `!(*.test).{js,ts}`)], authChecker: isAuthorized, }) } diff --git a/backend/src/index.ts b/backend/src/index.ts index 9dd75dce5..a2e533e34 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,64 +1,14 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import 'reflect-metadata' -import 'module-alias/register' -import express from 'express' -import { ApolloServer } from 'apollo-server-express' +import createServer from './server/createServer' // config import CONFIG from './config' -// database -import connection from './typeorm/connection' -import getDBVersion from './typeorm/getDBVersion' - -// server -import cors from './server/cors' -import context from './server/context' -import plugins from './server/plugins' - -// graphql -import schema from './graphql/schema' - -// TODO implement -// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; - -const DB_VERSION = '0002-add_settings' - async function main() { - // open mysql connection - const con = await connection() - if (!con || !con.isConnected) { - throw new Error(`Couldn't open connection to database`) - } + const { app } = await createServer() - // check for correct database version - const dbVersion = await getDBVersion() - if (!dbVersion || dbVersion.indexOf(DB_VERSION) === -1) { - throw new Error( - `Wrong database version - the backend requires '${DB_VERSION}' but found '${ - dbVersion || 'None' - }'`, - ) - } - - // Express Server - const server = express() - - // cors - server.use(cors) - - // Apollo Server - const apollo = new ApolloServer({ - schema: await schema(), - playground: CONFIG.GRAPHIQL, - context, - plugins, - }) - apollo.applyMiddleware({ app: server }) - - // Start Server - server.listen(CONFIG.PORT, () => { + app.listen(CONFIG.PORT, () => { // eslint-disable-next-line no-console console.log(`Server is running at http://localhost:${CONFIG.PORT}`) if (CONFIG.GRAPHIQL) { diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts new file mode 100644 index 000000000..4350483ff --- /dev/null +++ b/backend/src/server/createServer.ts @@ -0,0 +1,64 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import 'reflect-metadata' +import 'module-alias/register' + +import { ApolloServer } from 'apollo-server-express' +import express from 'express' + +// database +import connection from '../typeorm/connection' +import getDBVersion from '../typeorm/getDBVersion' + +// server +import cors from './cors' +import serverContext from './context' +import plugins from './plugins' + +// config +import CONFIG from '../config' + +// graphql +import schema from '../graphql/schema' + +// TODO implement +// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; + +const DB_VERSION = '0004-login_server_data' + +const createServer = async (context: any = serverContext): Promise => { + // open mysql connection + const con = await connection() + if (!con || !con.isConnected) { + throw new Error(`Couldn't open connection to database`) + } + + // check for correct database version + const dbVersion = await getDBVersion() + if (!dbVersion || dbVersion.indexOf(DB_VERSION) === -1) { + throw new Error( + `Wrong database version - the backend requires '${DB_VERSION}' but found '${ + dbVersion || 'None' + }'`, + ) + } + + // Express Server + const app = express() + + // cors + app.use(cors) + + // Apollo Server + const apollo = new ApolloServer({ + schema: await schema(), + playground: CONFIG.GRAPHIQL, + context, + plugins, + }) + apollo.applyMiddleware({ app }) + return { apollo, app, con } +} + +export default createServer diff --git a/backend/yarn.lock b/backend/yarn.lock index 373f623f0..091cd7038 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -1333,6 +1333,13 @@ apollo-server-plugin-base@^0.13.0: dependencies: apollo-server-types "^0.9.0" +apollo-server-testing@^2.25.2: + version "2.25.2" + resolved "https://registry.yarnpkg.com/apollo-server-testing/-/apollo-server-testing-2.25.2.tgz#0043e98b1a03720352e94b409215fb4782ae2e50" + integrity sha512-HjQV9wPbi/ZqpRbyyhNwCbaDnfjDM0hTRec5TOoOjurEZ/vh4hTPHwGkDZx3kbcWowhGxe2qoHM6KANSB/SxuA== + dependencies: + apollo-server-core "^2.25.2" + apollo-server-types@^0.9.0: version "0.9.0" resolved "https://registry.npmjs.org/apollo-server-types/-/apollo-server-types-0.9.0.tgz" diff --git a/community_server/src/Controller/ServerUsersController.php b/community_server/src/Controller/ServerUsersController.php index 236e35b7f..c07808641 100644 --- a/community_server/src/Controller/ServerUsersController.php +++ b/community_server/src/Controller/ServerUsersController.php @@ -15,7 +15,8 @@ class ServerUsersController extends AppController public function initialize() { parent::initialize(); - $this->Auth->allow(['add', 'edit']); + // uncomment in devmode to add new community server admin user, but don't!!! commit it + //$this->Auth->allow(['add', 'edit']); $this->Auth->deny('index'); } diff --git a/configs/login_server/grd_login.properties b/configs/login_server/grd_login.properties index 96b0ea928..74424328e 100644 --- a/configs/login_server/grd_login.properties +++ b/configs/login_server/grd_login.properties @@ -17,7 +17,7 @@ phpServer.host = nginx loginServer.path = http://localhost/account loginServer.default_locale = de loginServer.db.host = mariadb -loginServer.db.name = gradido_login +loginServer.db.name = gradido_community loginServer.db.user = root loginServer.db.password = loginServer.db.port = 3306 diff --git a/configs/login_server/grd_login_test.properties b/configs/login_server/grd_login_test.properties index 8a269694a..65aa0c5d0 100644 --- a/configs/login_server/grd_login_test.properties +++ b/configs/login_server/grd_login_test.properties @@ -17,7 +17,7 @@ phpServer.host = nginx loginServer.path = http://localhost/account loginServer.default_locale = de loginServer.db.host = mariadb -loginServer.db.name = gradido_login_test +loginServer.db.name = gradido_community_test loginServer.db.user = root loginServer.db.password = loginServer.db.port = 3306 diff --git a/configs/login_server/setup_db_tables/setup_docker_group.sql b/configs/login_server/setup_db_tables/setup_docker_group.sql deleted file mode 100644 index 5f1b64c3f..000000000 --- a/configs/login_server/setup_db_tables/setup_docker_group.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `groups` (`id`, `alias`, `name`, `url`, `host`, `home`, `description`) VALUES -(1, 'docker', 'docker gradido group', 'localhost', 'nginx', '/', 'gradido test group for docker and stage2 with blockchain db'); - - - - diff --git a/database/entity/0003-login_server_tables/LoginUser.ts b/database/entity/0003-login_server_tables/LoginUser.ts new file mode 100644 index 000000000..26614b4db --- /dev/null +++ b/database/entity/0003-login_server_tables/LoginUser.ts @@ -0,0 +1,56 @@ +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' + +// Moriz: I do not like the idea of having two user tables +@Entity('login_users') +export class LoginUser extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 191, unique: true }) + email: string + + @Column({ name: 'first_name', length: 150 }) + firstName: string + + @Column({ name: 'last_name', length: 255, default: '' }) + lastName: string + + @Column({ length: 255, default: '' }) + username: string + + @Column({ default: '' }) + description: string + + @Column({ type: 'bigint', default: 0, unsigned: true }) + password: string + + @Column({ name: 'pubkey', type: 'binary', length: 32, default: null, nullable: true }) + pubKey: Buffer + + @Column({ name: 'privkey', type: 'binary', length: 80, default: null, nullable: true }) + privKey: Buffer + + @Column({ name: 'email_hash', type: 'binary', length: 32, default: null, nullable: true }) + emailHash: Buffer + + @Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date + + @Column({ name: 'email_checked', default: 0 }) + emailChecked: boolean + + @Column({ name: 'passphrase_shown', default: 0 }) + passphraseShown: boolean + + @Column({ length: 4, default: 'de' }) + language: string + + @Column({ default: 0 }) + disabled: boolean + + @Column({ name: 'group_id', default: 0, unsigned: true }) + groupId: number + + @Column({ name: 'publisher_id', default: 0 }) + publisherId: number +} diff --git a/database/entity/LoginUser.ts b/database/entity/LoginUser.ts new file mode 100644 index 000000000..034f791cb --- /dev/null +++ b/database/entity/LoginUser.ts @@ -0,0 +1 @@ +export { LoginUser } from './0003-login_server_tables/LoginUser' diff --git a/database/entity/index.ts b/database/entity/index.ts index e18757ab8..1881b2932 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -1,4 +1,5 @@ import { Balance } from './Balance' +import { LoginUser } from './LoginUser' import { Migration } from './Migration' import { Transaction } from './Transaction' import { TransactionCreation } from './TransactionCreation' @@ -9,6 +10,7 @@ import { UserTransaction } from './UserTransaction' export const entities = [ Balance, + LoginUser, Migration, Transaction, TransactionCreation, diff --git a/database/migrations/0002-add_settings.ts b/database/migrations/0002-add_settings.ts index 68c340040..d26a2b4cc 100644 --- a/database/migrations/0002-add_settings.ts +++ b/database/migrations/0002-add_settings.ts @@ -11,7 +11,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn(` - CREATE TABLE IF NOT EXISTS \`user_setting\` ( + CREATE TABLE \`user_setting\` ( \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, \`userId\` int(11) NOT NULL, \`key\` varchar(255) NOT NULL, @@ -22,5 +22,5 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn(`DROP TABLE IF EXISTS \`user_setting\`;`) + await queryFn(`DROP TABLE \`user_setting\`;`) } diff --git a/database/migrations/0003-login_server_tables.ts b/database/migrations/0003-login_server_tables.ts new file mode 100644 index 000000000..dacc211ac --- /dev/null +++ b/database/migrations/0003-login_server_tables.ts @@ -0,0 +1,153 @@ +/* FIRST MIGRATION + * + * This migration is special since it takes into account that + * the database can be setup already but also may not be. + * Therefore you will find all `CREATE TABLE` statements with + * a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the + * downgrade function all `DROP TABLE` with a `IF EXISTS`. + * This ensures compatibility for existing or non-existing + * databases. + */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + CREATE TABLE \`login_app_access_tokens\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int NOT NULL, + \`access_code\` bigint unsigned NOT NULL, + \`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + \`updated\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`access_code\` (\`access_code\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_elopage_buys\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`elopage_user_id\` int DEFAULT NULL, + \`affiliate_program_id\` int NOT NULL, + \`publisher_id\` int NOT NULL, + \`order_id\` int NOT NULL, + \`product_id\` int NOT NULL, + \`product_price\` int NOT NULL, + \`payer_email\` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + \`publisher_email\` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + \`payed\` tinyint NOT NULL, + \`success_date\` datetime NOT NULL, + \`event\` varchar(255) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_email_opt_in_types\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(255) NOT NULL, + \`description\` varchar(255) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_email_opt_in\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int NOT NULL, + \`verification_code\` bigint unsigned NOT NULL, + \`email_opt_in_type_id\` int NOT NULL, + \`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + \`resend_count\` int DEFAULT '0', + \`updated\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`verification_code\` (\`verification_code\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_groups\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`alias\` varchar(190) NOT NULL, + \`name\` varchar(255) NOT NULL, + \`url\` varchar(255) NOT NULL, + \`host\` varchar(255) DEFAULT "/", + \`home\` varchar(255) DEFAULT "/", + \`description\` text, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`alias\` (\`alias\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_pending_tasks\` ( + \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, + \`user_id\` int UNSIGNED DEFAULT 0, + \`request\` varbinary(2048) NOT NULL, + \`created\` datetime NOT NULL, + \`finished\` datetime DEFAULT '2000-01-01 000000', + \`result_json\` text DEFAULT NULL, + \`param_json\` text DEFAULT NULL, + \`task_type_id\` int UNSIGNED NOT NULL, + \`child_pending_task_id\` int UNSIGNED DEFAULT 0, + \`parent_pending_task_id\` int UNSIGNED DEFAULT 0, + PRIMARY KEY (\`id\`) + ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_roles\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(255) NOT NULL, + \`description\` varchar(255) NOT NULL, + \`flags\` bigint NOT NULL DEFAULT '0', + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_user_backups\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int NOT NULL, + \`passphrase\` text NOT NULL, + \`mnemonic_type\` int DEFAULT '-1', + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_user_roles\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int NOT NULL, + \`role_id\` int NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) + await queryFn(` + CREATE TABLE \`login_users\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`email\` varchar(191) NOT NULL, + \`first_name\` varchar(150) NOT NULL, + \`last_name\` varchar(255) DEFAULT '', + \`username\` varchar(255) DEFAULT '', + \`description\` text DEFAULT '', + \`password\` bigint unsigned DEFAULT '0', + \`pubkey\` binary(32) DEFAULT NULL, + \`privkey\` binary(80) DEFAULT NULL, + \`email_hash\` binary(32) DEFAULT NULL, + \`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + \`email_checked\` tinyint NOT NULL DEFAULT '0', + \`passphrase_shown\` tinyint NOT NULL DEFAULT '0', + \`language\` varchar(4) NOT NULL DEFAULT 'de', + \`disabled\` tinyint DEFAULT '0', + \`group_id\` int unsigned DEFAULT 0, + \`publisher_id\` int DEFAULT 0, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`email\` (\`email\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + await queryFn(`DROP TABLE \`login_app_access_tokens\`;`) + await queryFn(`DROP TABLE \`login_elopage_buys\`;`) + await queryFn(`DROP TABLE \`login_email_opt_in_types\`;`) + await queryFn(`DROP TABLE \`login_email_opt_in\`;`) + await queryFn(`DROP TABLE \`login_groups\`;`) + await queryFn(`DROP TABLE \`login_pending_tasks\`;`) + await queryFn(`DROP TABLE \`login_roles\`;`) + await queryFn(`DROP TABLE \`login_user_backups\`;`) + await queryFn(`DROP TABLE \`login_user_roles\`;`) + await queryFn(`DROP TABLE \`login_users\`;`) +} diff --git a/database/migrations/0004-login_server_data.ts b/database/migrations/0004-login_server_data.ts new file mode 100644 index 000000000..dad7d1e34 --- /dev/null +++ b/database/migrations/0004-login_server_data.ts @@ -0,0 +1,74 @@ +/* FIRST MIGRATION + * + * This migration is special since it takes into account that + * the database can be setup already but also may not be. + * Therefore you will find all `CREATE TABLE` statements with + * a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the + * downgrade function all `DROP TABLE` with a `IF EXISTS`. + * This ensures compatibility for existing or non-existing + * databases. + */ + +const LOGIN_SERVER_DB = 'gradido_login' + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + const loginDatabaseExists = await queryFn(` + SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${LOGIN_SERVER_DB}' + `) + if (loginDatabaseExists.length === 0) { + // eslint-disable-next-line no-console + console.log(`Skipping Login Server Database migration - Database ${LOGIN_SERVER_DB} not found`) + return + } + + await queryFn(` + INSERT INTO \`login_app_access_tokens\` SELECT * FROM ${LOGIN_SERVER_DB}.\`app_access_tokens\`; + `) + await queryFn(` + INSERT INTO \`login_elopage_buys\` SELECT * FROM ${LOGIN_SERVER_DB}.\`elopage_buys\`; + `) + await queryFn(` + INSERT INTO \`login_email_opt_in_types\` SELECT * FROM ${LOGIN_SERVER_DB}.\`email_opt_in_types\`; + `) + await queryFn(` + INSERT INTO \`login_email_opt_in\` SELECT * FROM ${LOGIN_SERVER_DB}.\`email_opt_in\`; + `) + await queryFn(` + INSERT INTO \`login_groups\` SELECT * FROM ${LOGIN_SERVER_DB}.\`groups\`; + `) + await queryFn(` + INSERT INTO \`login_pending_tasks\` SELECT * FROM ${LOGIN_SERVER_DB}.\`pending_tasks\`; + `) + await queryFn(` + INSERT INTO \`login_roles\` SELECT * FROM ${LOGIN_SERVER_DB}.\`roles\`; + `) + await queryFn(` + INSERT INTO \`login_user_backups\` SELECT * FROM ${LOGIN_SERVER_DB}.\`user_backups\`; + `) + await queryFn(` + INSERT INTO \`login_user_roles\` SELECT * FROM ${LOGIN_SERVER_DB}.\`user_roles\`; + `) + await queryFn(` + INSERT INTO \`login_users\` SELECT * FROM ${LOGIN_SERVER_DB}.\`users\`; + `) + + // TODO clarify if we need this on non docker environment? + await queryFn(` + INSERT IGNORE INTO \`login_groups\` (\`id\`, \`alias\`, \`name\`, \`url\`, \`host\`, \`home\`, \`description\`) VALUES + (1, 'docker', 'docker gradido group', 'localhost', 'nginx', '/', 'gradido test group for docker and stage2 with blockchain db'); + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + await queryFn(`DELETE FROM \`login_app_access_tokens\`;`) + await queryFn(`DELETE FROM \`login_elopage_buys\`;`) + await queryFn(`DELETE FROM \`login_email_opt_in_types\`;`) + await queryFn(`DELETE FROM \`login_email_opt_in\`;`) + await queryFn(`DELETE FROM \`login_groups\`;`) + await queryFn(`DELETE FROM \`login_pending_tasks\`;`) + await queryFn(`DELETE FROM \`login_roles\`;`) + await queryFn(`DELETE FROM \`login_user_backups\`;`) + await queryFn(`DELETE FROM \`login_user_roles\`;`) + await queryFn(`DELETE FROM \`login_users\`;`) +} diff --git a/deployment/bare_metal/update_all.sh b/deployment/bare_metal/update_all.sh index b065a16d4..e045d3f39 100755 --- a/deployment/bare_metal/update_all.sh +++ b/deployment/bare_metal/update_all.sh @@ -36,8 +36,6 @@ cd $PROJECT_PATH # git checkout -f master git pull cd deployment/bare_metal -echo 'update schemas' >> $UPDATE_HTML -./update_db_schemas.sh echo 'starting with rebuilding login-server
' >> $UPDATE_HTML ./build_and_start_login_server.sh echo 'starting with rebuilding frontend
' >> $UPDATE_HTML diff --git a/deployment/bare_metal/update_db_schemas.sh b/deployment/bare_metal/update_db_schemas.sh deleted file mode 100755 index 80628f35c..000000000 --- a/deployment/bare_metal/update_db_schemas.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# For that to work skeema needed to be installed on system -# in login_server/skeema skeema configuration files need to be there also in the subfolders -# Update DB Schemas (only the schemas, not the data) - -cd ../../login_server/skeema -skeema push --allow-unsafe diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 1fa6c7e23..5783b9fe7 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -136,22 +136,7 @@ services: - external-net volumes: - /sessions - - ######################################################### - ## skeema for updating dbs if changes happend ########### - ######################################################### - skeema: - build: - context: . - dockerfile: ./skeema/Dockerfile - target: skeema_dev_run - depends_on: - - mariadb - networks: - - internal-net - volumes: - - ./login_server/skeema/gradido_login:/skeema/gradido_login - + volumes: frontend_node_modules: backend_node_modules: diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 457faf950..e7b0e9849 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -2,6 +2,26 @@ version: "3.4" services: + ######################################################## + # BACKEND ############################################## + ######################################################## + backend: + image: gradido/backend:test + build: + target: test + networks: + - external-net + - internal-net + environment: + - NODE_ENV="test" + - DB_HOST=mariadb + + ######################################################## + # DATABASE ############################################# + ######################################################## + database: + restart: always # this is very dangerous, but worth a test for the delayed mariadb startup at first run + ######################################################### ## MARIADB ############################################## ######################################################### @@ -9,16 +29,17 @@ services: build: context: . dockerfile: ./mariadb/Dockerfile - target: mariadb_server_test + target: mariadb_server environment: - MARIADB_ALLOW_EMPTY_PASSWORD=1 - MARIADB_USER=root networks: - internal-net + - external-net ports: - 3306:3306 volumes: - - db_test_vol:/var/lib/mysql + - db_test_vol:/var/lib/mysql ######################################################### ## LOGIN SERVER ######################################### @@ -75,19 +96,6 @@ services: - external-net volumes: - /sessions - - ######################################################### - ## skeema for updating dbs if changes happend ########### - ######################################################### - skeema: - build: - context: . - dockerfile: ./skeema/Dockerfile - target: skeema_run - depends_on: - - mariadb - networks: - - internal-net networks: external-net: diff --git a/docker-compose.yml b/docker-compose.yml index b85d155fe..3ce88715d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,9 +35,8 @@ services: ######################################################### mariadb: build: - context: . - dockerfile: ./mariadb/Dockerfile - target: mariadb_server_test + context: ./mariadb + target: mariadb_server environment: - MARIADB_ALLOW_EMPTY_PASSWORD=1 - MARIADB_USER=root @@ -158,41 +157,6 @@ services: - internal-net volumes: - ./community_server/config/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini - - ######################################################### - ## skeema for updating dbs if changes happend ########### - ######################################################### - skeema: - build: - context: . - dockerfile: ./skeema/Dockerfile - target: skeema_run - depends_on: - - mariadb - networks: - - internal-net - - ######################################################### - ## GRADIDO NODE v1 ###################################### - ######################################################### - # gradido-node: - # build: - # context: . - # dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile - # volumes: - # - ${GN_INSTANCE_FOLDER}:/opt/instance - # container_name: ${GN_CONTAINER_NAME} - - ######################################################### - ## GRADIDO NODE test ################################### - ######################################################### - # gradido-node-test: - # build: - # context: . - # dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile - # container_name: gn-test - # working_dir: /opt/gn/build - # command: ["./unit_tests"] networks: external-net: diff --git a/docu/Concepts/TechnicalRequirements/Architecture/TechnicalOverview.md b/docu/Concepts/TechnicalRequirements/Architecture/TechnicalOverview.md index f0fe1e52a..73f74dbae 100644 --- a/docu/Concepts/TechnicalRequirements/Architecture/TechnicalOverview.md +++ b/docu/Concepts/TechnicalRequirements/Architecture/TechnicalOverview.md @@ -15,7 +15,7 @@ This document describes the technical overview for the Gradido infrastructur. Be ![CommunityServerAPI](../image/CommunityServerAPI.png) -### Database Skeema +### Database Skeema (outdated) ![CommunityDBSkeema](../image/CommunityDBSkeema.png) diff --git a/docu/Gradido-Admin.epgz b/docu/Gradido-Admin.epgz new file mode 100644 index 000000000..9c00dc445 Binary files /dev/null and b/docu/Gradido-Admin.epgz differ diff --git a/docu/create-coins-as-admin.md b/docu/create-coins-as-admin.md new file mode 100644 index 000000000..6a95df119 --- /dev/null +++ b/docu/create-coins-as-admin.md @@ -0,0 +1,27 @@ +### User creation +A user needs to be created on the login_server we do this when we create a User in the client https://$community_domain/vue/register. + +### Admin user +To set a User admin we need the following SQL query on the gradido_login database: +``` +INSERT INTO user_roles (id, user_id, role_id) VALUES (NULL, '1', '1'); +``` +user_id has to be found in users +Now when we login in on https://$community_domain/account/ we can create coins but we will be restricted cause we can't sign the creations. + +### Signation account +At first we need to enable the server user account creation with uncommenting line: 19 in +community_server/src/Controller/ServerUsersController.php +```php +$this->Auth->allow(['add', 'edit']); +``` +This enable us to use this action without being logged in. +To add a signation account we need to go on the following url: http://$community_domain/server-users/add + +### Coin creation process +The coin creation for work is done in the following url: http://$community_domain/transaction-creations/create-multi +Where we can create coins for a number of as many users as we want excepted for our self. +Furthermore we must sign the transactions we created. Normally after clicking on the left button (Transaktion abschließen) we should be automatically forwarded to http://$community_domain/account/checkTransactions where we can do this. +If not this page can also be reached by clicking on the shield-icon with the hook in it on the Dashboard, which is only shown if at least one transaction is waiting for signing. + +For debug purposes you can check the `pending_tasks` table, which is used to store the transactions which are not signed yet or had errors. \ No newline at end of file diff --git a/docu/graphics/gradido_admin.png b/docu/graphics/gradido_admin.png new file mode 100644 index 000000000..855cf903e Binary files /dev/null and b/docu/graphics/gradido_admin.png differ diff --git a/docu/graphics/userdetails.png b/docu/graphics/userdetails.png new file mode 100644 index 000000000..b31ff3e63 Binary files /dev/null and b/docu/graphics/userdetails.png differ diff --git a/docu/presentation/adminarea-old-new.pdf b/docu/presentation/adminarea-old-new.pdf new file mode 100644 index 000000000..3fda700ec Binary files /dev/null and b/docu/presentation/adminarea-old-new.pdf differ diff --git a/frontend/jest.config.js b/frontend/jest.config.js index dc44ca43e..774aa6bf9 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -9,8 +9,9 @@ module.exports = { ], // coverageReporters: ['lcov', 'text'], moduleNameMapper: { - '^@/(.*)$': '/src/$1', '\\.(css|less)$': 'identity-obj-proxy', + '\\.(scss)$': '/src/assets/mocks/styleMock.js', + '^@/(.*)$': '/src/$1', }, transform: { '^.+\\.vue$': 'vue-jest', diff --git a/frontend/src/assets/mocks/styleMock.js b/frontend/src/assets/mocks/styleMock.js new file mode 100644 index 000000000..4ba52ba2c --- /dev/null +++ b/frontend/src/assets/mocks/styleMock.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 2ee381dd8..01021f601 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -75,9 +75,7 @@ export const sendResetPasswordEmail = gql` export const checkUsername = gql` query($username: String!) { - checkUsername(username: $username) { - state - } + checkUsername(username: $username) } ` diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 2db5f6e0d..0dd3ba926 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -96,7 +96,7 @@ "conversion-gdt-euro": "Umrechnung Euro / Gradido Transform (GDT)", "credit": "Gutschrift", "factor": "Faktor", - "formula": "Berechungsformel", + "formula": "Berechnungsformel", "funding": "Zu den Förderbeiträgen", "gdt-received": "Gradido Transform (GDT) erhalten", "no-transactions": "Du hast noch keine Gradido Transform (GDT).", diff --git a/frontend/src/plugins/dashboard-plugin.test.js b/frontend/src/plugins/dashboard-plugin.test.js new file mode 100644 index 000000000..3792ad2c4 --- /dev/null +++ b/frontend/src/plugins/dashboard-plugin.test.js @@ -0,0 +1,25 @@ +import dashboardPlugin from './dashboard-plugin.js' +import Vue from 'vue' + +import GlobalComponents from './globalComponents' +import GlobalDirectives from './globalDirectives' + +jest.mock('./globalComponents') +jest.mock('./globalDirectives') + +jest.mock('vue') + +const vueUseMock = jest.fn() +Vue.use = vueUseMock + +describe('dashboard plugin', () => { + dashboardPlugin.install(Vue) + + it('installs the global components', () => { + expect(vueUseMock).toBeCalledWith(GlobalComponents) + }) + + it('installs the global directives', () => { + expect(vueUseMock).toBeCalledWith(GlobalDirectives) + }) +}) diff --git a/frontend/src/validation-rules.js b/frontend/src/validation-rules.js index 5552794d1..54f4c3090 100644 --- a/frontend/src/validation-rules.js +++ b/frontend/src/validation-rules.js @@ -59,7 +59,7 @@ export const loadAllRules = (i18nCallback) => { }, }) .then((result) => { - return result.data.checkUsername.state === 'success' + return result.data.checkUsername }) .catch(() => { return false diff --git a/frontend/src/views/Pages/CheckEmail.vue b/frontend/src/views/Pages/CheckEmail.vue index baeacb34f..1a23f6b09 100644 --- a/frontend/src/views/Pages/CheckEmail.vue +++ b/frontend/src/views/Pages/CheckEmail.vue @@ -5,10 +5,10 @@
-

{{ $t('checkEmail.title') }}

+

{{ $t('site.checkEmail.title') }}

- {{ $t('checkEmail.errorText') }} + {{ $t('site.checkEmail.errorText') }}
diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index 0c2b2dea8..00114eb04 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -207,12 +207,6 @@ export default { }, }) .then(() => { - this.form.email = '' - this.form.firstname = '' - this.form.lastname = '' - this.form.password.password = '' - this.form.password.passwordRepeat = '' - this.language = '' this.$router.push('/thx/register') }) .catch((error) => { @@ -228,7 +222,6 @@ export default { this.form.lastname = '' this.form.password.password = '' this.form.password.passwordRepeat = '' - this.language = '' }, }, computed: { diff --git a/login_server/.gitignore b/login_server/.gitignore index 1d623d885..ca7f5f440 100644 --- a/login_server/.gitignore +++ b/login_server/.gitignore @@ -5,6 +5,5 @@ src/cpsp/*.h src/cpsp/*.cpp src/cpp/proto/ build*/ -/skeema/gradido_login/insert/crypto_key.sql src/LOCALE/messages.pot diff --git a/login_server/README.md b/login_server/README.md index 73f5deea0..118d0d53c 100644 --- a/login_server/README.md +++ b/login_server/README.md @@ -56,8 +56,7 @@ To update messages.pot run This will be also called by ./scripts/build_debug.sh ## database -Login-Server needs a db to run, it is tested with mariadb -table definitions are found in folder ./skeema/gradido_login +Login-Server needs a db to run, it is tested with mariadb. Currently at least one group must be present in table groups. For example: ```sql diff --git a/login_server/skeema/gradido_login/app_access_tokens.sql b/login_server/skeema/gradido_login/app_access_tokens.sql deleted file mode 100644 index d320bba5c..000000000 --- a/login_server/skeema/gradido_login/app_access_tokens.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `app_access_tokens` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `user_id` int NOT NULL, - `access_code` bigint unsigned NOT NULL, - `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `access_code` (`access_code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/elopage_buys.sql b/login_server/skeema/gradido_login/elopage_buys.sql deleted file mode 100644 index ba39e8c7a..000000000 --- a/login_server/skeema/gradido_login/elopage_buys.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE `elopage_buys` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `elopage_user_id` int DEFAULT NULL, - `affiliate_program_id` int NOT NULL, - `publisher_id` int NOT NULL, - `order_id` int NOT NULL, - `product_id` int NOT NULL, - `product_price` int NOT NULL, - `payer_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, - `publisher_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, - `payed` tinyint NOT NULL, - `success_date` datetime NOT NULL, - `event` varchar(255) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/email_opt_in.sql b/login_server/skeema/gradido_login/email_opt_in.sql deleted file mode 100644 index da4288475..000000000 --- a/login_server/skeema/gradido_login/email_opt_in.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `email_opt_in` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `user_id` int NOT NULL, - `verification_code` bigint unsigned NOT NULL, - `email_opt_in_type_id` int NOT NULL, - `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `resend_count` int DEFAULT '0', - `updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `verification_code` (`verification_code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/email_opt_in_types.sql b/login_server/skeema/gradido_login/email_opt_in_types.sql deleted file mode 100644 index dbcd2d272..000000000 --- a/login_server/skeema/gradido_login/email_opt_in_types.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `email_opt_in_types` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL, - `description` varchar(255) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/groups.sql b/login_server/skeema/gradido_login/groups.sql deleted file mode 100644 index 9d57a3b2c..000000000 --- a/login_server/skeema/gradido_login/groups.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `groups` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `alias` varchar(190) NOT NULL, - `name` varchar(255) NOT NULL, - `url` varchar(255) NOT NULL, - `host` varchar(255) DEFAULT "/", - `home` varchar(255) DEFAULT "/", - `description` text, - PRIMARY KEY (`id`), - UNIQUE KEY `alias` (`alias`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/login_server/skeema/gradido_login/pending_tasks.sql b/login_server/skeema/gradido_login/pending_tasks.sql deleted file mode 100644 index 6b7570c0c..000000000 --- a/login_server/skeema/gradido_login/pending_tasks.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE `pending_tasks` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` int UNSIGNED DEFAULT 0, - `request` varbinary(2048) NOT NULL, - `created` datetime NOT NULL, - `finished` datetime DEFAULT '2000-01-01 000000', - `result_json` text DEFAULT NULL, - `param_json` text DEFAULT NULL, - `task_type_id` int UNSIGNED NOT NULL, - `child_pending_task_id` int UNSIGNED DEFAULT 0, - `parent_pending_task_id` int UNSIGNED DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/roles.sql b/login_server/skeema/gradido_login/roles.sql deleted file mode 100644 index c99223961..000000000 --- a/login_server/skeema/gradido_login/roles.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `roles` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL, - `description` varchar(255) NOT NULL, - `flags` bigint NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/user_backups.sql b/login_server/skeema/gradido_login/user_backups.sql deleted file mode 100644 index 7e3b7d85a..000000000 --- a/login_server/skeema/gradido_login/user_backups.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `user_backups` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `user_id` int NOT NULL, - `passphrase` text NOT NULL, - `mnemonic_type` int DEFAULT '-1', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/user_roles.sql b/login_server/skeema/gradido_login/user_roles.sql deleted file mode 100644 index a92154ce8..000000000 --- a/login_server/skeema/gradido_login/user_roles.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `user_roles` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `user_id` int NOT NULL, - `role_id` int NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/skeema/gradido_login/users.sql b/login_server/skeema/gradido_login/users.sql deleted file mode 100644 index 95b6acec1..000000000 --- a/login_server/skeema/gradido_login/users.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE `users` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `email` varchar(191) NOT NULL, - `first_name` varchar(150) NOT NULL, - `last_name` varchar(255) DEFAULT '', - `username` varchar(255) DEFAULT '', - `description` text DEFAULT '', - `password` bigint unsigned DEFAULT '0', - `pubkey` binary(32) DEFAULT NULL, - `privkey` binary(80) DEFAULT NULL, - `email_hash` binary(32) DEFAULT NULL, - `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `email_checked` tinyint NOT NULL DEFAULT '0', - `passphrase_shown` tinyint NOT NULL DEFAULT '0', - `language` varchar(4) NOT NULL DEFAULT 'de', - `disabled` tinyint DEFAULT '0', - `group_id` int unsigned DEFAULT 0, - `publisher_id` int DEFAULT 0, - PRIMARY KEY (`id`), - UNIQUE KEY `email` (`email`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/login_server/src/cpp/SingletonManager/EmailManager.cpp b/login_server/src/cpp/SingletonManager/EmailManager.cpp index e460d129e..8a48fc8fa 100644 --- a/login_server/src/cpp/SingletonManager/EmailManager.cpp +++ b/login_server/src/cpp/SingletonManager/EmailManager.cpp @@ -58,7 +58,7 @@ bool EmailManager::init(const Poco::Util::LayeredConfiguration& cfg) void EmailManager::addEmail(model::Email* email) { if (mDisableEmail) { std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S"); - std::string log_message = dateTimeString + " Email should be sended to: "; + std::string log_message = dateTimeString + " Email should have been sent to: "; auto email_user = email->getUser(); Poco::AutoPtr email_model; if (email_user) { diff --git a/login_server/src/cpp/SingletonManager/SessionManager.cpp b/login_server/src/cpp/SingletonManager/SessionManager.cpp index c4039b10d..ea525b248 100644 --- a/login_server/src/cpp/SingletonManager/SessionManager.cpp +++ b/login_server/src/cpp/SingletonManager/SessionManager.cpp @@ -148,7 +148,7 @@ Session* SessionManager::getNewSession(int* handle) mWorkingMutex.tryLock(500); } catch (Poco::TimeoutException &ex) { - printf("[%s] exception timout mutex: %s\n", functionName, ex.displayText().data()); + printf("[%s] exception timeout mutex: %s\n", functionName, ex.displayText().data()); return nullptr; } //mWorkingMutex.lock(); diff --git a/login_server/src/cpp/controller/User.cpp b/login_server/src/cpp/controller/User.cpp index 576b2b8c8..a1cd4011f 100644 --- a/login_server/src/cpp/controller/User.cpp +++ b/login_server/src/cpp/controller/User.cpp @@ -69,7 +69,7 @@ namespace controller { using namespace Poco::Data::Keywords; Poco::Data::Statement select(session); - select << "SELECT id, first_name, last_name, email, username, description, pubkey, created, email_checked, disabled, group_id FROM " << db->getTableName(); + select << "SELECT id, first_name, last_name, email, username, description, pubkey, created, email_checked, disabled, group_id, publisher_id FROM " << db->getTableName(); select << " where email_checked = 0 "; select, into(resultFromDB); if (searchString != "") { @@ -439,6 +439,7 @@ namespace controller { return 0; auto cm = ConnectionManager::getInstance(); auto em = ErrorManager::getInstance(); + auto db = new model::table::User(); static const char* function_name = "User::checkIfVerificationEmailsShouldBeResend"; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); @@ -446,8 +447,9 @@ namespace controller { std::vector> results; int email_checked = 0; int resend_count = 1; - select << "select u.id, v.created from users as u " - << "LEFT JOIN email_opt_in as v ON(u.id = v.user_id) " + std::string table_name_email_opt_in = "login_email_opt_in"; + select << "select u.id, v.created from " << db->getTableName() << " as u " + << "LEFT JOIN " << table_name_email_opt_in << " as v ON(u.id = v.user_id) " << "where u.email_checked = ? " << "AND v.resend_count <= ? " << "ORDER BY u.id, v.created " , @@ -519,14 +521,15 @@ namespace controller { { auto cm = ConnectionManager::getInstance(); auto em = ErrorManager::getInstance(); + auto db = new model::table::User(); static const char* function_name = "User::addMissingEmailHashes"; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select(session); std::vector> results; - select << "select id, email from users " - << "where email_hash IS NULL " + select << "select id, email from " << db->getTableName() + << " where email_hash IS NULL " , Poco::Data::Keywords::into(results) ; int result_count = 0; @@ -556,7 +559,7 @@ namespace controller { // update db // reuse connection, I hope it's working Poco::Data::Statement update(session); - update << "UPDATE users set email_hash = ? where id = ?" + update << "UPDATE " << db->getTableName() << " set email_hash = ? where id = ?" , Poco::Data::Keywords::use(updates); int updated_count = 0; try { diff --git a/login_server/src/cpp/model/table/AppAccessToken.h b/login_server/src/cpp/model/table/AppAccessToken.h index bbee0568d..37c92a921 100644 --- a/login_server/src/cpp/model/table/AppAccessToken.h +++ b/login_server/src/cpp/model/table/AppAccessToken.h @@ -19,7 +19,7 @@ namespace model { // generic db operations - const char* getTableName() const { return "app_access_tokens"; } + const char* getTableName() const { return "login_app_access_tokens"; } std::string toString(); inline Poco::UInt64 getCode() const { return mAccessCode; } diff --git a/login_server/src/cpp/model/table/ElopageBuy.h b/login_server/src/cpp/model/table/ElopageBuy.h index 008a11a52..8f10d2dbd 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.h +++ b/login_server/src/cpp/model/table/ElopageBuy.h @@ -34,7 +34,7 @@ namespace model { ElopageBuy(); // generic db operations - const char* getTableName() const { return "elopage_buys"; } + const char* getTableName() const { return "login_elopage_buys"; } std::string toString(); diff --git a/login_server/src/cpp/model/table/EmailOptIn.h b/login_server/src/cpp/model/table/EmailOptIn.h index 9e0fc335a..7430a8000 100644 --- a/login_server/src/cpp/model/table/EmailOptIn.h +++ b/login_server/src/cpp/model/table/EmailOptIn.h @@ -29,7 +29,7 @@ namespace model { // generic db operations - const char* getTableName() const { return "email_opt_in"; } + const char* getTableName() const { return "login_email_opt_in"; } std::string toString(); inline Poco::UInt64 getCode() const { return mEmailVerificationCode; } diff --git a/login_server/src/cpp/model/table/Group.h b/login_server/src/cpp/model/table/Group.h index e998cfb7c..a2a300e3b 100644 --- a/login_server/src/cpp/model/table/Group.h +++ b/login_server/src/cpp/model/table/Group.h @@ -17,7 +17,7 @@ namespace model { Group(GroupTuple userTuple); // generic db operations - const char* getTableName() const { return "groups"; } + const char* getTableName() const { return "login_groups"; } std::string toString(); inline const std::string& getAlias() const { return mAlias; } diff --git a/login_server/src/cpp/model/table/PendingTask.h b/login_server/src/cpp/model/table/PendingTask.h index 3e7a0e8d5..730efcd43 100644 --- a/login_server/src/cpp/model/table/PendingTask.h +++ b/login_server/src/cpp/model/table/PendingTask.h @@ -30,7 +30,7 @@ namespace model { // generic db operations - const char* getTableName() const { return "pending_tasks"; } + const char* getTableName() const { return "login_pending_tasks"; } std::string toString(); //! \brief update table row with current request diff --git a/login_server/src/cpp/model/table/Roles.cpp b/login_server/src/cpp/model/table/Roles.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/login_server/src/cpp/model/table/Roles.h b/login_server/src/cpp/model/table/Roles.h deleted file mode 100644 index 01775b58c..000000000 --- a/login_server/src/cpp/model/table/Roles.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE -#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE - -#include "ModelBase.h" -#include "Poco/Types.h" -#include "Poco/Tuple.h" - -namespace model { - namespace table { - - enum RoleType { - ROLE_ADMIN = 1 - }; - - class Roles : public ModelBase - { - - }; - /* - typedef Poco::Tuple EmailOptInTuple; - - class EmailOptIn : public ModelBase - { - public: - EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type); - EmailOptIn(const Poco::UInt64& code, EmailOptInType type); - EmailOptIn(const EmailOptInTuple& tuple); - EmailOptIn(); - ~EmailOptIn(); - - // generic db operations - const char* getTableName() { return "email_opt_in"; } - std::string toString(); - - inline Poco::UInt64 getCode() const { return mEmailVerificationCode; } - inline int getUserId() const { return mUserId; } - inline EmailOptInType getType() const { return static_cast(mType); } - inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; } - inline void setUserId(int user_Id) { mUserId = user_Id; } - - static const char* typeToString(EmailOptInType type); - protected: - Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); - Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); - Poco::Data::Statement _loadMultipleFromDB(Poco::Data::Session session, const std::string& fieldName); - Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::vector& fieldNames, MysqlConditionType conditionType = MYSQL_CONDITION_AND); - Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); - - int mUserId; - // data type must be a multiple of 4 - Poco::UInt64 mEmailVerificationCode; - int mType; - - }; - */ - } -} - - -#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE \ No newline at end of file diff --git a/login_server/src/cpp/model/table/User.cpp b/login_server/src/cpp/model/table/User.cpp index 6d76b3b9e..3fca20edd 100644 --- a/login_server/src/cpp/model/table/User.cpp +++ b/login_server/src/cpp/model/table/User.cpp @@ -83,11 +83,11 @@ namespace model { if (mPasswordHashed) { - insert << "INSERT INTO users (email, first_name, last_name, username, description, password, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?,?);", + insert << "INSERT INTO " << getTableName() << " (email, first_name, last_name, username, description, password, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?,?);", use(mEmail), use(mFirstName), use(mLastName), use(mUsername), use(mDescription), bind(mPasswordHashed), use(mEmailHash), use(mLanguageKey), use(mGroupId), use(mPublisherId); } else { - insert << "INSERT INTO users (email, first_name, last_name, username, description, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?);", + insert << "INSERT INTO " << getTableName() << " (email, first_name, last_name, username, description, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?);", use(mEmail), use(mFirstName), use(mLastName), use(mUsername), use(mDescription), use(mEmailHash), use(mLanguageKey), use(mGroupId), use(mPublisherId); } @@ -103,10 +103,13 @@ namespace model { } Poco::Data::Statement select(session); - select << "SELECT " << getTableName() << ".id, email, first_name, last_name, username, description, password, pubkey, privkey, email_hash, created, email_checked, language, disabled, group_id, publisher_id, user_roles.role_id " + std::string table_name_user_roles = "login_user_roles"; + + select << "SELECT " << getTableName() << ".id, email, first_name, last_name, username, description, password, pubkey, privkey, email_hash, created, email_checked, language, disabled, group_id, publisher_id, " << table_name_user_roles << ".role_id " << " FROM " << getTableName() - << " LEFT JOIN user_roles ON " << getTableName() << ".id = user_roles.user_id " - << " WHERE " << _fieldName << " = ?" , + << " LEFT JOIN " << table_name_user_roles + << " ON " << getTableName() << ".id = " << table_name_user_roles << ".user_id " + << " WHERE " << _fieldName << " = ?; " , into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mUsername), into(mDescription), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(mEmailHash), into(mCreated), into(mEmailChecked), into(mLanguageKey), into(mDisabled), into(mGroupId), into(mPublisherId), into(mRole); @@ -194,7 +197,7 @@ namespace model { Poco::Data::Statement update(session); - update << "UPDATE users SET password = ?, privkey = ? where id = ?;", + update << "UPDATE " << getTableName() << " SET password = ?, privkey = ? where id = ?;", bind(mPasswordHashed), use(mPrivateKey), use(mID); @@ -221,7 +224,7 @@ namespace model { Poco::Data::Statement update(session); - update << "UPDATE users SET pubkey = ?, privkey = ? where id = ?;", + update << "UPDATE " << getTableName() << " SET pubkey = ?, privkey = ? where id = ?;", use(mPublicKey), use(mPrivateKey), use(mID); @@ -246,7 +249,7 @@ namespace model { auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement update(session); - update << "UPDATE users SET first_name = ?, last_name = ?, username = ?, description = ?, disabled = ?, language = ?, publisher_id = ? where id = ?;", + update << "UPDATE " << getTableName() << " SET first_name = ?, last_name = ?, username = ?, description = ?, disabled = ?, language = ?, publisher_id = ? where id = ?;", use(mFirstName), use(mLastName), use(mUsername), use(mDescription), use(mDisabled), use(mLanguageKey), use(mPublisherId), use(mID); try { diff --git a/login_server/src/cpp/model/table/User.h b/login_server/src/cpp/model/table/User.h index ac756434b..8d3acf0e2 100644 --- a/login_server/src/cpp/model/table/User.h +++ b/login_server/src/cpp/model/table/User.h @@ -54,7 +54,7 @@ namespace model { // generic db operations - const char* getTableName() const { return "users"; } + const char* getTableName() const { return "login_users"; } std::string toString(); std::string toHTMLString(); diff --git a/login_server/src/cpp/model/table/UserBackup.h b/login_server/src/cpp/model/table/UserBackup.h index a2f407fbd..1a8ec41ad 100644 --- a/login_server/src/cpp/model/table/UserBackup.h +++ b/login_server/src/cpp/model/table/UserBackup.h @@ -17,7 +17,7 @@ namespace model { UserBackup(); // generic db operations - const char* getTableName() const { return "user_backups"; } + const char* getTableName() const { return "login_user_backups"; } std::string toString(); inline int getUserId() const { return mUserId; } diff --git a/login_server/src/cpp/model/table/UserRole.h b/login_server/src/cpp/model/table/UserRole.h index 1369dbe86..30547b4b9 100644 --- a/login_server/src/cpp/model/table/UserRole.h +++ b/login_server/src/cpp/model/table/UserRole.h @@ -4,7 +4,6 @@ #include "ModelBase.h" #include "Poco/Types.h" #include "Poco/Tuple.h" -//#include "Roles.h" namespace model { namespace table { @@ -25,7 +24,7 @@ namespace model { UserRole(); // generic db operations - const char* getTableName() const { return "user_roles"; } + const char* getTableName() const { return "login_user_roles"; } std::string toString(); inline int getUserId() const { return mUserId; } diff --git a/login_server/src/cpp/test/main.cpp b/login_server/src/cpp/test/main.cpp index b98c86e61..f7f48cff2 100644 --- a/login_server/src/cpp/test/main.cpp +++ b/login_server/src/cpp/test/main.cpp @@ -176,9 +176,9 @@ int load(int argc, char* argv[]) { // clean up and fill db std::string tables[] = { - "groups", - "users", - "user_roles" + "login_groups", + "login_users", + "login_user_roles" }; for (int i = 0; i < 3; i++) { if (runMysql("TRUNCATE " + tables[i])) { @@ -191,7 +191,7 @@ int load(int argc, char* argv[]) { std::stringstream ss; // password = TestP4ssword&H - ss << "INSERT INTO `users` (`id`, `email`, `first_name`, `last_name`, `username`, `password`, `pubkey`, `privkey`, `created`, `email_checked`, `passphrase_shown`, `language`, `disabled`, `group_id`) VALUES " + ss << "INSERT INTO `login_users` (`id`, `email`, `first_name`, `last_name`, `username`, `password`, `pubkey`, `privkey`, `created`, `email_checked`, `passphrase_shown`, `language`, `disabled`, `group_id`) VALUES " << "(1, 'd_schultz32@gmx.de', 'DDD', 'Schultz', 'Diddel', 18242007140018938940, 0x69f2fefd6fa6947a370b9f8d3147f6617cf67416517ce25cb2d63901c666933c, 0x567f3e623a1899d1f8d69190c5799433c134ce0137c0c38cc0347874586d6234a19f2a0b484e6cc1863502e580ae6c17db1131f29a35eba45a46be29c7ee592940a3bd3ad519075fdeed6e368f0eb818, '2020-02-20 16:05:44', 1, 0, 'de', 0, 1), "; // if this isn't the same, some tests will fail, so we update the test data here. @@ -211,7 +211,7 @@ int load(int argc, char* argv[]) { } ss.str(std::string()); - ss << "INSERT INTO `user_roles` (`id`, `user_id`, `role_id`) VALUES" + ss << "INSERT INTO `login_user_roles` (`id`, `user_id`, `role_id`) VALUES" << "(1, 3, 1);"; if (runMysql(ss.str())) { @@ -219,7 +219,7 @@ int load(int argc, char* argv[]) { } ss.str(std::string()); - ss << "INSERT INTO `groups` (`id`, `alias`, `name`, `url`, `description`) VALUES" + ss << "INSERT INTO `login_groups` (`id`, `alias`, `name`, `url`, `description`) VALUES" << "(1, 'gdd1', 'Gradido1', 'gdd1.gradido.com', 'Der erste offizielle Gradido Server (zum Testen)'), " << "(2, 'gdd_test', 'Gradido Test', 'gdd1.gradido.com', 'Testgroup (zum Testen)'); "; if (runMysql(ss.str())) { diff --git a/login_server/src/cpsp/CheckTransaction.cpsp b/login_server/src/cpsp/CheckTransaction.cpsp index d866384b7..f0c56c100 100644 --- a/login_server/src/cpsp/CheckTransaction.cpsp +++ b/login_server/src/cpsp/CheckTransaction.cpsp @@ -74,7 +74,8 @@ enum PageState { { //mSession->finalizeTransaction(false, true); // - if(!transaction.isNull() && transaction->getModel()->getUserId() == user_model->getID()) + if(!transaction.isNull() && + (transaction_body->isCreation() || transaction->getModel()->getUserId() == user_model->getID())) { if(pt->removeTask(transaction)) { transaction->deleteFromDB(); @@ -150,7 +151,7 @@ enum PageState { transaction_body = transaction->getTransactionBody(); // user can only delete there own transactions // TODO: Auto timeout for community transactions - if(transaction->getModel()->getUserId() == user_model->getID()) { + if(transaction_body->isCreation() || transaction->getModel()->getUserId() == user_model->getID()) { transaction_removeable = true; } } @@ -338,20 +339,19 @@ enum PageState { <%= gettext("Transaktion unterzeichnen") %> <% } %> + <% if(transaction_removeable) { %> - <% } else { %> - <% } %> <% } %>
-<%@ include file="include/footer_chr.cpsp" %> \ No newline at end of file +<%@ include file="include/footer_chr.cpsp" %> diff --git a/mariadb/.skeema b/mariadb/.skeema deleted file mode 100644 index e5525e7b5..000000000 --- a/mariadb/.skeema +++ /dev/null @@ -1,5 +0,0 @@ -[production] -flavor=mariadb:10.5 -host=127.0.0.1 -port=3306 -user=root \ No newline at end of file diff --git a/mariadb/.skeema.login b/mariadb/.skeema.login deleted file mode 100644 index c6431dd8c..000000000 --- a/mariadb/.skeema.login +++ /dev/null @@ -1,3 +0,0 @@ -default-character-set=utf8mb4 -default-collation=utf8mb4_unicode_ci -schema=gradido_login \ No newline at end of file diff --git a/mariadb/Dockerfile b/mariadb/Dockerfile index 6b6b1e9aa..07d2ba368 100644 --- a/mariadb/Dockerfile +++ b/mariadb/Dockerfile @@ -3,29 +3,7 @@ ######################################################################################################### FROM mariadb/server:10.5 as mariadb_server -ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d" +# ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d" -RUN mkdir -p ${DOCKER_WORKDIR} -WORKDIR ${DOCKER_WORKDIR} - -# create databases -COPY ./mariadb/setup_dbs.sql a1_setup_dbs.sql -# login server db -COPY ./login_server/skeema/ . -RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b1_$f"; sed -i '1i use gradido_login;' "../b1_$f"; done -COPY ./configs/login_server/setup_db_tables ./gradido_login/insert -RUN cd ./gradido_login/insert && for f in *.sql; do cp -- "$f" "../../c1_$f"; sed -i '1i use gradido_login;' "../../c1_$f"; done - -######################################################################################################### -# mariadb server with test dbs -######################################################################################################### -FROM mariadb_server as mariadb_server_test - -# create test databases -COPY ./mariadb/setup_test_dbs.sql a2_setup_dbs.sql - -# login server test db -COPY ./login_server/skeema/ . -RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b2_$f"; sed -i '1i use gradido_login_test;' "../b2_$f"; done -COPY ./configs/login_server/setup_db_tables ./gradido_login/insert -RUN cd ./gradido_login/insert && for f in *.sql; do cp -- "$f" "../../c2_$f"; sed -i '1i use gradido_login_test;' "../../c2_$f"; done +# RUN mkdir -p ${DOCKER_WORKDIR} +# WORKDIR ${DOCKER_WORKDIR} diff --git a/mariadb/setup_dbs.sql b/mariadb/setup_dbs.sql deleted file mode 100644 index bf44c2ae6..000000000 --- a/mariadb/setup_dbs.sql +++ /dev/null @@ -1,7 +0,0 @@ -create database gradido_login - DEFAULT CHARACTER SET utf8mb4 - DEFAULT COLLATE utf8mb4_unicode_ci; -create database IF NOT EXISTS _skeema_tmp - DEFAULT CHARACTER SET utf8mb4 - DEFAULT COLLATE utf8mb4_unicode_ci; -FLUSH PRIVILEGES; \ No newline at end of file diff --git a/mariadb/setup_dbs_different_user.sh b/mariadb/setup_dbs_different_user.sh deleted file mode 100755 index 139337cbb..000000000 --- a/mariadb/setup_dbs_different_user.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -COLOR_GREEN="\033[0;32m" -COLOR_YELLOW="\e[33m" -COLOR_NONE="\033[0m" - -LOGIN_DB_USER=gradido_login_live -LOGIN_DB_NAME=gradido_login_live -LOGIN_DB_PASSWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo); - -COMMUNITY_DB_USER=gradido_community_live -COMMUNITY_DB_NAME=gradido_community_live -COMMUNITY_DB_PASSWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo); - -# create table -mysql < .skeema -[production] -flavor=mariadb:10.3.25 -host=127.0.0.1 -port=3306 -user=$LOGIN_DB_USER -EOF -cd gradido_login -sudo cat << EOF > .skeema -default-character-set=utf8mb4 -default-collation=utf8mb4_unicode_ci -schema=$LOGIN_DB_NAME -EOF - -source $HOME/.gvm/scripts/gvm -gvm use go1.14.4 -skeema push -p$LOGIN_DB_PASSWD - -echo -e "${COLOR_YELLOW}Login-Server db password: $LOGIN_DB_PASSWD${COLOR_NONE}" diff --git a/mariadb/setup_test_dbs.sql b/mariadb/setup_test_dbs.sql deleted file mode 100644 index 10326d002..000000000 --- a/mariadb/setup_test_dbs.sql +++ /dev/null @@ -1,10 +0,0 @@ -create database gradido_login_test - DEFAULT CHARACTER SET utf8mb4 - DEFAULT COLLATE utf8mb4_unicode_ci; -create database gradido_community_test - DEFAULT CHARACTER SET utf8mb4 - DEFAULT COLLATE utf8mb4_unicode_ci; -create database IF NOT EXISTS _skeema_tmp - DEFAULT CHARACTER SET utf8mb4 - DEFAULT COLLATE utf8mb4_unicode_ci; -FLUSH PRIVILEGES; \ No newline at end of file diff --git a/skeema/.skeema b/skeema/.skeema deleted file mode 100644 index dc87968d6..000000000 --- a/skeema/.skeema +++ /dev/null @@ -1,5 +0,0 @@ -[production] -flavor=mariadb:10.5 -host=mariadb -port=3306 -user=root \ No newline at end of file diff --git a/skeema/Dockerfile b/skeema/Dockerfile deleted file mode 100644 index bbc95f2d0..000000000 --- a/skeema/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -######################################################################################################### -# Build skeema -######################################################################################################### -FROM golang:1.17.1 as skeema_build -RUN go get -d -v github.com/skeema/skeema -WORKDIR /go/src/github.com/skeema/skeema -RUN go install github.com/skeema/skeema@v1.5.3 - -######################################################################################################### -# Run skeema for dev (dynamic) -######################################################################################################### -FROM skeema_build as skeema_dev_run - -ENV DOCKER_WORKDIR="/skeema" - -RUN mkdir -p ${DOCKER_WORKDIR} -WORKDIR ${DOCKER_WORKDIR} - -COPY ./skeema/.skeema . -COPY ./mariadb/.skeema.login . - -CMD cp .skeema.login ./gradido_login/.skeema && skeema push --allow-unsafe && rm ./gradido_login/.skeema - -######################################################################################################### -# Run skeema -######################################################################################################### -FROM skeema_build as skeema_run - -ENV DOCKER_WORKDIR="/skeema" - -RUN mkdir -p ${DOCKER_WORKDIR} -WORKDIR ${DOCKER_WORKDIR} - -COPY ./skeema/.skeema . -COPY ./login_server/skeema/ . -COPY ./mariadb/.skeema.login ./gradido_login/.skeema - -CMD skeema push --allow-unsafe -