This is a complete SaaS example (Software-as-a-Service) using PostgreSQL as a database and Gliimly as a web service engine; it includes user signup/login/logout with an email and password, separate user accounts and data, and a notes application. All in about 200 lines of code!
\ First, create a directory for your application where the source code will be:
mkdir -p notes cd notes Setup Postgres DatabaseCreate a PostgreSQL user (with the same name as your logged-on Linux user, so no password needed), and the database "db_app":
echo "create user $(whoami); create database db_app with owner=$(whoami); grant all on database db_app to $(whoami); \q" | sudo -u postgres psql\ Create a database configuration file to describe your PostgreSQL database above:
echo "user=$(whoami) dbname=db_app" > db_app\ Create database objects we'll need - a users table for application users, and a notes table to hold their notes:
echo "create table if not exists notes (dateOf timestamp, noteId bigserial primary key, userId bigint, note varchar(1000)); create table if not exists users (userId bigserial primary key, email varchar(100), hashed_pwd varchar(100), verified smallint, verify_token varchar(30), session varchar(100)); create unique index if not exists users1 on users (email);" | psql -d db_app Create A Gliimly ApplicationCreate the application "notes" owned by your Linux user:
sudo mgrg -i -u $(whoami) notes Source CodeThis executes before any other handler in an application, making sure all requests are authorized, file "before-handler.gliim":
vi before-handler.gliim\ Copy and paste:
before-handler set-param displayed_logout = false, is_logged_in = false call-handler "/session/check" end-before-handlerSignup users, login, logout
\ This is a generic session management web service that handles user creation, verification, login, and logout. Create file "session.gliim":
vi session.gliim\ Copy and paste:
// Display link to login or signup %% /session/login-or-signup private @>">Login >">Sign UpNotes application
This is the actual application that uses the above session management services. Create file "notes.gliim":
vi notes.gliim\ Copy and paste:
// Delete a note %% /notes/delete public call-handler "/notes/header" get-param sess_user_id, note_id run-query @db_app = "delete from notes where noteId='%s' and userId='%s'" : note_id, sess_user_id \ affected-rows arows no-loop error errnote if-true arows equal 1 @Note deleted else-if @Could not delete note (<In order to use this example, you need to be able to email local users, which means email addresses such as \"myuser@localhost\". To do that, install Postfix (or sendmail). On Debian systems (like Ubuntu):
sudo apt install postfix sudo systemctl start postfix\ and on Fedora systems (like RedHat):
sudo dnf install postfix sudo systemctl start postfix\ When the application sends an email to a local user, such as @localhost, then you can see the email sent at:
sudo vi /var/mail/A web server sits in front of the Gliimly application server, so it needs to be set up. This example is for Ubuntu, so edit the Nginx config file there:
sudo vi /etc/nginx/sites-enabled/default\ Add this in the "server {}" section:
location /notes/ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:///var/lib/gg/notes/sock/sock; }\ Restart Nginx:
sudo systemctl restart nginx You're Done; Run It!Go to your web browser, and enter:
http://127.0.0.1/notes/session/start\
All Rights Reserved. Copyright , Central Coast Communications, Inc.