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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f6181adcb3d172b124dceba665cae5c8d99a3a7
4
- data.tar.gz: cb5e02188b48fdbd21610bed1fe900b3b1ba5bb2
3
+ metadata.gz: 8ece14fd900a01402c3bce2e19de3e6bd6773bf3
4
+ data.tar.gz: 3d241c4fcee4b46a4e160a1ae1e77f543d979267
5
5
  SHA512:
6
- metadata.gz: da09eedd9134b50a83f216c9461aca84659110738d1127fe3f29baa740083206826d8679cce7e2d7270ddbf7f762994c4654abda182dacca39abf2e821d2766b
7
- data.tar.gz: 19dab607897fd7a9471e7f4dda372405e868ad23c01360d76c9469b1a040550b39238a9cc16339a3aeccfe2fae50b4ed4014d3f6300397fd10582ee2226ba81f
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.each do |error|
41
- puts error.inspect
42
- @errors << error
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 << "Incorrect #{params[:user].keys.join(' or ')}"
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 << "Incorrect password"
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'"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-backstage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov