Skip to content

Commit

Permalink
users controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshuma committed Jan 5, 2010
1 parent 44d8893 commit f20e694
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/user_sessions_controller.rb
Expand Up @@ -8,7 +8,7 @@ def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = 'Login successful.'
redirect_back_or_default root_path
continue_or_redirect_to root_path
else
flash[:error] = 'Incorrect login or password.'
redirect_to login_path
Expand All @@ -18,7 +18,7 @@ def create
def destroy
current_user_session.destroy
flash[:notice] = 'Logout successful.'
redirect_back_or_default root_path
continue_or_redirect_to root_path
end

end
36 changes: 36 additions & 0 deletions app/controllers/users_controller.rb
@@ -0,0 +1,36 @@
class UsersController < ApplicationController
before_filter :login_required, :only => [ :show, :edit, :update ]

def new
@user = User.new
end

def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = 'Account created!'
continue_or_redirect_to root_path
else
render :action => :new
end
end

def show
@user = current_user
end

def edit
@user = current_user
end

def update
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = 'Account updated!'
redirect_to root_path
else
render :action => :edit
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
module UsersHelper
end
5 changes: 2 additions & 3 deletions app/views/shared/_user_navigation.html.erb
Expand Up @@ -7,9 +7,8 @@
<%= link_to('Logout', logout_path, :class => 'logout') %>
</li>
<% else %>
<li>
<%= link_to('Login', login_path, :class => 'login') %>
</li>
<li><%= link_to('Login', login_path, :class => 'login') %></li>
<li><%= link_to('Sign Up', signup_path) %></li>
<% end %>
</ul>
</div><%# end #user-navigation %>
2 changes: 1 addition & 1 deletion app/views/user_sessions/new.html.erb
Expand Up @@ -20,7 +20,7 @@
<%= f.label :password, 'Password', :class => 'label right' %>
</div>
<div class="right">
<%= f.text_field :password, :class => 'text_field' %>
<%= f.password_field :password, :class => 'text_field' %>
</div>
</div>

Expand Down
25 changes: 25 additions & 0 deletions app/views/users/_form.html.erb
@@ -0,0 +1,25 @@
<%= f.error_messages %>

<div class="group">
<%= f.label :login, 'Login', :class => 'label' %>
<%= f.text_field :login, :class => 'text_field' %>
<span class="description">* Required</span>
</div>

<div class="group">
<%= f.label :email, 'Email', :class => 'label' %>
<%= f.text_field :email, :class => 'text_field' %>
<span class="description">Any valid email address.</span>
</div>

<div class="group">
<%= f.label :password, 'Password', :class => 'label' %>
<%= f.password_field :password, :class => 'text_field' %>
<span class="description">* Required</span>
</div>

<div class="group">
<%= f.label :password_confirmation, 'Password Confirmation', :class => 'label' %>
<%= f.password_field :password_confirmation, :class => 'text_field' %>
<span class="description">One more time.</span>
</div>
Empty file.
25 changes: 25 additions & 0 deletions app/views/users/edit.html.erb
@@ -0,0 +1,25 @@
<% content_for :sidebar, render(:partial => 'sidebar') -%>

<div class="block">
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><%= link_to "#{t("web-app-theme.list", :default => "List")}", users_path %></li>
<li><%= link_to "#{t("web-app-theme.new", :default => "New")}", new_user_path %></li>
<li class="active"><%= link_to "#{t("web-app-theme.edit", :default => "Edit")}", edit_user_path %></li>
</ul>
</div>
<div class="content">
<h2 class="title"><%= t("web-app-theme.edit", :default => "Edit") %> User</h2>
<div class="inner">
<% form_for @user, :url => user_path(@user), :html => { :class => :form } do |f| -%>
<%= render :partial => "form", :locals => {:f => f} %>
<div class="group navform wat-cf">
<button class="button" type="submit">
<%= image_tag("web-app-theme/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Save") %>
</button>
<%= link_to "#{image_tag("web-app-theme/cross.png", :alt => "#{t("web-app-theme.cancel", :default => "Cancel")}")} #{t("web-app-theme.cancel", :default => "Cancel")}", users_path, :class => "button" %>
</div>
<% end -%>
</div>
</div>
</div>
48 changes: 48 additions & 0 deletions app/views/users/index.html.erb
@@ -0,0 +1,48 @@
<% content_for :sidebar, render(:partial => 'sidebar') -%>

<div class="block">
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first active"><%= link_to "#{t("web-app-theme.list", :default => "List")}", users_path %></li>
<li><%= link_to "#{t("web-app-theme.new", :default => "New")}", new_user_path %></li>
</ul>
</div>
<div class="content">
<h2 class="title"><%= t("web-app-theme.all", :default => "All") %> Users</h2>
<div class="inner">
<table class="table">
<tr>
<th class="first">ID</th>
<th>
<%= t("activerecord.attributes.user.login", :default => t("activerecord.labels.login", :default => "Login")) %>
</th>
<th><%= t("web-app-theme.created_at", :default => "Created at") %></th>
<th class="last">&nbsp;</th>
</tr>
<% @users.each do |user| -%>
<tr class="<%= cycle("odd", "even") %>">
<td>
<%= user.id %>
</td>
<td>
<%= link_to user.login, user_path(user) %>
</td>
<td>
<%= user.created_at %>
</td>
<td class="last">
<%= link_to "#{t("web-app-theme.show", :default => "Show")}", user_path(user) %> |
<%= link_to "#{t("web-app-theme.edit", :default => "Edit")}", edit_user_path(user) %> |
<%= link_to "#{t("web-app-theme.delete", :default => "Delete")}", user_path(user), :method => :delete, :confirm => "#{t("web-app-theme.confirm", :default => "Are you sure?")}" %>
</td>
</tr>
<% end -%>
</table>
<div class="actions-bar wat-cf">
<div class="actions">
</div>

</div>
</div>
</div>
</div>
20 changes: 20 additions & 0 deletions app/views/users/new.html.erb
@@ -0,0 +1,20 @@
<% content_for :sidebar, render(:partial => 'sidebar') -%>

<div id="box">
<div class="block" id="block-signup">
<h2>Sign Up</h2>
<div class="content">
<div>&nbsp;</div>
<% form_for :user, :url => users_path, :html => { :class => 'form' } do |f| %>
<%= render :partial => "form", :locals => {:f => f} %>

<div class="group wat-cf navform">
<button class="button" type="submit">
<%= image_tag('web-app-theme/tick.png', :alt => 'Sign Up') %>
Sign Up
</button>
</div>
<% end %>
</div>
</div>
</div>
57 changes: 57 additions & 0 deletions app/views/users/show.html.erb
@@ -0,0 +1,57 @@
<div class="block">
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><%= link_to "#{t("web-app-theme.list", :default => "List")}", users_path %></li>
<li><%= link_to "#{t("web-app-theme.new", :default => "New")}", new_user_path %></li>
<li class="active"><%= link_to "#{t("web-app-theme.show", :default => "Show")}", user_path %></li>
</ul>
</div>
<div class="content">
<div class="inner">

<p>
<b><%= t("activerecord.attributes.user.login", :default => t("activerecord.labels.login", :default => "Login")) %>:</b>
<%= @user.login %>
</p>

<p>
<b><%= t("activerecord.attributes.user.email", :default => t("activerecord.labels.email", :default => "Email")) %>:</b>
<%= @user.email %>
</p>

<p>
<b><%= t("activerecord.attributes.user.crypted_password", :default => t("activerecord.labels.crypted_password", :default => "Crypted password")) %>:</b>
<%= @user.crypted_password %>
</p>

<p>
<b><%= t("activerecord.attributes.user.password_salt", :default => t("activerecord.labels.password_salt", :default => "Password salt")) %>:</b>
<%= @user.password_salt %>
</p>

<p>
<b><%= t("activerecord.attributes.user.persistence_token", :default => t("activerecord.labels.persistence_token", :default => "Persistence token")) %>:</b>
<%= @user.persistence_token %>
</p>

<p>
<b><%= t("activerecord.attributes.user.single_access_token", :default => t("activerecord.labels.single_access_token", :default => "Single access token")) %>:</b>
<%= @user.single_access_token %>
</p>

<p>
<b><%= t("activerecord.attributes.user.perishable_token", :default => t("activerecord.labels.perishable_token", :default => "Perishable token")) %>:</b>
<%= @user.perishable_token %>
</p>

<p>
<b><%= t("activerecord.attributes.user.admin", :default => t("activerecord.labels.admin", :default => "Admin")) %>:</b>
<%= @user.admin %>
</p>
<%= link_to "#{image_tag("web-app-theme/application_edit.png", :alt => "#{t("web-app-theme.edit", :default=> "Edit")}")} #{t("web-app-theme.edit", :default=> "Edit")}", edit_user_path(@user), :class => "button" %>
<%= link_to "#{image_tag("web-app-theme/cross.png", :alt => "#{t("web-app-theme.delete", :default=> "Delete")}")} #{t("web-app-theme.delete", :default => "Delete")}", user_path(@user), :method => "delete", :class => "button", :confirm => "#{t("web-app-theme.confirm", :default => "Are you sure?")}" %>
</div>
</div>
</div>

<% content_for :sidebar, render(:partial => 'sidebar') -%>
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,4 +1,5 @@
ActionController::Routing::Routes.draw do |map|
map.signup '/signup', :controller => 'users', :action => 'new'
map.with_options :controller => 'user_sessions' do |auth|
auth.login '/login', :action => 'new'
auth.logout '/logout', :action => 'destroy'
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -41,7 +41,7 @@

create_table "users", :force => true do |t|
t.string "login", :null => false
t.string "email", :null => false
t.string "email"
t.string "crypted_password", :null => false
t.string "password_salt", :null => false
t.string "persistence_token", :null => false
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/users_controller_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'

describe UsersController do

#Delete this example and add some real ones
it "should use UsersController" do
controller.should be_an_instance_of(UsersController)
end

end
11 changes: 11 additions & 0 deletions spec/helpers/users_helper_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe UsersHelper do

#Delete this example and add some real ones or delete this file
it "should be included in the object returned by #helper" do
included_modules = (class << helper; self; end).send :included_modules
included_modules.should include(UsersHelper)
end

end

0 comments on commit f20e694

Please sign in to comment.