From 21ba7b89c0b185ef1e6878ebd02df21af8c51ed6 Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Sat, 6 Feb 2021 19:55:27 +0100 Subject: Add lastname column to User DB table and update API logic to save,return and update this data. --- app/Controllers/Http/DashboardController.js | 5 +++++ app/Controllers/Http/UserController.js | 19 ++++++++++++------- .../migrations/1612629845398_users_update_schema.js | 20 ++++++++++++++++++++ resources/views/dashboard/account.edge | 8 ++++++++ resources/views/dashboard/data.edge | 6 ++++++ 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 database/migrations/1612629845398_users_update_schema.js diff --git a/app/Controllers/Http/DashboardController.js b/app/Controllers/Http/DashboardController.js index 3de4816..2f06961 100644 --- a/app/Controllers/Http/DashboardController.js +++ b/app/Controllers/Http/DashboardController.js @@ -122,6 +122,7 @@ class DashboardController { return view.render('dashboard.account', { username: auth.user.username, email: auth.user.email, + lastname: auth.user.lastname }); } @@ -135,6 +136,7 @@ class DashboardController { let validation = await validateAll(request.all(), { username: 'required', email: 'required', + lastname: 'required' }); if (validation.fails()) { session.withErrors(validation.messages()).flashExcept(['password']); @@ -168,6 +170,7 @@ class DashboardController { // Update user account const { user } = auth; user.username = request.input('username'); + user.lastname = request.input('lastname'); user.email = request.input('email'); if (request.input('password')) { const hashedPassword = crypto.createHash('sha256').update(request.input('password')).digest('base64'); @@ -192,6 +195,7 @@ class DashboardController { return view.render('dashboard.data', { username: general.username, + lastname: general.lastname, mail: general.email, created: general.created_at, updated: general.updated_at, @@ -211,6 +215,7 @@ class DashboardController { const exportData = { username: general.username, + lastname: general.lastname, mail: general.email, services, workspaces, diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js index e367d99..dc92b21 100644 --- a/app/Controllers/Http/UserController.js +++ b/app/Controllers/Http/UserController.js @@ -48,9 +48,11 @@ class UserController { // Validate user input const validation = await validateAll(request.all(), { firstname: 'required', + lastname: 'required', email: 'required|email|unique:users,email', password: 'required', }); + if (validation.fails()) { return response.status(401).send({ message: 'Invalid POST arguments', @@ -59,7 +61,7 @@ class UserController { }); } - const data = request.only(['firstname', 'email', 'password']); + const data = request.only(['firstname', 'lastname', 'email', 'password']); // Create user in DB let user; @@ -68,6 +70,7 @@ class UserController { email: data.email, password: data.password, username: data.firstname, + lastname: data.lastname, }); } catch (e) { return response.status(401).send({ @@ -149,13 +152,13 @@ class UserController { email: auth.user.email, emailValidated: true, features: {}, - firstname: 'Franz', + firstname: auth.user.username, id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', isPremium: true, isSubscriptionOwner: true, - lastname: 'Franz', + lastname: auth.user.lastname, locale: 'en-US', - ...settings || {}, + ...settings || {}, }); } @@ -185,13 +188,13 @@ class UserController { email: auth.user.email, emailValidated: true, features: {}, - firstname: 'Franz', + firstname: auth.user.username, id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', isPremium: true, isSubscriptionOwner: true, - lastname: 'Franz', + lastname: auth.user.lastname, locale: 'en-US', - ...newSettings || {}, + ...newSettings || {}, }, status: [ 'data-updated', @@ -246,6 +249,7 @@ class UserController { email, password: hashedPassword, username: 'Franz', + lastname: 'Franz' }); return response.send('Your account has been created but due to this server\'s configuration, we could not import your Franz account data.\n\nIf you are the server owner, please set CONNECT_WITH_FRANZ to true to enable account imports.'); @@ -301,6 +305,7 @@ class UserController { email: userInf.email, password: hashedPassword, username: userInf.firstname, + lastname: userInf.lastname }); } catch (e) { const errorMessage = `Could not create your user in our system.\nError: ${e}`; diff --git a/database/migrations/1612629845398_users_update_schema.js b/database/migrations/1612629845398_users_update_schema.js new file mode 100644 index 0000000..d07f66d --- /dev/null +++ b/database/migrations/1612629845398_users_update_schema.js @@ -0,0 +1,20 @@ +'use strict' + +/** @type {import('@adonisjs/lucid/src/Schema')} */ +const Schema = use('Schema') + +class UsersUpdateSchema extends Schema { + up() { + this.table('users', (table) => { + table.string('lastname', 80).notNullable().default(''); + }) + } + + down() { + this.table('users', (table) => { + table.dropColumn('lastname') + }) + } +} + +module.exports = UsersUpdateSchema \ No newline at end of file diff --git a/resources/views/dashboard/account.edge b/resources/views/dashboard/account.edge index 9f3539e..6792615 100644 --- a/resources/views/dashboard/account.edge +++ b/resources/views/dashboard/account.edge @@ -37,6 +37,14 @@ type="text" value="{{ old('name', username) }}" placeholder="Name" name="username" required> +
+ +
+ +
+
diff --git a/resources/views/dashboard/data.edge b/resources/views/dashboard/data.edge index 60ef10b..92a78d4 100644 --- a/resources/views/dashboard/data.edge +++ b/resources/views/dashboard/data.edge @@ -122,6 +122,9 @@ Name + + Last Name + Order @@ -147,6 +150,9 @@ {{ workspace.name }} + + {{ workspace.lastname }} + {{ workspace.order }} -- cgit v1.2.3-70-g09d2 From 5296311b393a61b08e771d3074a8a9c7258533cc Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Sun, 7 Feb 2021 09:49:21 +0100 Subject: Fix regarding CR comments - username should be added to user and not to workspace --- resources/views/dashboard/data.edge | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/views/dashboard/data.edge b/resources/views/dashboard/data.edge index 92a78d4..cf48c1c 100644 --- a/resources/views/dashboard/data.edge +++ b/resources/views/dashboard/data.edge @@ -48,6 +48,14 @@ {{ username }} + + + Last Name + + + {{ lastname }} + + Created account on @@ -122,9 +130,6 @@ Name - - Last Name - Order @@ -150,9 +155,6 @@ {{ workspace.name }} - - {{ workspace.lastname }} - {{ workspace.order }} -- cgit v1.2.3-70-g09d2 From 07be43b09308c609fe3d3c9efa2c7a2cab34173f Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Thu, 11 Feb 2021 22:03:59 +0100 Subject: Fix import from Franz by adding additional headers and body to login request --- app/Controllers/Http/UserController.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js index e367d99..09da261 100644 --- a/app/Controllers/Http/UserController.js +++ b/app/Controllers/Http/UserController.js @@ -258,12 +258,19 @@ class UserController { let token; try { const basicToken = btoa(`${email}:${hashedPassword}`); + const loginBody = { + isZendeskLogin: false + }; const rawResponse = await fetch(`${base}auth/login`, { method: 'POST', + body: JSON.stringify(loginBody), headers: { Authorization: `Basic ${basicToken}`, 'User-Agent': userAgent, + 'Content-Type': 'application/json', + 'accept': '*/*', + 'x-franz-source': 'Web' }, }); const content = await rawResponse.json(); -- cgit v1.2.3-70-g09d2 From 555ce7ce135ad6aee3dc31983d2b93b148218edb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 02:33:58 +0000 Subject: Bump hosted-git-info from 2.8.8 to 2.8.9 Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9. - [Release notes](https://github.com/npm/hosted-git-info/releases) - [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md) - [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6c5fece..8114529 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3066,9 +3066,9 @@ } }, "hosted-git-info": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", - "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "http-cache-semantics": { -- cgit v1.2.3-70-g09d2 From a0ef2d216359c8508e9544b589dd0576a393c469 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 09:23:19 +0000 Subject: Bump lodash from 4.17.19 to 4.17.21 Bumps [lodash](https://github.com/lodash/lodash) from 4.17.19 to 4.17.21. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.19...4.17.21) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8114529..6680dae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3842,9 +3842,9 @@ } }, "lodash": { - "version": "4.17.19", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", - "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.includes": { "version": "4.3.0", -- cgit v1.2.3-70-g09d2 From e3e17652c7d90fed0f981d68b875fec9ce71d041 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 19 May 2021 10:33:26 +0530 Subject: [Housekeeping] Added missing hygiene configs/files for developer/contributor. --- .gitignore | 3 ++ .npmrc | 2 + .nvmrc | 1 + CONTRIBUTING.md | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 39 +++++++++------ package.json | 7 ++- 6 files changed, 187 insertions(+), 16 deletions(-) create mode 100644 .npmrc create mode 100644 .nvmrc create mode 100644 CONTRIBUTING.md diff --git a/.gitignore b/.gitignore index 0f1f969..afef829 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ recipes/ resources/announcements/*.json !resources/announcements/version.json npm-debug.log +yarn-error.log +server*.log +.idea diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..aafab16 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +save-exact = true +engine-strict = true diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..6b17d22 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14.16.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d276763 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,151 @@ +# Contributing to ferdi-server + +:tada: First off, thanks for taking the time and your effort to make Ferdi better! :tada: + +## Table of contents + + + +- [Contributing to ferdi-server](#contributing-to-ferdi-server) + - [Table of contents](#table-of-contents) + - [Code of Conduct](#code-of-conduct) + - [What should I know before I get started?](#what-should-i-know-before-i-get-started) + - [How Can I Contribute?](#how-can-i-contribute) + - [Setting up your Development machine](#setting-up-your-development-machine) + - [Install System-level dependencies](#install-system-level-dependencies) + - [Node.js, npm, node-gyp](#nodejs-npm-node-gyp) + - [Git](#git) + - [Clone repository with submodule](#clone-repository-with-submodule) + - [Install dependencies](#install-dependencies) + - [Styleguide](#styleguide) + - [Git Commit Messages format](#git-commit-messages-format) + - [Javascript Coding style-checker](#javascript-coding-style-checker) + + + +## Code of Conduct + +This project and everyone participating in it is governed by the [Ferdi Code of Conduct](https://github.com/getferdi/ferdi/blob/develop/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [stefan@adlk.io](mailto:stefan@adlk.io). + +## What should I know before I get started? + +For the moment, Ferdi's development is a bit slow but all contributions are highly appreciated. [Check this issue for discussion](https://github.com/getferdi/ferdi/issues/956). + +## How Can I Contribute? + +As a basic rule, before filing issues, feature requests or anything else. Take a look at the issues and check if this has not already been reported by another user. If so, engage in the already existing discussion. + +## Setting up your Development machine + +### Install System-level dependencies + +#### Node.js, npm, node-gyp + +Please make sure you are running the exact node version used by the developers/contributors as specified in the [nvmrc file](./.nvmrc). + +Currently, these are the combinations of system dependencies that work on an intel-based machines for MacOS/Linux/Windows (building on an ARM-based machine is still a work-in-progress due to node-sass native dependencies) + +```bash +node -v +v14.16.1 +npm -v +6.14.12 +node-gyp -v +v8.0.0 +``` + +#### Git + +The version [2.23.0](https://github.com/git-for-windows/git/releases/tag/v2.23.0.windows.1) for Git is working fine for development. You can then use the console from Git to do the development procedure. + + + +### Clone repository with submodule + +```bash +git clone https://github.com/getferdi/server.git +cd server +git submodule update --init --recursive +``` + +It is important you execute the last command to get the required submodules (recipes, server). + +### Install dependencies + +- Run the following command to install all dependencies, and link sibling modules with ferdi-server. + +```bash +npm i +``` + +- Copy the `.env.example` file into `.env` and change the values to match your system. + +```bash +cp .env.example .env +``` + +_Note:_ + +1. Have env DB_SSL=true only if your database is postgres and it is hosted online on platforms like GCP, AWS, etc +2. You will have to provide a value for `API_KEY` that is at least 16 characters long. + +- If using sqlite for local development, create the database directory (whatever is set to `DATA` in `.env`) + +```bash +mkdir -p data +``` + +- Run the database migrations with + + ```bash + node ace migration:refresh + ``` + +- To get the full functionality, you will need to have an SMTP server running for local development. + + + +### Start development app + + ```bash + npm start --dev + ``` + +### Styleguide + +#### Git Commit Messages format + +- Use the present tense ("Add feature" not "Added feature") +- Use the imperative mood ("Move cursor to..." not "Moves cursor to...") +- Limit the first line to 72 characters or less +- Reference issues and pull requests liberally after the first line +- When only changing documentation, include `[ci skip]` in the commit description + +#### Javascript Coding style-checker + +- Please use `es-lint` and the defined rules to maintain a consistent style diff --git a/README.md b/README.md index 098ba16..d6ff0ff 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 

- +

# ferdi-server @@ -16,6 +16,7 @@ Official Server software for the [Ferdi Messaging Browser](https://getferdi.com) - [Transferring user data](#transferring-user-data) - [Creating and using custom recipes](#creating-and-using-custom-recipes) - [Listing custom recipes](#listing-custom-recipes) + - [Contributing to ferdi-server's development](#contributing-to-ferdi-servers-development) - [License](#license) ## Why use a custom Ferdi server? @@ -37,7 +38,7 @@ If you are not interested in doing this you can use our official instance of Fer ### with Docker The easiest way to set up Ferdi server on your server is with Docker. -The Docker image can be run as is, with the default sqlite database or you can modifying your ENV variables to use an external database (e.g. MySQL, MariaDB, Postgres, etc). +The Docker image can be run as is, with the default sqlite database or you can modifying your ENV variables to use an external database (e.g. MySQL, MariaDB, Postgres, etc). After setting up the docker container we recommend you to set up an NGINX reverse proxy to access ferdi-server outside of your home network and protect it with an SSL certificate. 1. Pull the Docker image @@ -47,11 +48,11 @@ After setting up the docker container we recommend you to set up an NGINX revers ``` 2. Create a new Docker container with your desired configuration - ```sh + ```sh docker create \ --name=ferdi-server \ -e NODE_ENV=development \ - -e EXTERNAL_DOMAIN= \ + -e EXTERNAL_DOMAIN= \ -e DB_CONNECTION= \ -e DB_HOST= \ -e DB_PORT= \ @@ -75,7 +76,7 @@ After setting up the docker container we recommend you to set up an NGINX revers -v :/app/database \ -v :/app/recipes \ --restart unless-stopped \ - getferdi/ferdi-server + getferdi/ferdi-server ``` Alternatively, you can also use docker-compose v2 schemas @@ -89,7 +90,7 @@ After setting up the docker container we recommend you to set up an NGINX revers container_name: ferdi-server environment: - NODE_ENV=development - - EXTERNAL_DOMAIN= + - EXTERNAL_DOMAIN= - DB_CONNECTION= - DB_HOST= - DB_PORT= @@ -116,34 +117,32 @@ After setting up the docker container we recommend you to set up an NGINX revers - :80 restart: unless-stopped ``` + 3. Optionally, you can now [set up Nginx as a reverse proxy](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-a-reverse-proxy-server). For more information on configuring the Docker image, visit the Docker image repository at . ### Manual setup + 1. Clone this repository 2. Install the [AdonisJS CLI](https://adonisjs.com/) 3. Copy `.env.example` to `.env` and edit the [configuration](#configuration) to your needs 4. Have env DB_SSL=true only if your database is postgres and it is hosted online on platforms like GCP, AWS, etc 5. Run `npm install` to install local dependencies 6. Run the database migrations with + ```js - adonis migration:run + node ace migration:run ``` + 7. Start the server with - ```js - adonis serve --dev - ``` -8. If on previous step it does not run the server then run with + ```js npm start ``` - or - ```js - node server.js - ``` ## Configuration + franz-server's configuration is saved inside the `.env` file. Besides AdonisJS's settings, ferdi-server has the following custom settings: - `IS_CREATION_ENABLED` (`true` or `false`, default: `true`): Whether to enable the [creation of custom recipes](#creating-and-using-custom-recipes) - `IS_REGISTRATION_ENABLED` (`true` or `false`, default: `true`): Whether to enable the creation of new user accounts @@ -153,19 +152,23 @@ franz-server's configuration is saved inside the `.env` file. Besides AdonisJS's - Import Franz accounts ## Importing your Franz account + ferdi-server allows you to import your full Franz account, including all its settings. To import your Franz account, open `http://[YOUR FERDI-SERVER]/import` in your browser and login using your Franz account details. ferdi-server will create a new user with the same credentials and copy your Franz settings, services and workspaces. ## Transferring user data + Please refer to ## Creating and using custom recipes + ferdi-server allows to extends the Franz recipe catalogue with custom Ferdi recipes. For documentation on how to create a recipe, please visit [the official guide by Franz](https://github.com/meetfranz/plugins/blob/master/docs/integration.md). To add your recipe to ferdi-server, open `http://[YOUR FERDI-SERVER]/new` in your browser. You can now define the following settings: + - `Author`: Author who created the recipe - `Name`: Name for your new service. Can contain spaces and unicode characters - `Service ID`: Unique ID for this recipe. Does not contain spaces or special characters (e.g. `google-drive`) @@ -173,7 +176,13 @@ To add your recipe to ferdi-server, open `http://[YOUR FERDI-SERVER]/new` in you - `Recipe files`: Recipe files that you created using the [Franz recipe creation guide](https://github.com/meetfranz/plugins/blob/master/docs/integration.md). Please do *not* package your files beforehand - upload the raw files (you can drag and drop multiple files). ferdi-server will automatically package and store the recipe in the right format. Please also do not drag and drop or select the whole folder, select the individual files. ### Listing custom recipes + Inside Ferdi, searching for `ferdi:custom` will list all your custom recipes. +## Contributing to ferdi-server's development + +We welcome all contributors. Please read the [contributing guidelines](CONTRIBUTING.md) to setup your development machine and proceed. + ## License + ferdi-server is licensed under the MIT License diff --git a/package.json b/package.json index 5b25aac..85a2082 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,15 @@ "adonis-version": "4.1.0", "description": "Ferdi server to replace the default Franz server.", "main": "index.js", + "engines": { + "node": "^14.16", + "npm": "^6.14", + "node-gyp": "^8.0" + }, "scripts": { "start": "node server.js", "test": "node ace test", - "lint": "eslint --fix ./" + "lint": "eslint --quiet --fix ./" }, "keywords": [ "adonisjs", -- cgit v1.2.3-70-g09d2 From a227833e66eebbed9c0dae8cd74b276eb7bbc572 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 19 May 2021 10:37:34 +0530 Subject: Fixed #56: Added favicon for all html pages served by the server. --- public/img/favicon.ico | Bin 0 -> 4286 bytes public/privacy.html | 1 + public/terms.html | 1 + resources/views/layouts/main.edge | 1 + resources/views/layouts/v2.edge | 1 + 5 files changed, 4 insertions(+) create mode 100644 public/img/favicon.ico diff --git a/public/img/favicon.ico b/public/img/favicon.ico new file mode 100644 index 0000000..4ec9d51 Binary files /dev/null and b/public/img/favicon.ico differ diff --git a/public/privacy.html b/public/privacy.html index ac17608..33302ad 100644 --- a/public/privacy.html +++ b/public/privacy.html @@ -8,6 +8,7 @@ Privacy Policy - Ferdi API + diff --git a/public/terms.html b/public/terms.html index 270e3ab..d7ef44b 100644 --- a/public/terms.html +++ b/public/terms.html @@ -8,6 +8,7 @@ Terms of Service - Ferdi API +