-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devise user and role management foundation
- Loading branch information
Josh Gum
committed
Apr 13, 2016
1 parent
3468bad
commit 87d09a5
Showing
26 changed files
with
686 additions
and
83 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class HomeController < ApplicationController | ||
skip_before_filter :check_auth | ||
skip_before_filter :authenticate_user! | ||
|
||
def index | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
class RegistrationsController < Devise::RegistrationsController | ||
|
||
def create | ||
build_resource | ||
resource.role = "user" | ||
|
||
if resource.save | ||
if resource.active? | ||
set_flash_message :notice, :signed_up | ||
sign_in_and_redirect(resource_name, resource) | ||
else | ||
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s | ||
expire_session_data_after_sign_in! | ||
redirect_to after_inactive_sign_up_path_for(resource) | ||
end | ||
else | ||
clean_up_passwords(resource) | ||
render_with_scope :new | ||
end | ||
end | ||
|
||
def token | ||
#@user = User.where(:id => params[:user_id]).first | ||
#@user.reset_authentication_token! | ||
redirect_to edit_user_registration_path(@user) | ||
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,45 @@ | ||
class UserController < ApplicationController | ||
load_and_authorize_resource | ||
|
||
def index | ||
@users = User.excludes(:id => current_user.id) | ||
end | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(params[:user]) | ||
if @user.save | ||
flash[:notice] = "Successfully created User." | ||
redirect_to root_path | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def update | ||
@user = User.find(params[:id]) | ||
params[:user].delete(:password) if params[:user][:password].blank? | ||
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? | ||
if @user.update_attributes(params[:user]) | ||
flash[:notice] = "Successfully updated User." | ||
redirect_to root_path | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@user = User.find(params[:id]) | ||
if @user.destroy | ||
flash[:notice] = "Successfully deleted User." | ||
redirect_to root_path | ||
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,18 @@ | ||
class Ability | ||
include CanCan::Ability | ||
|
||
def initialize(user) | ||
# Define abilities for the passed in user here. For example: | ||
# | ||
user ||= User.new # guest user (not logged in) | ||
if user.is_admin? | ||
can :administrate, :all | ||
elsif user.is_reviewer? | ||
can :review, :all | ||
elsif user.is_submitter? | ||
can :submit, :all | ||
else | ||
can :read, :all | ||
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,22 @@ | ||
class User < ActiveRecord::Base | ||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :trackable, :validatable | ||
|
||
ROLES = { | ||
:admin => 'admin', | ||
:reviewer => 'reviewer', | ||
:submitter => 'submitter' | ||
} | ||
|
||
def is_admin? | ||
roles.include?(ROLES[:admin]) | ||
end | ||
def is_reviewer? | ||
roles.include?(ROLES[:reviewer]) | ||
end | ||
def is_sumitter? | ||
roles.include?(ROLES[:submitter]) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
<h2>Edit <%= resource_name.to_s.humanize %></h2> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %> | ||
<%= devise_error_messages! %> | ||
|
||
<p><%= f.label :name %><br /> | ||
<%= f.text_field :name %></p> | ||
|
||
<p><%= f.label :email %><br /> | ||
<%= f.text_field :email %></p> | ||
|
||
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br /> | ||
<%= f.password_field :password %></p> | ||
|
||
<p><%= f.label :password_confirmation %><br /> | ||
<%= f.password_field :password_confirmation %></p> | ||
|
||
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br /> | ||
<%= f.password_field :current_password %></p> | ||
|
||
<p><%= f.label :token_authentication_key %><br /> | ||
<%= resource.authentication_token.blank? ? "Token Empty" : resource.authentication_token %></p> | ||
|
||
<p><%= link_to "Generate Token", token_authentications_path(:user_id => resource.id), :method => :post, :confirm => "Are you sure?" %> | ||
<%= link_to "Delete Token", token_authentication_path(resource), :method => :delete, :confirm => "Are you sure?" %></p> | ||
|
||
<% if resource.authentication_token %> | ||
<p>You can use this url to login<br /> | ||
<%= link_to "http://localhost:3000#{root_path(:auth_token => resource.authentication_token)}", root_path(:auth_token => resource.authentication_token) %></p> | ||
<% end %> | ||
<% if can? :manage, @users %> | ||
<p><%= f.label :role %>: <%= f.collection_select :role, User::ROLES, :to_s, :humanize, {:include_blank => true} %></p> | ||
<% end %> | ||
|
||
<p><%= f.submit "Update" %></p> | ||
<% end %> | ||
|
||
<h3>Cancel my account</h3> | ||
|
||
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p> | ||
|
||
<%= link_to "Back", :back %> | ||
|
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 @@ | ||
<h2>Sign up</h2> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> | ||
<%= devise_error_messages! %> | ||
|
||
<p><%= f.label :name %><br /> | ||
<%= f.text_field :name %></p> | ||
|
||
|
||
<p><%= f.label :email %><br /> | ||
<%= f.text_field :email %></p> | ||
|
||
<p><%= f.label :password %><br /> | ||
<%= f.password_field :password %></p> | ||
|
||
<p><%= f.label :password_confirmation %><br /> | ||
<%= f.password_field :password_confirmation %></p> | ||
|
||
<p><%= f.submit "Sign up" %></p> | ||
<% end %> | ||
<%= render :partial => "devise/shared/links" %> |
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 |
---|---|---|
@@ -1,23 +1,25 @@ | ||
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<%= link_to "opaquenamespace.org", '/', class: "navbar-brand"%> | ||
</div> | ||
<div id="navbar" class="collapse navbar-collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li><%= link_to "Home", '/' %></li> | ||
<li><%= link_to "Vocabularies", vocabularies_path %></li> | ||
|
||
<li><%= link_to "Predicates", predicates_path %></li> | ||
|
||
<%- if session[:authorized] == true %> | ||
<li><%= link_to "Import External RDF", import_rdf_path %></li> | ||
<li><%= link_to "Logout", '/login/auth' %></li> | ||
<%- else -%> | ||
<li><%= link_to "Login", '/login/auth' %></li> | ||
<%- end -%> | ||
</ul> | ||
</div><!--/.nav-collapse --> | ||
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<%= link_to "opaquenamespace.org", '/', class: "navbar-brand"%> | ||
</div> | ||
</nav> | ||
<div id="navbar" class="collapse navbar-collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li><%= link_to "Home", '/' %></li> | ||
<li><%= link_to "Vocabularies", vocabularies_path %></li> | ||
<li><%= link_to "Predicates", predicates_path %></li> | ||
|
||
<%- if session[:authorized] == true %> | ||
<% if can? :administrate %> | ||
<li><%= link_to "Users", users_path %></li> | ||
<% end %> | ||
<li><%= link_to "Import External RDF", import_rdf_path %></li> | ||
<li><%= link_to "Logout", logout_path %></li> | ||
<%- else -%> | ||
<li><%= link_to "Login", login_path %></li> | ||
<%- end -%> | ||
</ul> | ||
</div><!--/.nav-collapse --> | ||
</div> | ||
</nav> | ||
|
Oops, something went wrong.