Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.

JuzerShakir/session

Repository files navigation

Project: Creating Session in Browser

A Rails webapp that uses cookies to maintain a session with clients' browsers.

wakatime


❗ Objectives

This web-app must accomplish the following:

  • Use the PostgreSQL database which stores the email and password of visitors.
  • Only valid email formats are allowed and it should be unique.
  • Use the BCrypt gem to store a secure hash password and it should be at least 6 to 36 characters long.
  • Show validation error messages (if any) to signing in visitors.
  • Create a session using CookieStore as soon as visitors sign up.
  • Show different homepage content for signed-in and non-signed-in visitors.
  • If a visitor logs in with an email that doesn't exist in the database, redirect them to the signup page.
  • If a visitor signs up with an email that exists in our database then redirect them to the sign-in page.
  • Show appropriate flash messages wherever necessary like new sign up, sign in, logout, etc.
  • Show visitor sign-up count for both logged out and logged in visitors.
  • Redirect logged-in visitor to the homepage if he tries to visit the log-in or signup page.
  • Build a responsive site using bootstrap.
  • Show logged-in visitors different ways of destroying the session.
  • When a visitor manually enters a URL that doesn't exist, redirect them to the homepage with a flash message informing them that the URL doesn't exist.

💎 Required Gems

This project was built on Ruby version 2.7.2.

Following important gems were installed in these versions:

Gem Names Gem Version Use
Rails 'rails' 6.1.4.1 Use for executing and rendering web-app
Postgresql 'pg' 1.2.3 Use postgres as the database for Active Record
Bootstrap 'bootstrap-sass' 3.4.1 For SCSS Styling
BCrypt 'bcrypt' 3.1.16 Secure hash algorithm for safely storing passwords

⚙️ Setting up a PostgreSQL user

If you don't have a user set on postgres, here's how to set new user:

sudo -u postgres createuser -s [username]

To set a password for this user, log in to the PostgreSQL command line client:

sudo -u postgres psql

Enter the following command to set the password:

\password your_password

Enter and confirm the password. Then exit the PostgreSQL client:

\q

📋 Execution

Run the following commands to execute locally:

The following will install required version of ruby (make sure rvm is installed.)

rvm use 2.7.2
git clone git@github.com:JuzerShakir/rails-session.git
cd Session-CookieStore
bundle install
rails db:setup
rails s

About

A demonstration of how to implement a session on a rails site using the default session store, the 'CookieStore'

Topics

Resources

Stars

Watchers

Forks

Contributors