Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modified routes, sessions views and controller for loging in

  • Loading branch information...
commit 3319d3c2b45ddc9028b8c49127582b5ccfe34c5a 1 parent 7140233
@florida authored
View
15 app/controllers/sessions_controller.rb
@@ -1,4 +1,19 @@
class SessionsController < ApplicationController
def new
end
+
+ def create
+ user = login(params[:email], params[:password], params[:remember_me])
+ if user
+ redirect_back_or_to root_url, :notice => "Logged in!"
+ end
+ flash.now.alert = "Email or Password was invalid"
+ render :new
+ end
+
+ def destroy
+ logout
+ redirect_to root_url, :notice => "Logged Out!"
+ end
+
end
View
20 app/views/sessions/new.html.erb
@@ -1,2 +1,18 @@
-<h1>Sessions#new</h1>
-<p>Find me in app/views/sessions/new.html.erb</p>
+<%= form_tag sessions_path do %>
+ <section class="field">
+ <% label_tag :email %>
+ <% text_field_tag :email, params [:email] %>
+
+ </section>
+ <section class="field">
+ <%= label_tag :password %>
+ <%= password_field_tag :password %>
+ </section>
+ <section class="field">
+ <%= check_box_tag :remember_me, 1, params[:remember_me]%>
+ <%= label_tag :remember_me %>
+ </section>
+ <section class="actions">
+ <%= submit_tag "Log in" %>
+ </section>
+<% end %>
View
3  app/views/users/new.html.erb
@@ -25,4 +25,5 @@
<section class="actions">
<%= f.submit %>
- </section>
+ </section>
+<% end %>
View
19 config/routes.rb
@@ -1,13 +1,14 @@
Elmorfstore::Application.routes.draw do
- get "sessions/new"
-
- get "users/new"
-
-namespace :admin do
- resources :orders, :products
-end
-
-resources :orders, :products
+ get "logout" => "sessions#destroy", :as => "logout"
+ get "login" => "sessions#new", :as => "login"
+ get "signup" => "users#new", :as => "signup"
+ # root :to => "store#index"
+
+ namespace :admin do
+ resources :orders, :products
+ end
+
+ resources :orders, :products, :users, :sessions
# The priority is based upon order of creation:
# first created -> highest priority.
Please sign in to comment.
Something went wrong with that request. Please try again.