diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0d95db2..ce2bb32 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,4 +1,10 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
+
+ helper_method :current_user
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index ba061be..b1b7356 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,18 +1,22 @@
class SessionsController < ApplicationController
- def new
- end
-
def create
user = User.find_by(email: params[:email])
- respond_to do |format|
if user && user.authenticate(params[:password])
+
session[:user_id] = user.id
- format.html { redirect_back(fallback_location: root_path, notice: "Logged in successfully.") }
- format.json { render :show, status: :created, location: user }
+ redirect_to user_path(user), notice: "Logged in successfully."
else
- format.html { render :new, status: :unprocessable_entity }
+ message = "Something went wrong! Make sure your username and password are correct."
+ redirect_to login_path, notice: message
end
+ end
+
+ def login
+ if session[:user_id]
+ redirect_to user_path(session[:user_id]), notice: "You already logged in."
+ else
+ render :login
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2adc274..e4a385d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,10 +1,10 @@
module ApplicationHelper
- def current_user
- @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ def logged_in?
+ !!session[:user_id]
end
- def logged_in?
- !!current_user
+ def current_user
+ @current_user ||= User.find_by_id(session[:user_id]) if !!session[:user_id]
end
def authenticate_user!
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb
index 7f2b96d..115ac12 100644
--- a/app/views/layouts/_footer.html.erb
+++ b/app/views/layouts/_footer.html.erb
@@ -14,6 +14,7 @@
- <%= link_to 'Home', root_path, class: 'text-white' %>
- <%= link_to 'Pets', pets_path, class: 'text-white' %>
+ - <%= link_to 'Contribute', contribute_guide_path, target: '_blank', class: 'text-white' %>
<%
=begin%>
- <%= link_to 'Privacy Policy', privacy_policy_path, class: 'text-white' %>
diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb
index c4c25bf..7ab664c 100644
--- a/app/views/layouts/_navbar.html.erb
+++ b/app/views/layouts/_navbar.html.erb
@@ -15,15 +15,27 @@
<%= link_to 'Home', root_path, class: 'nav-link active' %>
-
- <%= link_to 'Pets', pets_path, class: 'nav-link active' %>
+ <%= link_to 'Pet Members', pets_path, class: 'nav-link active' %>
- -
- <%= link_to 'Open Source', github_repo_path, class: 'nav-link active' %>
+
-
+ <%= link_to 'Open Source', github_repo_path, class: 'nav-link active', target: '_blank' %>
+ -
+ <%= link_to "Register new pet for Free", new_pet_path, class: "btn btn-success mt-3" %>
+
-
diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb
new file mode 100644
index 0000000..e519dde
--- /dev/null
+++ b/app/views/sessions/login.html.erb
@@ -0,0 +1,18 @@
+
+
Log In
+ <%= form_tag '/login', class: 'needs-validation' do %>
+
+ <%= label_tag :email, "Username", class: 'form-label' %>
+ <%= text_field_tag :email, nil, class: 'form-control' %>
+
+
+
+ <%= label_tag :password, "Password", class: 'form-label' %>
+ <%= password_field_tag :password, nil, class: 'form-control' %>
+
+
+
+ <%= submit_tag "Log In", class: 'btn btn-primary' %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
deleted file mode 100644
index 678ed04..0000000
--- a/app/views/sessions/new.html.erb
+++ /dev/null
@@ -1,17 +0,0 @@
-Log In
-
-<%= form_with url: sessions_path, local: true do |form| %>
-
- <%= form.label :email %>
- <%= form.email_field :email %>
-
-
-
- <%= form.label :password %>
- <%= form.password_field :password %>
-
-
-
- <%= form.submit "Log In" %>
-
-<% end %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
index dc74c44..dd21fd0 100644
--- a/app/views/users/new.html.erb
+++ b/app/views/users/new.html.erb
@@ -1,9 +1,9 @@
-Sign Up
+Sign Up
-<%= form_with model: @user, local: true do |form| %>
+<%= form_with model: @user, local: true, class: 'needs-validation' do |form| %>
<% if @user.errors.any? %>
-
-
<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:
+
+
<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:
<% @user.errors.full_messages.each do |message| %>
- <%= message %>
@@ -12,45 +12,45 @@
<% end %>
-
- <%= form.label :name %>
- <%= form.text_field :name %>
+
+ <%= form.label :name, class: 'form-label' %>
+ <%= form.text_field :name, class: 'form-control' %>
-
- <%= form.label :email %>
- <%= form.email_field :email %>
+
+ <%= form.label :email, class: 'form-label' %>
+ <%= form.email_field :email, class: 'form-control' %>
-
- <%= form.label :password %>
- <%= form.password_field :password %>
+
+ <%= form.label :password, class: 'form-label' %>
+ <%= form.password_field :password, class: 'form-control' %>
-
- <%= form.label :password_confirmation %>
- <%= form.password_field :password_confirmation %>
+
+ <%= form.label :password_confirmation, class: 'form-label' %>
+ <%= form.password_field :password_confirmation, class: 'form-control' %>
-
- <%= form.submit "Sign Up" %>
+
+ <%= form.submit "Sign Up", class: 'btn btn-primary' %>
<% end %>
-
Log In
+
Log In
-<%= form_with url: login_path, local: true do |form| %>
-
- <%= form.label :email %>
- <%= form.email_field :email %>
+<%= form_with url: login_path, local: true, class: 'needs-validation' do |form| %>
+
+ <%= form.label :email, class: 'form-label' %>
+ <%= form.email_field :email, class: 'form-control' %>
-
- <%= form.label :password %>
- <%= form.password_field :password %>
+
+ <%= form.label :password, class: 'form-label' %>
+ <%= form.password_field :password, class: 'form-control' %>
-
- <%= form.submit "Log In" %>
+
+ <%= form.submit "Log In", class: 'btn btn-primary' %>
<% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index f9b42e2..88bfd37 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -1,9 +1,19 @@
-
<%= @user.name %>
-
Email: <%= @user.email %>
+
<%= @user.name %>
+
Registered e-mail: <%= @user.email %>
+
+ <%= link_to 'Edit User Info', edit_user_path(@user), class: 'btn btn-warning' %>
+
-
Pets
-