Skip to content

Commit

Permalink
Merge pull request #2 from ab-noori/authentication
Browse files Browse the repository at this point in the history
Authentication
  • Loading branch information
ab-noori authored Sep 20, 2023
2 parents 8ecb4cf + 0c51541 commit 2bcebe1
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gem 'devise'

gem 'rubocop', '>= 1.0', '< 2.0'

# gem 'sassc'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.0.8'

Expand Down
24 changes: 24 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@
*= require_tree .
*= require_self
*/

.no-underline {
text-decoration: none;
}

/* Define the animation keyframes */
@keyframes pulse {
0% {
transform: scale(1);
}

50% {
transform: scale(1.05);
}

100% {
transform: scale(1);
}
}

/* Apply the animation to the logo image */
.logo-image {
animation: pulse 3s infinite;
}
48 changes: 25 additions & 23 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<h2>Sign up</h2>
<%= render partial: 'layouts/shared/navbar', locals: { back_destination: root_path, page_name: 'Sign Up', link: { destination: new_user_session_path, label: 'Log In' } } %>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="mb-3">
<%= f.text_field :name, class: "form-control", placeholder: "Name", autocomplete: "name" %>
</div>

<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
<div class="mb-3">
<%= f.email_field :email, class: "form-control", placeholder: "Email", autofocus: true, autocomplete: "email" %>
</div>

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
<div class="mb-3">
<%= f.password_field :password, class: "form-control", placeholder: "Password (6 characters minimum)", autocomplete: "new-password" %>
</div>

<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<div class="mb-3">
<%= f.password_field :password_confirmation, class: "form-control", placeholder: "Confirm Password", autocomplete: "new-password" %>
</div>

<%= render "devise/shared/links" %>
<div class="text-center">
<%= f.submit "Sign up", class: "btn btn-primary btn-md" %>
</div>
<% end %>
</div>
</div>
</div>
50 changes: 29 additions & 21 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
<h2>Log in</h2>
<%= render partial: 'layouts/shared/navbar', locals: { back_destination: root_path, page_name: 'Log In', link: { destination: new_user_registration_path, label: 'Sign Up' } } %>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>

<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "current-password" %>
</div>
<div class="mb-3">
<%= f.email_field :email, class: "form-control", placeholder: "Email", autofocus: true, autocomplete: "email" %>
</div>

<% if devise_mapping.rememberable? %>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end %>
<div class="mb-3">
<%= f.password_field :password, class: "form-control", placeholder: "Password", autocomplete: "current-password" %>
</div>

<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<% if devise_mapping.rememberable? %>
<div class="mb-3">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end %>

<%= render "devise/shared/links" %>
<div class="mb-3">
<%= f.submit "Log in", class: "btn btn-primary btn-md" %>
</div>
<% end %>

<div>
<%= render "devise/shared/links" %>
</div>
</div>
</div>
</div>
6 changes: 1 addition & 5 deletions app/views/devise/shared/_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<%= link_to "Forgot your password?", new_password_path(resource_name), class: "no-underline" %><br />
<% end %>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
Expand Down
27 changes: 27 additions & 0 deletions app/views/layouts/shared/_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="container mt-4 col-md-4">
<!-- Bootstrap alert for notice -->
<% if notice.present? %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<%= notice %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<script>
setTimeout(function(){
document.querySelector('.alert-success').style.display = 'none';
}, 5000); // Hide after 5 seconds (adjust as needed)
</script>
<% end %>

<!-- Bootstrap alert for alert -->
<% if alert.present? %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<%= alert %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<script>
setTimeout(function(){
document.querySelector('.alert-danger').style.display = 'none';
}, 5000); // Hide after 5 seconds (adjust as needed)
</script>
<% end %>
</div>
14 changes: 14 additions & 0 deletions app/views/layouts/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<nav class="navbar navbar-expand-lg navbar-light bg-primary bg-gradient">
<div class="container">
<% if back_destination.present? %>
<a href="<%= back_destination %>" class="btn btn-link text-white">
<i class="fas fa-arrow-left fa-lg"></i>
</a>
<% end %>
<span class="navbar-brand mx-auto text-white"><%= page_name %></span>

<% if link.present? %>
<a href="<%= link[:destination] %>" class="ml-2 text-white no-underline"><%= link[:label] %></a>
<% end %>
</div>
</nav>
20 changes: 12 additions & 8 deletions app/views/splash/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<div class="container-fluid text-center">
<div class="container text-center">
<div class="row mt-5">
<div class="col-md-6 offset-md-3">
<h1 class="display-4">Welcome to Finance Tracker</h1>
<img src="<%= asset_path('logo.png') %>" alt="Finance Tracker Logo" class="img-fluid my-4">
<img src="<%= asset_path('logo.png') %>" alt="Finance Tracker Logo" class="img-fluid my-4 logo-image">
<p class="lead">Track your finances with ease.</p>
</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="d-grid gap-2">
<%= link_to "Sign in", new_user_session_path, class: "btn btn-primary btn-lg mb-2" %>
<%= link_to "Sign up", new_user_registration_path, class: "btn btn-secondary btn-lg" %>
</div>

<div class="fixed-bottom text-center mb-2">
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="d-grid gap-1">
<%= link_to "Sign in", new_user_session_path, class: "btn btn-primary btn-lg mb-1" %>
<%= link_to "Sign up", new_user_registration_path, class: "btn btn-success btn-lg" %>
</div>
</div>
</div>
</div>
</div>

2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0

# config.assets.css_compressor = :sass

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20230916144014_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name
t.string :role, default: "Guest" # Add default role
t.string :role, default: "User" # Add default role

t.timestamps
end
Expand Down

0 comments on commit 2bcebe1

Please sign in to comment.