Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish user sign up #3

Merged
merged 1 commit into from
Sep 14, 2024
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
Empty file added --color --format doc
Empty file.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

629 changes: 629 additions & 0 deletions .idea/simple_app.iml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
gem 'ostruct'

Check failure on line 19 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
gem 'bcrypt'
gem 'bcrypt', '~> 3.1.7'

Check failure on line 20 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 20 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

gem "sassc-rails"
gem "rails-controller-testing"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ PLATFORMS
x86_64-linux-musl

DEPENDENCIES
bcrypt
bcrypt (~> 3.1.7)
bootsnap
bootstrap-sass (~> 3.4.1)
brakeman
Expand Down
48 changes: 48 additions & 0 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ $gray-medium-light: #eaeaea;

/* universal */

@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

body {
padding-top: 60px;
}
Expand All @@ -21,6 +27,7 @@ textarea {

.center {
text-align: center;

h1 {
margin-bottom: 10px;
}
Expand Down Expand Up @@ -65,6 +72,7 @@ p {
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;

&:hover {
color: white;
text-decoration: none;
Expand All @@ -78,21 +86,61 @@ footer {
padding-top: 5px;
border-top: 1px solid $gray-medium-light;
color: $gray-light;

a {
color: $gray;

&:hover {
color: $gray-darker;
}
}

small {
float: left;
}

ul {
float: right;
list-style: none;

li {
float: left;
margin-left: 15px;
}
}
}
.debug_dump{
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing
}

/* forms */

input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}

input {
height: auto !important;
}

#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}

.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
Empty file.
19 changes: 19 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new', status: :unprocessable_entity

Check failure on line 14 in app/controllers/users_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end
end

private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end

Check failure on line 22 in app/controllers/users_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end.
end
5 changes: 5 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
module UsersHelper
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)

Check failure on line 3 in app/helpers/users_helper.rb

View workflow job for this annotation

GitHub Actions / lint

Style/ColonMethodCall: Do not use `::` for method calls.
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @user.errors.any? %>

<div class="error_explanation">
<div class ='alert alert-danger'>
The form contains <%=pluralize(@user.errors.count,"error") %> errors.
</div>
<ul>
<% @user.errors.full_messages.each do |message| %>
<li>
<%= message %>
</li>
<% end %>
</ul>
</div>
<% end %>
22 changes: 21 additions & 1 deletion app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<p>This will be a signup page for new users.</p>

<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_with(model: @user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :email %>
<%= f.email_field :email %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>

<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% provide(:title, @user.name) %>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
get "about", to: "static_pages#about"
get "contact", to: "static_pages#contact"
get "signup", to: "users#new"
resources :users
end
20 changes: 20 additions & 0 deletions test/integration/users_signup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "test_helper"

class UsersSignupTest < ActionDispatch::IntegrationTest
def setup
@user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
end

test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, params: { user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar" } }
end

assert_template :'users/new'
end

end
Loading