Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Bierbrauer
authored and
Alexander Bierbrauer
committed
May 3, 2016
1 parent
f0364cb
commit 06cf371
Showing
29 changed files
with
300 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.5.1 | ||
0.5.2 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
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 @@ | ||
// Place all the styles related to the System/User controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
class System::UserController < ApplicationController | ||
before_action :filter_needs_admin_role | ||
|
||
def index | ||
@users = User.all | ||
end | ||
|
||
def edit | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(strong_params_user) | ||
|
||
if !@user.save | ||
flash['error'] = @user.errors.full_messages | ||
render action: 'new' | ||
else | ||
redirect_to action: 'edit', id: @user.id | ||
end | ||
end | ||
|
||
def update | ||
@user = User.find(params[:id]) | ||
|
||
Role.all.each do |role| | ||
if params[:role][role.id.to_s].to_i == 1 | ||
@user.add_role(role.name) | ||
else | ||
@user.remove_role(role.name) | ||
end | ||
end | ||
|
||
# ensure that the first user is always admin!!! | ||
if @user.id == 1 | ||
@user.add_role(:admin) | ||
end | ||
|
||
if !params[:user][:password].blank? | ||
@user.password = params[:user][:password] | ||
@user.password_confirmation = params[:user][:password_confirmation] | ||
end | ||
|
||
if !@user.save | ||
flash['error'] = @user.errors.full_messages | ||
render action: 'edit' | ||
else | ||
|
||
redirect_to action: :index | ||
end | ||
end | ||
|
||
def destroy | ||
@user = User.find(params[:id]) | ||
|
||
if @user.id != 1 | ||
@user.destroy | ||
end | ||
redirect_to action: 'index' | ||
end | ||
|
||
private | ||
|
||
def strong_params_user | ||
params.require(:user).permit(:email,:password,:password_confirmation) | ||
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,2 @@ | ||
module System::UserHelper | ||
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,10 @@ | ||
class Role < ActiveRecord::Base | ||
has_and_belongs_to_many :users, :join_table => :users_roles | ||
belongs_to :resource, :polymorphic => true | ||
|
||
validates :resource_type, | ||
:inclusion => { :in => Rolify.resource_types }, | ||
:allow_nil => true | ||
|
||
scopify | ||
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 |
---|---|---|
@@ -1,24 +1 @@ | ||
<%= bootstrap_devise_error_messages! %> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h4><%= t('.sign_up', :default => "Sign up") %></h4> | ||
</div> | ||
<div class="panel-body"> | ||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { role: "form" }) do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :email %> | ||
<%= f.email_field :email, autofocus: true, class: "form-control" %> | ||
</div> | ||
<div class="form-group"> | ||
<%= f.label :password %><br /> | ||
<%= f.password_field :password, class: "form-control" %> | ||
</div> | ||
<div class="form-group"> | ||
<%= f.label :password_confirmation %> | ||
<%= f.password_field :password_confirmation, class: "form-control" %> | ||
</div> | ||
<%= f.submit t('.sign_up', :default => "Sign up"), class: "btn btn-primary" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<%= render "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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%h1 | ||
Edit User | ||
|
||
|
||
= form_for(@user,url: {action: :update, id: @user.id}, :html => { :method => :put }) do |f| | ||
.form-group | ||
= f.label :email | ||
= f.email_field :email, autofocus: true, class: "form-control" | ||
|
||
.form-group | ||
= f.label :password | ||
= f.password_field :password, :autocomplete => "off", class: "form-control" | ||
|
||
.form-group | ||
= f.label :password_confirmation | ||
= f.password_field :password_confirmation, class: "form-control" | ||
|
||
.form-group | ||
Roles: | ||
- Role.all.each do |role| | ||
= check_box("role", role.id, checked: @user.has_role?(role.name)) | ||
= role.name | ||
|
||
= f.submit |
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 | ||
Accounts | ||
|
||
= link_to 'Add User',{action: 'new'},{class: 'btn btn-primary'} | ||
|
||
%table.table.table-bordered | ||
%thead | ||
%tbody | ||
- @users.each do |u| | ||
%tr | ||
%td | ||
= u.id | ||
%td | ||
= u.email | ||
%td | ||
- u.roles.each do |r| | ||
= r.name | ||
%td | ||
= link_to('edit',{action: 'edit', id: u.id},{class: 'btn btn-primary'}) | ||
= link_to('delete',{action: 'destroy', id: u.id},{class: 'btn btn-warning', method: :delete,data: {confirm:'Are you sure?'}}) |
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 @@ | ||
%h1 | ||
New User | ||
|
||
|
||
= form_for(@user,url: {action: :create }, :html => { :method => :post }) do |f| | ||
.form-group | ||
= f.label :email | ||
= f.email_field :email, autofocus: true, class: "form-control" | ||
|
||
.form-group | ||
= f.label :password | ||
= f.password_field :password, :autocomplete => "off", class: "form-control" | ||
|
||
.form-group | ||
= f.label :password_confirmation | ||
= f.password_field :password_confirmation, class: "form-control" | ||
|
||
= f.submit |
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,7 @@ | ||
Rolify.configure do |config| | ||
# By default ORM adapter is ActiveRecord. uncomment to use mongoid | ||
# config.use_mongoid | ||
|
||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false | ||
# config.use_dynamic_shortcuts | ||
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
Oops, something went wrong.