forked from project-rhex/patient-data-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhanced user model; added user UI support
- Loading branch information
Ganley
committed
Mar 12, 2012
1 parent
600f708
commit c2e2277
Showing
15 changed files
with
474 additions
and
29 deletions.
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
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,3 @@ | ||
class StaticController < ApplicationController | ||
|
||
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,112 @@ | ||
class UsersController < ApplicationController | ||
# GET /users | ||
# GET /users.json | ||
def index | ||
|
||
@users = User.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @users } | ||
end | ||
end | ||
|
||
# GET /users/1 | ||
# GET /users/1.json | ||
def show | ||
@user = User.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @user } | ||
end | ||
end | ||
|
||
# GET /users/new | ||
# GET /users/new.json | ||
def new | ||
@user = User.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @user } | ||
end | ||
end | ||
|
||
# GET /users/1/edit | ||
def edit | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
# POST /users | ||
# POST /users.json | ||
def create | ||
@user = User.new(params[:user]) | ||
|
||
respond_to do |format| | ||
if @user.save | ||
format.html { redirect_to @user, notice: 'User was successfully created.' } | ||
format.json { render json: @user, status: :created, location: @user } | ||
else | ||
##puts @user.errors.inspect | ||
format.html { render action: "new" } | ||
format.json { render json: @user.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /users/1 | ||
# PUT /users/1.json | ||
def update | ||
@user = User.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @user.update_attributes(params[:user]) | ||
format.html { redirect_to @user, notice: 'User was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @user.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /users/1 | ||
# DELETE /users/1.json | ||
def destroy | ||
@user = User.find(params[:id]) | ||
@user.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to users_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
|
||
def make_admin | ||
@user = User.find( params[:id] ) || current_user | ||
@user.admin = :true | ||
@user.save | ||
|
||
respond_to do |wants| | ||
flash[:notice] = 'User was successfully updated.' | ||
wants.html { redirect_to :action => "edit", :id => @user.id } | ||
end | ||
end | ||
|
||
def remove_admin | ||
@user = User.find( params[:id] ) || current_user | ||
@user.admin = :false | ||
@user.save | ||
#rent_user, "ADMIN", "admin_privs_remove", "" | ||
|
||
respond_to do |wants| | ||
flash[:notice] = 'User was successfully updated.' | ||
wants.html { redirect_to :action => "edit", :id => @user.id } | ||
end | ||
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,8 @@ | ||
module UsersHelper | ||
|
||
def isAdmin? | ||
return true if current_user.admin == :true | ||
false | ||
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,25 @@ | ||
<div class="breadcrumb"> | ||
<%= link_to "Home", root_path( :action => "index" ) %> | | ||
Settings | ||
</div> | ||
|
||
<h1>Settings</h1> | ||
|
||
<table/> | ||
<tr> | ||
<td><%= link_to 'Notifications and Alerts', :controller => :notify_configs, :action => :index %></td> | ||
</tr> | ||
|
||
<tr> | ||
<td> <%= link_to 'My User Info', current_user %> </td> | ||
</tr> | ||
|
||
<% if isAdmin? %> | ||
<tr> | ||
<td><%= link_to 'All Users', :controller => :users, :action => :index %></td> | ||
</tr> | ||
<% end %> | ||
|
||
</table> | ||
|
||
<br /> |
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,73 @@ | ||
|
||
|
||
<%= form_for(@user) do |f| %> | ||
<% if @user.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> | ||
|
||
<ul> | ||
<% @user.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label "Name" %><br /> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label "Username / email" %><br /> | ||
<%= f.text_field :email %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label "Password" %><br /> | ||
<%= f.text_field :password %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :street %><br /> | ||
<%= f.text_field :street %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :city %><br /> | ||
<%= f.text_field :city %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :state %><br /> | ||
<%= f.text_field :state %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :zip %><br /> | ||
<%= f.text_field :zip %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :country %><br /> | ||
<%= f.text_field :country %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :role %><br /> | ||
<%= f.select :role, User.get_role_values, :prompt => 'Select...' %> | ||
</div> | ||
<% if isAdmin? && current_user != @user %> | ||
<div class="field"> | ||
<%= f.label :admin %><br /> | ||
<%= f.select :admin, User.get_admin_values, :prompt => 'Select...' %> | ||
</div> | ||
<% else %> | ||
<p> | ||
<div class="field"> | ||
<b>Admin:</b> | ||
<%= @user.admin %> | ||
</div> | ||
<% end %> | ||
|
||
<p> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> | ||
|
||
|
||
<p> | ||
|
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,21 @@ | ||
<h1>Editing user</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @user %> | ||
<% if isAdmin? %> | ||
| <%= link_to 'Back', users_path %> | ||
<% end %> | ||
|
||
|
||
<p> | ||
<div class="field"> | ||
<br/> | ||
<% if current_user == @user %> | ||
<% if current_user.admin == :true %> | ||
<a href="/users/<%= @user.id%>/remove_admin">Turn off Admin privs</a> | ||
<% else %> | ||
<a href="/users/<%= @user.id%>/make_admin">Add Admin privs</a> | ||
<% end %> | ||
<% end %> | ||
</div> |
Oops, something went wrong.