user and session generated
This commit is contained in:
parent
0cec39413f
commit
53819e6839
18 changed files with 111 additions and 0 deletions
3
app/assets/stylesheets/sessions.scss
Normal file
3
app/assets/stylesheets/sessions.scss
Normal file
|
@ -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
app/assets/stylesheets/users.scss
Normal file
3
app/assets/stylesheets/users.scss
Normal file
|
@ -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/
|
10
app/controllers/sessions_controller.rb
Normal file
10
app/controllers/sessions_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class SessionsController < ApplicationController
|
||||||
|
def new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
end
|
||||||
|
|
||||||
|
def welcome
|
||||||
|
end
|
||||||
|
end
|
10
app/controllers/users_controller.rb
Normal file
10
app/controllers/users_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class UsersController < ApplicationController
|
||||||
|
def new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@user = User.create(params.require(:user).permit(:username, :password))
|
||||||
|
session[:user_id] = @user.id
|
||||||
|
redirect_to '/welcome'
|
||||||
|
end
|
||||||
|
end
|
2
app/helpers/sessions_helper.rb
Normal file
2
app/helpers/sessions_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module SessionsHelper
|
||||||
|
end
|
2
app/helpers/users_helper.rb
Normal file
2
app/helpers/users_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module UsersHelper
|
||||||
|
end
|
3
app/models/user.rb
Normal file
3
app/models/user.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class User < ApplicationRecord
|
||||||
|
has_secure_password
|
||||||
|
end
|
2
app/views/sessions/create.html.erb
Normal file
2
app/views/sessions/create.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Sessions#create</h1>
|
||||||
|
<p>Find me in app/views/sessions/create.html.erb</p>
|
2
app/views/sessions/new.html.erb
Normal file
2
app/views/sessions/new.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Sessions#new</h1>
|
||||||
|
<p>Find me in app/views/sessions/new.html.erb</p>
|
3
app/views/sessions/welcome.html.erb
Normal file
3
app/views/sessions/welcome.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<h1>Welcome</h1>
|
||||||
|
<%= button_to "Login", '/login', method: :get%>
|
||||||
|
<%= button_to "Sign Up", '/users/new', method: :get%>
|
2
app/views/users/create.html.erb
Normal file
2
app/views/users/create.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Users#create</h1>
|
||||||
|
<p>Find me in app/views/users/create.html.erb</p>
|
8
app/views/users/new.html.erb
Normal file
8
app/views/users/new.html.erb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<h1>Sign Up</h1>
|
||||||
|
<%= form_for @user do |f|%>
|
||||||
|
<%= f.label :username%><br>
|
||||||
|
<%= f.text_field :username%><br>
|
||||||
|
<%= f.label :password%><br>
|
||||||
|
<%= f.password_field :password%><br>
|
||||||
|
<%= f.submit %>
|
||||||
|
<%end%>
|
|
@ -1,3 +1,7 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
resources :users, only: [:new, :create]
|
||||||
|
get 'login', to: 'sessions#new'
|
||||||
|
post 'login', to: 'sessions#create'
|
||||||
|
get 'welcome', to: 'sessions#welcome'
|
||||||
resources :books
|
resources :books
|
||||||
end
|
end
|
||||||
|
|
10
db/migrate/20210320130542_create_users.rb
Normal file
10
db/migrate/20210320130542_create_users.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class CreateUsers < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :username
|
||||||
|
t.string :password_digest
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
18
test/controllers/sessions_controller_test.rb
Normal file
18
test/controllers/sessions_controller_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class SessionsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test "should get new" do
|
||||||
|
get sessions_new_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get create" do
|
||||||
|
get sessions_create_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get welcome" do
|
||||||
|
get sessions_welcome_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
13
test/controllers/users_controller_test.rb
Normal file
13
test/controllers/users_controller_test.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test "should get new" do
|
||||||
|
get users_new_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get create" do
|
||||||
|
get users_create_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
9
test/fixtures/users.yml
vendored
Normal file
9
test/fixtures/users.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
username: MyString
|
||||||
|
password_digest: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
username: MyString
|
||||||
|
password_digest: MyString
|
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class UserTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue