maxjustus-sinatra-authentication 0.0.1 → 0.0.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.
- data/Rakefile +1 -1
- data/lib/models/user.rb +2 -2
- data/lib/sinatra-authentication.rb +4 -8
- data/lib/views/edit.haml +2 -2
- data/lib/views/index.haml +4 -1
- data/sinatra-authentication.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
require 'rake'
|
|
3
3
|
require 'echoe'
|
|
4
4
|
|
|
5
|
-
Echoe.new('sinatra-authentication', '0.0.
|
|
5
|
+
Echoe.new('sinatra-authentication', '0.0.2') do |p|
|
|
6
6
|
p.description = "Simple authentication plugin for sinatra."
|
|
7
7
|
p.url = "http://github.com/maxjustus/sinatra-authentication"
|
|
8
8
|
p.author = "Max Justus Spransy"
|
data/lib/models/user.rb
CHANGED
|
@@ -8,7 +8,7 @@ class User
|
|
|
8
8
|
property :hashed_password, String
|
|
9
9
|
property :salt, String, :protected => true, :nullable => false
|
|
10
10
|
property :created_at, DateTime
|
|
11
|
-
property :permission_level, Integer, :default =>
|
|
11
|
+
property :permission_level, Integer, :default => 1
|
|
12
12
|
|
|
13
13
|
validates_present :password_confirmation, :unless => Proc.new { |t| t.hashed_password }
|
|
14
14
|
validates_present :password, :unless => Proc.new { |t| t.hashed_password }
|
|
@@ -28,7 +28,7 @@ class User
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def admin?
|
|
31
|
-
self.permission_level == -1
|
|
31
|
+
self.permission_level == -1 || self.id == 1
|
|
32
32
|
end
|
|
33
33
|
protected
|
|
34
34
|
|
|
@@ -123,8 +123,6 @@ module Sinatra
|
|
|
123
123
|
redirect '/'
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
|
-
|
|
127
|
-
|
|
128
126
|
end
|
|
129
127
|
|
|
130
128
|
module Helpers
|
|
@@ -139,8 +137,6 @@ module Sinatra
|
|
|
139
137
|
end
|
|
140
138
|
|
|
141
139
|
def current_user
|
|
142
|
-
# TODO
|
|
143
|
-
# considering returning a user like object with a permission method if not logged in
|
|
144
140
|
if session[:user]
|
|
145
141
|
User.first(:id => session[:user])
|
|
146
142
|
else
|
|
@@ -179,11 +175,11 @@ module Sinatra
|
|
|
179
175
|
logout_parameters = html_attributes
|
|
180
176
|
# a tad janky?
|
|
181
177
|
logout_parameters.delete(:rel)
|
|
182
|
-
result += "<a href='/
|
|
183
|
-
result += "<a href='/
|
|
178
|
+
result += "<a href='/users/#{current_user.id}/edit' class='#{css_classes} sinatra-authentication-edit' #{parameters}>edit account</a> "
|
|
179
|
+
result += "<a href='/logout' class='#{css_classes} sinatra-authentication-logout' #{logout_parameters}>logout</a>"
|
|
184
180
|
else
|
|
185
|
-
result += "<a href='/
|
|
186
|
-
result += "<a href='/
|
|
181
|
+
result += "<a href='/signup' class='#{css_classes} sinatra-authentication-signup' #{parameters}>signup</a> "
|
|
182
|
+
result += "<a href='/login' class='#{css_classes} sinatra-authentication-login' #{parameters}>login</a>"
|
|
187
183
|
end
|
|
188
184
|
|
|
189
185
|
result += "</div>"
|
data/lib/views/edit.haml
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
- if current_user.admin? && current_user.id != @user.id
|
|
13
13
|
%br
|
|
14
14
|
%select{ :id => "permission_level", :name => "user[permission_level]" }
|
|
15
|
-
%option{:value => -1}
|
|
15
|
+
%option{:value => -1, :selected => @user.admin?}
|
|
16
16
|
admin
|
|
17
|
-
%option{:value => 1}
|
|
17
|
+
%option{:value => 1, :selected => @user.permission_level == 1}
|
|
18
18
|
authenticated user
|
|
19
19
|
permission level
|
|
20
20
|
%br
|
data/lib/views/index.haml
CHANGED
|
@@ -16,4 +16,7 @@
|
|
|
16
16
|
%td
|
|
17
17
|
%a{:href => "/users/#{user.id}/edit"} edit
|
|
18
18
|
%td
|
|
19
|
-
|
|
19
|
+
- if user.id != 1
|
|
20
|
+
%a{:href => "/users/#{user.id}/delete", :onclick => "return confirm('you sure?')"} delete
|
|
21
|
+
- else
|
|
22
|
+
site admin
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{sinatra-authentication}
|
|
5
|
-
s.version = "0.0.
|
|
5
|
+
s.version = "0.0.2"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Max Justus Spransy"]
|
|
9
|
-
s.date = %q{2009-04-
|
|
9
|
+
s.date = %q{2009-04-22}
|
|
10
10
|
s.description = %q{Simple authentication plugin for sinatra.}
|
|
11
11
|
s.email = %q{maxjustus@gmail.com}
|
|
12
12
|
s.extra_rdoc_files = ["lib/models/user.rb", "lib/views/signup.haml", "lib/views/edit.haml", "lib/views/login.haml", "lib/views/index.haml", "lib/views/show.haml", "lib/sinatra-authentication.rb", "TODO"]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maxjustus-sinatra-authentication
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Max Justus Spransy
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-04-
|
|
12
|
+
date: 2009-04-22 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|