Rails-Restaurants-API is a web application built with Ruby on Rails that allows users to view and manage restaurants. The application includes user authentication features, an API for working with restaurants, and support for file uploads and email handling.
Follow these steps to install and run the project locally:
git clone https://github.com/shliamin/Rails-Restaurants-API.git
cd Rails-Restaurants-API
Make sure you have Ruby and Bundler installed. Then run:
bundle install
Create and set up the database:
rails db:create
rails db:migrate
rails db:seed
Start the Rails server:
rails server
In this Rails application, user authentication is managed by Devise, a flexible authentication solution for Rails applications. Devise handles the registration, login, logout, and password management for users. It provides a set of ready-made controllers, views, and routes to simplify the authentication process.
Devise provides a full-stack authentication solution based on Warden, a Rack-based authentication framework. It offers a range of features, including:
- User registration
- User login
- Password recovery
- Account management
- Session management
- Email confirmation
Warden is a flexible authentication solution for Ruby applications. It provides a simple way to handle various authentication strategies and is designed to be integrated into Rack-based applications. Warden is often used in conjunction with libraries like Devise to provide a complete authentication system.
Warden works by intercepting requests and checking if the user is authenticated based on predefined strategies. Here's a high-level overview of how Warden operates:
- Middleware Integration: Warden is integrated as Rack middleware. This means it sits between the application and the web server, processing incoming requests and outgoing responses.
- Strategies: Warden uses strategies to authenticate users. A strategy is a piece of code that checks if a user is authenticated based on certain criteria (e.g., checking a session or an API token).
- Sessions: Warden manages user sessions, storing information about authenticated users and their session state.
- Hooks: Warden allows hooks to be defined at various points in the authentication lifecycle (e.g., after authentication, before logout).
-
Strategies: A strategy in Warden is a method of authenticating a user. Each strategy can define how to handle authentication, what conditions need to be met, and how to store user data. Strategies are configurable and can be customized as needed.
-
Scopes: Warden supports multiple authentication scopes. A scope represents a particular context of authentication. For example, an application might have different scopes for users, admins, and API clients.
-
Handlers: Warden handlers process the request and response to check if the user is authenticated. If the user is not authenticated, the handler can redirect them to a login page or return an error.
-
Sessions: Warden stores session data using the Rack session mechanism. This allows it to persist information about the authenticated user across multiple requests.
The application provides an API for working with restaurants. Available routes:
GET /api/v1/restaurants
- get a list of all restaurants
The home page displays a list of all restaurants centered on the page.
app/controllers
- application controllersapp/models
- application modelsapp/views
- application viewsconfig/routes.rb
- routing filedb/migrate
- database migrations
- Efim Shliamin