Created
June 9, 2009 16:29
-
-
Save antunderwood/126616 to your computer and use it in GitHub Desktop.
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
<%= form.error_messages %> | |
<div id="user_form"> | |
<div class="text_field"> | |
<%= form.label :email %> | |
<%= form.text_field :email %> | |
</div> | |
<div class="password_field"> | |
<%= form.label :password %> | |
<%= form.password_field :password %> | |
</div> | |
<div class="password_field"> | |
<%= form.label :password_confirmation, "Verify password" %> | |
<%= form.password_field :password_confirmation %> | |
</div> | |
<% if signed_in_as_admin? %> | |
<div class="select_field"> | |
<%= form.select :role, Roleify::Role::ROLES %> | |
<%= form.label :role, "Role" %> | |
</div> | |
<% 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
# Filters added to this controller apply to all controllers in the application. | |
# Likewise, all the methods added will be available for all controllers. | |
class ApplicationController < ActionController::Base | |
include Clearance::Authentication | |
helper :all # include all helpers, all the time | |
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |
# Scrub sensitive parameters from your log | |
filter_parameter_logging :password | |
helper_method :signed_in_as_admin? | |
def signed_in_as_admin? | |
signed_in? && current_user.admin? | |
end | |
def users_only | |
deny_access("Please Login or Create an Account to Access that Feature.") unless signed_in? | |
end | |
def admin_only | |
deny_access("Please Login as an administrator to Access that Feature.") unless signed_in_as_admin? | |
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
<h2>Edit User</h2> | |
<% form_for @user do |form| %> | |
<%= render :partial => '/users/form', :object => form %> | |
<%= form.submit 'Update user details', :disable_with => 'Please wait...' %> | |
<% 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
<table> | |
<tr> | |
<th>Email</th> | |
<th>Confirmed Email?</th> | |
<th>Role</th> | |
<tr> | |
<% @users.each do |user| %> | |
<tr> | |
<td><%= link_to user.email, user_path(user) %></td> | |
<td><%= user.email_confirmed %></td> | |
<td><%= user.role %></td> | |
</tr> | |
<% end %> | |
</table> |
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
<h3><%= mail_to @user.email if signed_in? %></h3> | |
<% if signed_in_as_admin? %> | |
<div id="control_block"> | |
<%= link_to "Edit", edit_user_path(@user) %> | |
<%= link_to "Users", users_path %> | |
</div> | |
<% 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
class User < ActiveRecord::Base | |
include Roleify::RoleifyableModel | |
include Clearance::User | |
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
class UsersController < Clearance::UsersController | |
before_filter :admin_only, :only => [ :index, :show ] | |
before_filter :users_only, :only => [ :edit, :update ] | |
def index | |
@users = User.find :all | |
end | |
def show | |
@user = User.find(params[:id]) | |
end | |
def edit | |
if signed_in_as_admin? | |
@user = User.find(params[:id]) | |
else | |
@user = current_user | |
end | |
end | |
def update | |
@user = User.find(params[:id]) | |
respond_to do |format| | |
if @user.update_attributes(params[:user]) | |
flash[:notice] = 'User Record was successfully updated.' | |
format.html { redirect_to(user_url(@user)) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @user.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment