sinatra-backstage 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinatra/backstage/user/user_middleware.rb +23 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ece14fd900a01402c3bce2e19de3e6bd6773bf3
|
4
|
+
data.tar.gz: 3d241c4fcee4b46a4e160a1ae1e77f543d979267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c3d0f14840b2bfa679c28092264f95c3e0becb624ba7077dabd7338665f307733019419e385b5fc5b2387a1957709d347cba86228b8dfdc0ac02532995b889
|
7
|
+
data.tar.gz: b2d0b615d96bc594642279cb0aa644fcd4850d9ec9cbf8f403c48568d20c75922955ac22a2b25cf5abd7e9830dcb4e04322273c95f5c37f62841e396d8ad136f
|
@@ -28,7 +28,7 @@ module Sinatra
|
|
28
28
|
app.post '/signup' do
|
29
29
|
# puts "params = #{params}"
|
30
30
|
# halt
|
31
|
-
@errors =
|
31
|
+
@errors = {}
|
32
32
|
begin
|
33
33
|
user = settings.user_class.create(
|
34
34
|
params[:user].merge({:role => :user})
|
@@ -36,13 +36,19 @@ module Sinatra
|
|
36
36
|
set_session user
|
37
37
|
redirect '/'
|
38
38
|
rescue DataMapper::SaveFailureError => e
|
39
|
-
puts e.resource.errors.inspect
|
40
|
-
e.resource.errors.
|
41
|
-
|
42
|
-
|
39
|
+
# puts e.resource.errors.inspect
|
40
|
+
# puts "-- Backstage::UserMiddleware /signup rescue ( e.resource.errors.keys = #{e.resource.errors.keys} )"
|
41
|
+
# puts "-- Backstage::UserMiddleware /signup rescue ( e.resource.errors.to_hash = #{e.resource.errors.to_hash} )"
|
42
|
+
e.resource.errors.to_hash.each do |key, error|
|
43
|
+
# puts "-- Backstage::UserMiddleware /signup rescue each ( key = #{key} )"
|
44
|
+
# puts "-- Backstage::UserMiddleware /signup rescue each ( error[0].to_s = #{error[0].to_s} )"
|
45
|
+
@errors[key.to_s] = {
|
46
|
+
'text' => error[0].to_s,
|
47
|
+
'autofocus' => true
|
48
|
+
}
|
43
49
|
end
|
44
|
-
@errors.flatten!
|
45
|
-
puts @errors.inspect
|
50
|
+
# @errors.flatten!
|
51
|
+
# puts @errors.inspect
|
46
52
|
params[:user].delete_if do |key, val|
|
47
53
|
['password', 'password_confirmation'].include? key
|
48
54
|
end
|
@@ -53,19 +59,26 @@ module Sinatra
|
|
53
59
|
|
54
60
|
### login user
|
55
61
|
app.post '/login' do
|
56
|
-
@errors =
|
62
|
+
@errors = {}
|
57
63
|
password = params[:user].delete('password')
|
58
64
|
user = settings.user_class.first params[:user]
|
59
65
|
# puts "User::Middleware post '/login' ( params[:user] = #{params[:user]} )"
|
60
66
|
# puts "User::Middleware post '/login' ( user = #{user} )"
|
67
|
+
ident_field = params[:user].keys.first
|
61
68
|
if user.nil?
|
62
|
-
@errors
|
69
|
+
@errors[ident_field] = {
|
70
|
+
'text' => "Incorrect #{params[:user].keys.join(' or ')}",
|
71
|
+
'autofocus' => true
|
72
|
+
}
|
63
73
|
else
|
64
74
|
if user.password == password
|
65
75
|
set_session user
|
66
76
|
redirect '/'
|
67
77
|
else
|
68
|
-
@errors
|
78
|
+
@errors['password'] = {
|
79
|
+
'text' => "Incorrect password",
|
80
|
+
'autofocus' => true
|
81
|
+
}
|
69
82
|
end
|
70
83
|
end
|
71
84
|
eval "#{settings.render_engine} 'user/login'"
|