Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UserSessions scaffold with AuthLogic model
- Loading branch information
Showing
14 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class UserSessionsController < ApplicationController | ||
# GET /user_sessions/new | ||
# GET /user_sessions/new.xml | ||
def new | ||
@user_session = UserSession.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @user_session } | ||
end | ||
end | ||
|
||
# POST /user_sessions | ||
# POST /user_sessions.xml | ||
def create | ||
@user_session = UserSession.new(params[:user_session]) | ||
|
||
if @user_session.save | ||
flash[:notice] = "Successfully logged in." | ||
redirect_to root_url | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
# DELETE /user_sessions/1 | ||
# DELETE /user_sessions/1.xml | ||
def destroy | ||
@user_session = UserSession.find # no arguments -> current session | ||
@user_session.destroy | ||
flash[:notice] = "Successfully logged out." | ||
redirect_to root_url | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UserSessionsHelper | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
<title>UserSessions: <%= controller.action_name %></title> | ||
<%= stylesheet_link_tag 'scaffold' %> | ||
</head> | ||
<body> | ||
|
||
<p style="color: green"><%= flash[:notice] %></p> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Editing user_session</h1> | ||
|
||
<% form_for(@user_session) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :username %><br /> | ||
<%= f.text_field :username %> | ||
</p> | ||
<p> | ||
<%= f.label :password %><br /> | ||
<%= f.text_field :password %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Update' %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Show', @user_session %> | | ||
<%= link_to 'Back', user_sessions_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1>Listing user_sessions</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Username</th> | ||
<th>Password</th> | ||
</tr> | ||
|
||
<% @user_sessions.each do |user_session| %> | ||
<tr> | ||
<td><%=h user_session.username %></td> | ||
<td><%=h user_session.password %></td> | ||
<td><%= link_to 'Show', user_session %></td> | ||
<td><%= link_to 'Edit', edit_user_session_path(user_session) %></td> | ||
<td><%= link_to 'Destroy', user_session, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New user_session', new_user_session_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1>New user_session</h1> | ||
|
||
<% form_for(@user_session) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :username %><br /> | ||
<%= f.text_field :username %> | ||
</p> | ||
<p> | ||
<%= f.label :password %><br /> | ||
<%= f.text_field :password %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Create' %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Back', user_sessions_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<p> | ||
<b>Username:</b> | ||
<%=h @user_session.username %> | ||
</p> | ||
|
||
<p> | ||
<b>Password:</b> | ||
<%=h @user_session.password %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_user_session_path(@user_session) %> | | ||
<%= link_to 'Back', user_sessions_path %> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateUserSessions < ActiveRecord::Migration | ||
def self.up | ||
create_table :user_sessions do |t| | ||
t.string :username | ||
t.string :password | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :user_sessions | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
username: MyString | ||
password: MyString | ||
|
||
two: | ||
username: MyString | ||
password: MyString |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'test_helper' | ||
|
||
class UserSessionsControllerTest < ActionController::TestCase | ||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:user_sessions) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create user_session" do | ||
assert_difference('UserSession.count') do | ||
post :create, :user_session => { } | ||
end | ||
|
||
assert_redirected_to user_session_path(assigns(:user_session)) | ||
end | ||
|
||
test "should show user_session" do | ||
get :show, :id => user_sessions(:one).to_param | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, :id => user_sessions(:one).to_param | ||
assert_response :success | ||
end | ||
|
||
test "should update user_session" do | ||
put :update, :id => user_sessions(:one).to_param, :user_session => { } | ||
assert_redirected_to user_session_path(assigns(:user_session)) | ||
end | ||
|
||
test "should destroy user_session" do | ||
assert_difference('UserSession.count', -1) do | ||
delete :destroy, :id => user_sessions(:one).to_param | ||
end | ||
|
||
assert_redirected_to user_sessions_path | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class UserSessionsHelperTest < ActionView::TestCase | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test_helper' | ||
|
||
class UserSessionTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
end | ||
end |