Last active
December 12, 2015 08:39
-
-
Save fidel/4745493 to your computer and use it in GitHub Desktop.
session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/sessions/new.html.erb --> | |
<div class="depot_form"> | |
<% if flash[:alert] %> | |
<p id="notice"><%= flash[:alert] %></p> | |
<% end %> | |
<%= form_tag do %> | |
<fieldset> | |
<legend>Please Log In</legend> | |
<div> | |
<%= label_tag :name, 'Name:' %> | |
<%= text_field_tag :name, params[:name] %> | |
</div> | |
<div> | |
<%= label_tag :password, 'Password:' %> | |
<%= password_field_tag :password, params[:password] %> | |
</div> | |
<div> | |
<%= submit_tag "Login" %> | |
</div> | |
</fieldset> | |
<% end %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
user = User.find_by_name(params[:name]) | |
if user and user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to admin_url | |
else | |
redirect_to login_url, | |
alert: "Invalid user/password combination" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment