Skip to content

Commit fc5b37e

Browse files
committed
enable sign up
1 parent ac91a59 commit fc5b37e

9 files changed

Lines changed: 104 additions & 8 deletions

File tree

app/assets/stylesheets/application.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ul { list-style: none; }
4646
border-bottom: 1px solid var(--color-border);
4747
padding: 0 24px;
4848
display: flex;
49+
justify-content: space-between;
4950
align-items: center;
5051
height: 56px;
5152
gap: 24px;
@@ -269,6 +270,10 @@ ul { list-style: none; }
269270
border: 1px solid var(--color-border);
270271
border-radius: var(--radius-lg);
271272
box-shadow: var(--shadow-sm);
273+
274+
&.centered {
275+
margin: 0 auto;
276+
}
272277
}
273278
.form-group {
274279
margin-bottom: 20px;
@@ -283,6 +288,8 @@ ul { list-style: none; }
283288
.form-group input[type="text"],
284289
.form-group input[type="number"],
285290
.form-group input[type="date"],
291+
.form-group input[type="email"],
292+
.form-group input[type="password"],
286293
.form-group select {
287294
width: auto%;
288295
padding: 9px 12px;
@@ -294,6 +301,12 @@ ul { list-style: none; }
294301
background: var(--color-bg);
295302
transition: border-color .15s, box-shadow .15s;
296303
}
304+
305+
.form-group input[type="email"],
306+
.form-group input[type="password"] {
307+
width: 100%;
308+
}
309+
297310
.form-group input:focus,
298311
.form-group select:focus {
299312
outline: none;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class RegistrationsController < ApplicationController
2+
allow_unauthenticated_access
3+
before_action { redirect_to root_url if authenticated? }
4+
5+
def new
6+
@user = User.new
7+
end
8+
9+
def create
10+
@user = User.new(user_params)
11+
12+
if @user.save
13+
start_new_session_for(@user)
14+
redirect_to root_url
15+
else
16+
render :new, status: :unprocessable_content
17+
end
18+
end
19+
20+
private
21+
22+
def user_params
23+
params.expect(user: [ :email_address, :password ])
24+
end
25+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module RegistrationsHelper
2+
end

app/models/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ class User < ApplicationRecord
44
has_many :budgets, dependent: :destroy
55

66
normalizes :email_address, with: ->(e) { e.strip.downcase }
7+
8+
validates :password, length: { minimum: 8 }, on: :create
79
end

app/views/layouts/application.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<body>
2828
<nav class="nav">
2929
<%= link_to "Tally", budgets_path, class: "nav__brand" %>
30+
<% if authenticated? %>
31+
<%= button_to "Logout", session_path, method: :delete, class: "btn btn-secondary" %>
32+
<% else %>
33+
<%= link_to "Sign Up", new_registration_path, class: "btn btn-primary" %>
34+
<% end %>
3035
</nav>
3136

3237
<main class="container">
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
2+
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
3+
4+
<div class="form-card centered">
5+
<%= form_with model: @user, url: registrations_path do |form| %>
6+
<% if form.object.errors.any? %>
7+
<div class="error-list">
8+
<h2><%= pluralize(form.object.errors.count, "error") %> prohibited this:</h2>
9+
<ul>
10+
<% form.object.errors.each do |error| %>
11+
<li><%= error.full_message %></li>
12+
<% end %>
13+
</ul>
14+
</div>
15+
<% end %>
16+
17+
<div class="form-group">
18+
<%= form.label :email_address %>
19+
<%= form.email_field :email_address, required: true, autofocus: true, placeholder: "Enter your email address" %>
20+
</div>
21+
22+
<div class="form-group">
23+
<%= form.label :password %>
24+
<%= form.password_field :password, required: true, placeholder: "Enter your password" %>
25+
</div>
26+
27+
<div class="form-actions">
28+
<%= form.submit "Sign up", class: "btn btn-primary" %>
29+
</div>
30+
<% end %>
31+
</div>

app/views/sessions/new.html.erb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
22
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
33

4-
<%= form_with url: session_path do |form| %>
5-
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
6-
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
7-
<%= form.submit "Sign in" %>
8-
<% end %>
9-
<br>
10-
11-
<%= link_to "Forgot password?", new_password_path %>
4+
<div class="form-card centered">
5+
<%= form_with url: session_path do |form| %>
6+
<div class="form-group">
7+
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %>
8+
</div>
9+
10+
<div class="form-group">
11+
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password" %>
12+
</div>
13+
14+
<div class="form-actions">
15+
<%= form.submit "Sign in", class: "btn btn-primary" %>
16+
</div>
17+
<% end %>
18+
<br>
19+
20+
<%= link_to "Forgot password?", new_password_path %>
21+
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Rails.application.routes.draw do
22
resource :session
3+
resources :registrations
34
resources :passwords, param: :token
45
resources :budgets do
56
resources :transactions, except: [ :index, :show ]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)