Complete Lesson 30

main
Simon Quigley 1 year ago
parent 22cf0819ac
commit cd2f24f7ca

@ -3,7 +3,14 @@ class SessionsController < ApplicationController
end
def create
fail
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to user, notice: "Welcome back, #{user.name}!"
else
flash.now[:alert] = "Invalid email/password combination!"
render :new, status: :unprocessable_entity
end
end
def destroy

@ -1,12 +1,25 @@
<header>
<div class="alert alert-primary" role="alert">
<h1>The only movies that actually matter</h1>
<%= link_to image_tag("logo.png"), root_path %>
</div>
<ul class="left">
<li><%= link_to "All Movies", movies_path, class: "btn" %></li>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-primary">
<a class="navbar-brand" href="<%= root_path %>">
<%= image_tag("logo.png") %> The only movies that actually matter
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<%= link_to "All Movies", movies_path, class: "nav-link" %>
</li>
</ul>
<ul class="right">
<li><%= link_to "Sign Up", signup_path, class: "button btn" %></li>
<ul class="navbar-nav">
<li class="nav-item">
<%= link_to "Sign In", new_session_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Sign Up", signup_path, class: "nav-link" %>
</li>
</ul>
</header>
</div>
</nav>
</header>

@ -0,0 +1,10 @@
<h1>Sign In</h1>
<%= form_with(url: session_path) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, autofocus: true %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit "Sign In" %>
<% end %>

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resource :session, only: [:new, :create, :destroy]
resources :users
resources :reviews
root "movies#index"

Loading…
Cancel
Save