snapuser 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +86 -0
- data/Rakefile +0 -30
- data/app/views/sessions/new.html.erb +2 -2
- data/lib/snapuser/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6071678522da82d7646d3c87d54828f63f68129d
|
4
|
+
data.tar.gz: a55d8d5b1f208372018ced5a9d08fa9ab5d6a3f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0c1e350c3bfd3d02f8bb6c56bfcb997b77e848727d89241284464cdc816fc5cbe86c9d052e75459d7781d6c37a1560c02a2e74a87dbb9b8390da01bc163510
|
7
|
+
data.tar.gz: be262fffc639a34b54e241c8525334b1f9cb0e240263f3072970331131feff104dc86a4337c034808c12c6058dbe6f793a276b6e5205e5a301fe5977f9b1f1c6
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Snapuser
|
2
|
+
|
3
|
+
A rails engine to add a simple authentification and permission system.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'snapuser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
In order to run the engine's migrations:
|
18
|
+
|
19
|
+
$ rake db:migrate
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The gem provides two methods to securize your controllers and your views.
|
24
|
+
|
25
|
+
Use `authorize_level(level)` to prevent access to an action from a certain user level. In this example, only the users with a level 3 or higher can visit these pages.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Admin::EventsController < Admin::BaseController
|
29
|
+
before_action { |c| c.authorize_level(3) }
|
30
|
+
|
31
|
+
def index
|
32
|
+
@events = Event.all
|
33
|
+
end
|
34
|
+
|
35
|
+
def new
|
36
|
+
@event = Event.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def create
|
40
|
+
...
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Use `authorize_level?(level)` to know if a user is authorized compared to a given level.
|
47
|
+
|
48
|
+
```html
|
49
|
+
<%= link_to "Add an event", new_event_path if authorize_level?(3) %>
|
50
|
+
```
|
51
|
+
|
52
|
+
Finally, if you just want that a user is connected, use the first method and pass the lowest level.
|
53
|
+
|
54
|
+
The plugin also provides few methods that can be useful:
|
55
|
+
* `current_user`: return the connected user, or otherwise `nil`
|
56
|
+
* `signed_in?`: check if a user is connected
|
57
|
+
|
58
|
+
The following URL are reserved by the plugin:
|
59
|
+
|
60
|
+
* `/login`, login_path
|
61
|
+
* `/user/edit`, user_edit_path
|
62
|
+
* `/user/update`, user_update_path
|
63
|
+
* `/signout`, signout_path
|
64
|
+
* `/sessions`, sessions_path
|
65
|
+
* resources `/admin/users`, admin_users_path
|
66
|
+
|
67
|
+
## Configuration
|
68
|
+
|
69
|
+
Create an custom initializer to put your configuration.
|
70
|
+
|
71
|
+
You can configure the different permission's levels. Set `Snapuser.levels` with an hash:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# initializers/snapuser.rb
|
75
|
+
|
76
|
+
Snapuser.levels = {"superadmin" => "1", "admin" => "2", "author" => "3", "member" => "4"}
|
77
|
+
```
|
78
|
+
By default, the levels are `{"superadmin" => "1", "admin" => "2"}`.
|
79
|
+
|
80
|
+
Set `Snapuser.superuser_level` to configure from which level the users are allowed to edit the other users. By default, the superuser level is 1.
|
81
|
+
|
82
|
+
Set `Snapuser.can_edit` to configure from which level a user is allowed to edit his information (username and password).
|
83
|
+
|
84
|
+
Set `Snapuser.redirect_url` to configure where the user is redirected after a successful login. By default, "/profile".
|
85
|
+
|
86
|
+
Set `Snapuser.layout` to configure which layout is used in the admin views, when you edit a user for instance. By default, "admin".
|
data/Rakefile
CHANGED
@@ -4,34 +4,4 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Snapuser'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
|
-
|
21
|
-
load 'rails/tasks/statistics.rake'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
7
|
Bundler::GemHelper.install_tasks
|
26
|
-
|
27
|
-
require 'rake/testtask'
|
28
|
-
|
29
|
-
Rake::TestTask.new(:test) do |t|
|
30
|
-
t.libs << 'lib'
|
31
|
-
t.libs << 'test'
|
32
|
-
t.pattern = 'test/**/*_test.rb'
|
33
|
-
t.verbose = false
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
task default: :test
|
@@ -3,13 +3,13 @@
|
|
3
3
|
<div>
|
4
4
|
<p>
|
5
5
|
<%= f.label :name %><br>
|
6
|
-
<%= f.text_field :name
|
6
|
+
<%= f.text_field :name %>
|
7
7
|
</p>
|
8
8
|
</div>
|
9
9
|
<div>
|
10
10
|
<p>
|
11
11
|
<%= f.label :password %><br>
|
12
|
-
<%= f.password_field :password
|
12
|
+
<%= f.password_field :password %>
|
13
13
|
</p>
|
14
14
|
</div>
|
15
15
|
<div class="rem">
|
data/lib/snapuser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapuser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khcr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- MIT-LICENSE
|
91
|
+
- README.md
|
91
92
|
- Rakefile
|
92
93
|
- app/assets/stylesheets/snapuser.css
|
93
94
|
- app/assets/stylesheets/snapuser/snapuser.css.scss
|
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
131
|
version: '0'
|
131
132
|
requirements: []
|
132
133
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.6.10
|
134
135
|
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: A rails engine to add a simple authentification and permission system.
|