gennaro 0.3.2.1 → 0.3.2.2
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/lib/gennaro/version.rb +1 -1
- data/templates/authentication/app/controllers/users.rb +45 -0
- data/templates/authentication/app/models/user.rb +30 -8
- data/templates/authentication/spec/user_spec.rb +14 -1
- data/templates/authentication/views/user/change_level.erb +35 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 736ce9fd63b913dff9a5d1620a7487d7eee9f87c
|
4
|
+
data.tar.gz: 185ec1cfb4c872fbc2b2f2c300f92d92d079745f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97009f17bd4ac06754f6eb794e5f3edfeb2b7199917ea6d1903bb22e46f4635c0feca5129309e275b27bb61c4cc1e071971122dc9c59c448ae0e2fbd9b3e8c5
|
7
|
+
data.tar.gz: fe65d76d7e25c7e5d3ac550e85cd1d92907ee70c4d817b2b2109b7ee4fc171c5ed1441fdc27a63d599c37bb9215f5619e78ad03a8e891b4725ff4682d1af213e
|
data/lib/gennaro/version.rb
CHANGED
@@ -41,6 +41,17 @@ class ${ClassName}
|
|
41
41
|
erb :'user/password_recovery'
|
42
42
|
end
|
43
43
|
|
44
|
+
get '/user/change_level/?' do
|
45
|
+
if not logged_in?
|
46
|
+
@error = 'You need to log in.'
|
47
|
+
elsif not current_user.staff?
|
48
|
+
@error = 'Go home, this is not a place for you.'
|
49
|
+
else
|
50
|
+
@users = User.all
|
51
|
+
end
|
52
|
+
erb :'user/change_level'
|
53
|
+
end
|
54
|
+
|
44
55
|
post '/user/login/?' do
|
45
56
|
if not fields? :username, :password
|
46
57
|
@error = 'You have to complete all the required fields.'
|
@@ -108,4 +119,38 @@ class ${ClassName}
|
|
108
119
|
|
109
120
|
erb :'user/password_recovery'
|
110
121
|
end
|
122
|
+
|
123
|
+
post '/user/change_level/?' do
|
124
|
+
if not logged_in?
|
125
|
+
@error = 'You need to log in.'
|
126
|
+
elsif not current_user.staff?
|
127
|
+
@error = 'Go home, this is not a place for you.'
|
128
|
+
elsif fields? :username, :go
|
129
|
+
@user = User.get params[:username]
|
130
|
+
@levels = User.levels
|
131
|
+
elsif not fields? :username, :level
|
132
|
+
@error = 'To change a user level, you need to send his username and level.'
|
133
|
+
else
|
134
|
+
level = case # I guess using #send could be dangerous
|
135
|
+
when 'banned' then User.banned
|
136
|
+
when 'founder' then User.founder
|
137
|
+
when 'admin' then User.admin
|
138
|
+
when 'smod' then User.smod
|
139
|
+
when 'mod' then User.mod
|
140
|
+
when 'user' then User.user
|
141
|
+
else nil
|
142
|
+
end
|
143
|
+
if level.nil?
|
144
|
+
@error = 'User level not recognized.'
|
145
|
+
else
|
146
|
+
user = User.change_level params[:username], level
|
147
|
+
if user
|
148
|
+
@success = 'User level set successful.'
|
149
|
+
else
|
150
|
+
@error = 'Error setting the user level.'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
erb :'user/change_level'
|
155
|
+
end
|
111
156
|
end
|
@@ -12,16 +12,16 @@ class User
|
|
12
12
|
include DataMapper::Resource
|
13
13
|
|
14
14
|
property :id, Serial
|
15
|
-
property :username, String, :
|
16
|
-
:
|
17
|
-
:
|
18
|
-
property :email, String, :
|
19
|
-
:
|
15
|
+
property :username, String, unique: true,
|
16
|
+
length: 4..16,
|
17
|
+
format: /^[a-zA-Z0-9_\-\*^]*$/
|
18
|
+
property :email, String, unique: true,
|
19
|
+
format: :email_address
|
20
20
|
|
21
|
-
property :permission_level, Integer, :
|
21
|
+
property :permission_level, Integer, default: 4
|
22
22
|
|
23
|
-
property :salt, String, :
|
24
|
-
property :salted_password, String, :
|
23
|
+
property :salt, String, length: 29
|
24
|
+
property :salted_password, String, length: 60
|
25
25
|
property :lost_password, String
|
26
26
|
property :session, String
|
27
27
|
|
@@ -78,6 +78,10 @@ class User
|
|
78
78
|
end
|
79
79
|
alias_method :logout!, :logout
|
80
80
|
|
81
|
+
def change_level(permission_level)
|
82
|
+
self.permission_level = permission_level
|
83
|
+
end
|
84
|
+
|
81
85
|
class << self
|
82
86
|
def banned
|
83
87
|
-1
|
@@ -108,6 +112,18 @@ class User
|
|
108
112
|
5
|
109
113
|
end
|
110
114
|
|
115
|
+
def levels
|
116
|
+
{
|
117
|
+
:banned => User.banned,
|
118
|
+
:founder => User.founder,
|
119
|
+
:admin => User.admin,
|
120
|
+
:smod => User.smod,
|
121
|
+
:gmod => User.gmod,
|
122
|
+
:mod => User.mod,
|
123
|
+
:user => User.user
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
111
127
|
def empty?
|
112
128
|
User.count == 0
|
113
129
|
end
|
@@ -162,5 +178,11 @@ class User
|
|
162
178
|
:password => password
|
163
179
|
})
|
164
180
|
end
|
181
|
+
|
182
|
+
def change_level(username, permission_level)
|
183
|
+
user = User.first username: username
|
184
|
+
return false unless user
|
185
|
+
user.update permission_level: permission_level
|
186
|
+
end
|
165
187
|
end
|
166
188
|
end
|
@@ -4,7 +4,7 @@ require './spec'
|
|
4
4
|
require 'rspec'
|
5
5
|
require 'rack/test'
|
6
6
|
|
7
|
-
describe '
|
7
|
+
describe 'Pigro' do
|
8
8
|
def app
|
9
9
|
Sinatra::Application
|
10
10
|
end
|
@@ -60,4 +60,17 @@ describe '${ClassName}' do
|
|
60
60
|
|
61
61
|
User.login(username, new_password).should be_true
|
62
62
|
end
|
63
|
+
|
64
|
+
it 'change the user level' do
|
65
|
+
username = 'Gennaro'
|
66
|
+
password = 'sonounnuovobullo!'
|
67
|
+
|
68
|
+
User.login(username, password).should be_true
|
69
|
+
|
70
|
+
user = User.get username
|
71
|
+
user.founder?
|
72
|
+
|
73
|
+
user.change_level User.banned
|
74
|
+
user.banned?
|
75
|
+
end
|
63
76
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<% @title = 'Change user level' %>
|
2
|
+
<%= erb :'template/header' %>
|
3
|
+
|
4
|
+
<% if defined? @error %>
|
5
|
+
<p class="error"><%= @error %></p>
|
6
|
+
<% elsif defined? @success %>
|
7
|
+
<p class="success"><%= @success %></p>
|
8
|
+
<% elsif defined? @users %>
|
9
|
+
<form action="<%= @current_url %>" method="post">
|
10
|
+
|
11
|
+
<select name="username">
|
12
|
+
<% @users.each { |user| %>
|
13
|
+
<option value="<%= user.username %>"><%= user.username %></option>
|
14
|
+
<% } %>
|
15
|
+
</select><br />
|
16
|
+
|
17
|
+
<%= csrf_tag %>
|
18
|
+
<input type="submit" name="go" value="Change">
|
19
|
+
</form>
|
20
|
+
<% else %>
|
21
|
+
<form action="<%= @current_url %>" method="post">
|
22
|
+
|
23
|
+
<select name="level">
|
24
|
+
<% @levels.each_pair { |key, val| %>
|
25
|
+
<option value="<%= key %>" <%= 'selected' if val == @user.permission_level %>><%= key.capitalize %></option>
|
26
|
+
<% } %>
|
27
|
+
</select><br />
|
28
|
+
|
29
|
+
<%= csrf_tag %>
|
30
|
+
<input type="hidden" value="<%= @user.username %>" name="username">
|
31
|
+
<input type="submit" value="Change">
|
32
|
+
</form>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<%= erb :'template/footer' %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gennaro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2.
|
4
|
+
version: 0.3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- templates/authentication/views/index.erb
|
67
67
|
- templates/authentication/views/template/footer.erb
|
68
68
|
- templates/authentication/views/template/header.erb
|
69
|
+
- templates/authentication/views/user/change_level.erb
|
69
70
|
- templates/authentication/views/user/login.erb
|
70
71
|
- templates/authentication/views/user/logout.erb
|
71
72
|
- templates/authentication/views/user/lost_password.erb
|