Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 75 additions & 12 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,78 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*= require_tree .
*/

body {
margin: 0;
padding: 0;
height: 100dvh;
font-family: Arial, Helvetica, sans-serif;
}

#navbar-container {
border-bottom: 1px solid #eee;
}

#navbar {
display: flex;
justify-content: space-between;
width: 70%;
margin: 0 auto;
padding: 10px;
font-size: 20px;
}

#navbar-title {
font-weight: 600;
}

#navbar-items {
display: flex;
gap: 15px;
}


/* Login page */
#login-container {
height: 100dvh;
display: flex;
flex-direction: column;
align-items: center;
}

#login-inputs {
display: flex;
align-items: center;
flex-direction: column;
gap: 15px;
}

#login-container .input-div input {
box-sizing: border-box;
width: 100%;
border: 1px solid gray;
padding: 7px 10px;
border-radius: 6px;
}

#login-button {
margin-top: 10px;
width: 150px;
cursor: pointer;
background-color: #1877f2;
color: white;
font-weight: 600;
font-size: 18px;
padding: 7px 0px;
border: none;
border-radius: 6px;
}

#login-button:hover {
background-color: #4267b2;
}

#login-button:active {
background-color: #264177;
}
2 changes: 0 additions & 2 deletions app/controllers/admin/team_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/admin/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Admin::TeamsController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/admin/user_controller.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin::UsersController < ApplicationController

def index
@users = User.all
end
end
22 changes: 21 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
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
# allow_browser versions: :modern

helper_method :current_user

def current_user
@current_user ||= session[:user_id] && User.find_by(id: session[:user_id])
end

before_action :require_login

private

def require_login
unless logged_in?
redirect_to login_path
end
end

def logged_in?
!!current_user
end
end
2 changes: 0 additions & 2 deletions app/controllers/bike_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/bikes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class BikesController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/manage/team_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/manage/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Manage::TeamsController < ApplicationController
end
2 changes: 2 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PagesController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/part_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/parts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PartsController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/service_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ServicesController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/team_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class TeamsController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/controllers/user_controller.rb

This file was deleted.

24 changes: 24 additions & 0 deletions app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class UserSessionsController < ApplicationController
# Login is not required for these actions
skip_before_action :require_login, only: [:new, :create]
def new
@user = User.new
end

def create
@user = User.find_by(email: params[:user][:email])

if @user && @user.authenticate(params[:user][:password])
session[:user_id] = @user.id
redirect_to root_path
else
flash[:alert] = "Login failed"
redirect_to new_user_session_path
end
end

def destroy
session[:user_id] = nil
redirect_to login_path
end
end
28 changes: 28 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class UsersController < ApplicationController
skip_before_action :require_login, only: [:new, :create]
def show
@user = current_user
end

def new
@user = User.new
end

def create
@user = User.new(user_params)

if @user.save
flash[:notice] = "User created successfully"
redirect_to users_path
else
flash[:alert] = "User not created"
render :new, status: :unprocessable_entity
end
end

private

def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation)
end
end
2 changes: 2 additions & 0 deletions app/helpers/user_sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UserSessionsHelper
end
5 changes: 4 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class User < ApplicationRecord
belongs_to :team
has_secure_password
validates :email, presence: true, uniqueness: true
validates :name, presence: true, uniqueness: true
belongs_to :team, optional: true
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h1>All Users</h1>

<%= link_to 'New user', new_user_path %>

<table>
<thead>
<tr>
<th>id</th>
<th>email</th>
<th>name</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.id %></td>
<td><%= user.email %></td>
<td><%= user.name %></td>
</tr>
<% end %>
</tbody>
</table>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
</head>

<body>
<% flash.each do |type, msg| %>
<div>
<%= msg %>
</div>
<% end %>

<% if current_user %>
<div id="navbar-container">
<div id="navbar">
<div id="navbar-title">Motorify</div>
<div id="navbar-items">
<%= link_to 'Profile', profile_path, method: :get %>
<%= link_to 'Logout', logout_path, method: :get %>
</div>
</div>
</div>
<% end %>

<%= yield %>
</body>
</html>
File renamed without changes.
6 changes: 6 additions & 0 deletions app/views/pages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if current_user %>
<h1>Welcome, <%= current_user.name %></h1>
<% else %>
<h1>This is the index page</h1>
<%= link_to 'Login', new_user_session_path %><br>
<% end %>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions app/views/user/index.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/user/new.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/user/show.html.erb

This file was deleted.

2 changes: 2 additions & 0 deletions app/views/user_sessions/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>UserSessions#create</h1>
<p>Find me in app/views/user_sessions/create.html.erb</p>
15 changes: 15 additions & 0 deletions app/views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="login-container">
<h1>Motorify</h1>
<div>Login</div>
<%= form_with model: @user, id:'login-inputs', url: user_sessions_path do |f| %>
<div class="input-div">
<%= f.label :email %><br>
<%= f.text_field :email %>
</div>
<div class="input-div">
<%= f.label :password %><br>
<%= f.password_field :password %>
</div>
<%= f.submit 'Login', id:'login-button' %>
<% end %>
</div>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>Sign up</h1>

<%= form_with model: @user do |f| %>
<% if @user.errors.any? %>
<div>
<ul>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= f.label :email %><br>
<%= f.text_field :email %>
</div>
<div>
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :password %><br>
<%= f.password_field :password %>
</div>
<div>
<%= f.label :password_confirmation %><br>
<%= f.password_field :password_confirmation %>
</div>
<p>
<%= f.submit %>
</p>
<% end %>

11 changes: 11 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p style="color: green"><%= notice %></p>

<%= @user.name %>
<%= @user.email %>
<%= @user.team_id %>

<div>
<%= link_to "Change password", edit_user_path(@user) %>
<%= link_to "Edit", edit_user_path(@user) %>
<%= link_to "Back", root_path %>
</div>
Loading
Loading