Skip to content

Commit

Permalink
registration form created on main page, user method updated, posts me…
Browse files Browse the repository at this point in the history
…thod updated
  • Loading branch information
moby-codes committed Sep 19, 2021
1 parent c07ba86 commit 2e625af
Show file tree
Hide file tree
Showing 25 changed files with 239 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ gem 'jbuilder', '~> 2.5'
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'


# for users
gem 'devise'
gem 'bootsnap', require: false
gem 'sqlite3', '~> 1.3', '>= 1.3.11'
gem 'therubyracer'
gem 'metro-ui-rails'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
Expand Down
36 changes: 36 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ GEM
ast (2.4.2)
bcrypt (3.1.16)
bindex (0.8.1)
bootsnap (1.9.0)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
capybara (2.18.0)
Expand All @@ -75,9 +77,16 @@ GEM
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
childprocess (3.0.0)
commonjs (0.2.7)
concurrent-ruby (1.1.9)
crass (1.0.6)
date (3.1.1)
devise (4.8.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.4.4)
erubi (1.10.0)
execjs (2.8.1)
Expand All @@ -88,6 +97,14 @@ GEM
concurrent-ruby (~> 1.0)
jbuilder (2.11.2)
activesupport (>= 5.0.0)
less (2.6.0)
commonjs (~> 0.2.7)
less-rails (4.0.0)
actionpack (>= 4)
less (~> 2.6.0)
sprockets (>= 2)
libv8 (3.16.14.19)
libv8 (3.16.14.19-x86_64-darwin-18)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -99,15 +116,19 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.1)
method_source (1.0.0)
metro-ui-rails (0.15.8.15)
less-rails (> 2.2.3)
mini_mime (1.1.1)
mini_portile2 (2.6.1)
minitest (5.14.4)
msgpack (1.4.2)
nio4r (2.5.8)
nokogiri (1.12.4)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-darwin)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -149,7 +170,11 @@ GEM
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
ref (2.0.0)
regexp_parser (2.1.1)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
Expand Down Expand Up @@ -206,13 +231,19 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thor (1.1.0)
tilt (2.0.10)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.1.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.1.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -231,11 +262,14 @@ PLATFORMS

DEPENDENCIES
bcrypt (~> 3.1.7)
bootsnap
byebug
capybara (~> 2.13)
date
devise
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
metro-ui-rails
pg
puma (~> 3.12.6)
rails (~> 6.1)
Expand All @@ -244,6 +278,8 @@ DEPENDENCIES
rubocop-rails
sass-rails (~> 6.0)
selenium-webdriver
sqlite3 (~> 1.3, >= 1.3.11)
therubyracer
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
2 changes: 2 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PostsController < ApplicationController
end
2 changes: 2 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class SessionsController < ApplicationController
end
25 changes: 25 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class UsersController < ApplicationController

def index

end

def create
user = User.new(user_params)
if user.save
session[:user_id] = user.id
redirect_to '/posts#index'
else
flash[:register_errors] = user.errors.full_messages
redirect_to '/'
end

end


private

def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end
2 changes: 2 additions & 0 deletions app/helpers/posts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PostsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SessionsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ApplicationRecord
has_secure_password
end
8 changes: 1 addition & 7 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>InstagramChallenge</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<title>Instagram Challenge</title>
</head>

<body>
Expand Down
1 change: 1 addition & 0 deletions app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
posts index
40 changes: 40 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Login and registration</title>
</head>

<body>
<%
=begin%>
<h1> Login </h1>
<form action ="/sessions" method="POST">
<input type="hidden" name="authenticity_token" value="<%=form_authenticity_token%>">
<input type="email" name="login[email]" placeholder="email">
<input type="password" name="login[password]" placeholder="password">
<input type="submit" name="submit" class="submit">
</form>
<%
=end%>
<h1> Registration </h1>
<form action ="/users" method="POST">
<input type="hidden" name="authenticity_token" value="<%=form_authenticity_token%>">
<input type="name" name="user[name]" placeholder="name">
<input type="email" name="user[email]" placeholder="email">
<input type="password" name="user[password]" placeholder="password">
<input type="password" name="user[password_confirmation]" placeholder="confirm your password">
<input type="submit" name="submit" class="submit">



<%
=begin%>
<%= yield %>
<%
=end%>

</body>
</html>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

resources :users, :sessions, :posts
root 'users#index'
end
11 changes: 11 additions & 0 deletions db/migrate/20210919161742_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest

t.timestamps
end
end
end
23 changes: 23 additions & 0 deletions db/schema.rb

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

15 changes: 15 additions & 0 deletions spec/helpers/posts_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the PostsHelper. For example:
#
# describe PostsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe PostsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
15 changes: 15 additions & 0 deletions spec/helpers/sessions_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the SessionsHelper. For example:
#
# describe SessionsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe SessionsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
15 changes: 15 additions & 0 deletions spec/helpers/users_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the UsersHelper. For example:
#
# describe UsersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe UsersHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe User, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/requests/posts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe "Posts", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end
7 changes: 7 additions & 0 deletions spec/requests/sessions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe "Sessions", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end
7 changes: 7 additions & 0 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe "Users", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end

0 comments on commit 2e625af

Please sign in to comment.