npm i
NODE_API_URL=https://api.WeYouMe.io
NODE_API_URL_SERVER=https://api.WeYouMe.io
BROADCASTER_USERNAME=CHAIN_ACCOUNT_NAME_STRING
BROADCASTER_POSTING_KEY=CHAIN_ACCOUNT_POSTING_PRIVATE_KEY
JWT_SECRET=somerandomstringthatneedstostaysecret
DEBUG=weauth:*
dburl=postgresql://user:pass@localhost:port/db
PORT=5555
CONTENT_DEFAULT='self'
CONTENT_SCRIPT_SRC='self','unsafe-eval','unsafe-inline'
CONTENT_CONNECT_SRC='self',*.WeYouMe.io
CONTENT_FRAME_SRC='self'
CONTENT_STYLE_SRC='self','unsafe-inline'
CONTENT_IMG_SRC='self',steemitimages.com,steemit-production-imageproxy-thumbnail.s3.amazonaws.com,data:
CONTENT_FONT_SRC='self'
sudo apt-get install postgresql -y
sudo service postgresql initdb
sudo sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql9/data/pg_hba.conf
sudo /sbin/chkconfig --levels 235 postgresql on
sudo service postgresql start
// 1 liner
sudo apt-get install postgresql -y && service postgresql initdb && sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql9/data/pg_hba.conf && /sbin/chkconfig --levels 235 postgresql on && service postgresql start
sudo yum -y install postgresql94 postgresql94-server
sudo service postgresql94 initdb
sudo sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql94/data/pg_hba.conf
sudo service postgresql94 start
// 1 liner
sudo yum -y install postgresql94 postgresql94-server && service postgresql94 initdb && sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql94/data/pg_hba.conf && service postgresql94 start
or
./scripts/install_postgresql_yum.sh
or
./scripts/install_postgresql_apt-get.sh
brew install postgresql
brew services start postgresql
// 1 liner
brew install postgresql && services start postgresql
sudo -u postgres psql
// postgres = linux username , psql = linux cli program
psql postgres
first open psql
sudo -u postgres psql
psql postgres
then run
whoami
user // this is the user you want to be creating within postgresql
sudo -u postgres psql
psql (9.4.17)
Type "help" for help.
postgres=# CREATE ROLE user LOGIN; // replace "user" with the username of the machine ie. what whoami returned above
CREATE ROLE
postgres=# CREATE DATABASE user;
CREATE DATABASE
postgres=# ALTER USER user WITH PASSWORD 'password';
ALTER USER
first open psql
sudo -u user psql // can just run psql if you made the user in postgresql/psql with the same username as your machine username ie. what whoami returns, the default postgresql username is postgres
psql user // can leave blank if you made the user in postgresql/psql with the same username as your machine username ie. what whoami returns, the default postgresql username is postgres
then run
postgres=# CREATE DATABASE weauth; // or name the database whatever you want
CREATE DATABASE
first open psql
sudo -u user psql // can just run psql if you made the user in postgresql/psql with the same username as your machine username ie. what whoami returns, the default postgresql username is postgres
psql user // can leave blank if you made the user in postgresql/psql with the same username as your machine username ie. what whoami returns, the default postgresql username is postgres
then run
password for user: __________
psql (9.4.17)
Type "help" for help.
postgres=# SHOW port;
port
------
5432
(1 row)
postgres=# _
there's a few formats
postgresql://
postgresql://localhost
postgresql://localhost:5432
postgresql://localhost/mydb
postgresql://user@localhost
postgresql://user:secret@localhost
postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
postgresql://localhost/mydb?user=other&password=secret
we're going to use, make sure to replace user, password, localhost, and weauth if you didn't use weauth for your postgresql database name Put this in your .env file as the dburl= variable! :D
postgresql://user:password@localhost:5432/weauth
an npm version of mysql needs to be installed, either mysql or mysql2, it's a dev dependancy but you may need to install it via
npm i -g mysql
or try if necessary
npm i -g mysql2
npm i -g sequelize-cli
We use sequelize to autogenerate some tables and their schemas for postgresql from json schema's stored in db/models. Sequelize will use a connection config stored at db/config.json which looks like the below, you'll have to fill in the username and password and database with the postgresql username and password and database you made above
{
"database": "weauth",
"username": "user",
"password": "password",
"host" : "localhost",
"logging": false,
"dialect" : "postgres",
"operatorsAliases": false,
"pool": {
"max": 150,
"min": 0,
"idle": 10000
},
"port":5432
}
sequelize db:migrate
npm run run
or
npm run build
npm run start
npm run rundev
or
npm run builddev
npm run startdev
/api/me - Get user profile (require user or app token)
/api/ - Broadcast posting operation for user (require app token)
/api/oauth2/authorize - Issue new app token (require user token)
Tokens are created with JWT, the payload is public. Here is how it look:
{
role: 'user',
user: 'guest'
}
The token hash is saved on user localStorage once he login.
{
role: 'app',
proxy: 'example',
user: 'guest',
scope: ['vote', 'comment']
}
The token hash is sent to the application once user authorize the application.
will show a kind of state info showing the database and user you're in
\conninfo
psql (10.5)
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/tmp" at port "5432".
postgres=#
shows roles/users
\dg
database=# \dg
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
user | Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
add attributes to role
database=# ALTER ROLE user WITH SUPERUSER CREATEROLE REPLICATION;
ALTER ROLE
database=# \dg
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
lopu | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
database=# _
creates a database completely from a database
create database "database"
CREATE DATABASE
shows databases
\l
database=# \l
weauth | lopu | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
lopu | lopu | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | lopu | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | lopu | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/lopu +
| | | | | lopu=CTc/lopu
template1 | lopu | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/lopu +
| | | | | lopu=CTc/lopu
connect to the database "database"
\c database
You are now connected to database "database" as user "user".
deletes a database completely from a database
drop database "database"
DROP DATABASE
shows tables in current database
\dt
database=# \dg
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
user | Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
shows a table's "table" schema
\d table
id | integer | | not null | nextval('apps_id_seq'::regclass)
client_id | character varying(255) | | not null |
secret | character varying(255) | | not null |
owner | character varying(255) | | |
redirect_uris | jsonb | | |
name | character varying(255) | | |
description | text | | |
icon | text | | |
website | text | | |
beneficiaries | jsonb | | |
allowed_ips | jsonb | | |
is_approved | boolean | | | true
is_public | boolean | | | false
is_disabled | boolean | | | false
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
shows all of a table's data
select from "table"
select * from "table"
1 | weapp | g34h4w6jw645h54 | webuilder | ["https://alpha.weyoume.io", "http://alpha.weyoume.io"] | weapp | official weapp | | alpha.weyoume.io | | | t | t | f | 2018-09-26 05:54:41.036+10 | 2018-09-26 05:55:20.358+10
delete all data from table
delete from table;
DELETE 1
deletes a table completely from a database
drop table "table"
1 | weapp | g34h4w6jw645h54 | webuilder | ["https://alpha.weyoume.io", "http://alpha.weyoume.io"] | weapp | official weapp | | alpha.weyoume.io | | | t | t | f | 2018-09-26 05:54:41.036+10 | 2018-09-26 05:55:20.358+10
Helpful 1 Liner
\c user ; drop database database ; create database database ; \c database ;
\c lopu ; drop database weauth ; create database weauth ; \c weauth ;
if you fall into authentication woes then you'll have to read about md5, trust, peer, ident authentication methods, ident is annoying, so we want md5, trust, or peer
/etc/init.d/postgresql reload
or
./scripts/repost.sh