gennaro 0.2 → 0.2.1

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: f276db9cbe8d7450b3fdbbb057a49d7ad9c56f5e
4
- data.tar.gz: b4c8e77897d5600237aae200cea2a0b9049a7ff6
3
+ metadata.gz: e4d5143a79ab2cf7e6e3ccb6dea61bd0b7290de0
4
+ data.tar.gz: 462d31e7772aac3b15b27a2f7631b638f8101e7c
5
5
  SHA512:
6
- metadata.gz: 9f6f92734e9f9a5c662aa6964c3c897d68a48c7211281c3094e38534860b586024461c04bbf824da0cb15179672a48f53d61048578948d07d148ce72f15f92c5
7
- data.tar.gz: dc0c89c79ae0c4d2a9af2f78d0b5568d51f0ac36f2452e1bc7c9e766bc45585abda00cd8f010e1cd958fc960290b645720d76d33a67f554bd5981d66ff766aff
6
+ metadata.gz: 7a5f52841341d2b93d7c48b14e0eb44811bb0ea4afa1cc25dd1e07483d5970f4f00086eb208145106f663f0e74a1e59714fce38d33c3ba76adb6eeecfc75f9d1
7
+ data.tar.gz: 2b9cecbeca7b065ae60cbad34e2d54a7da2d399efd84c79a13d48732f605366b188d9e8b378ca2d82408c04fb6f8ce39d9f8aad52a8bee8f3cbc48f8f9b4f652
@@ -10,6 +10,6 @@
10
10
 
11
11
  class Gennaro
12
12
  def self.version
13
- '0.2'
13
+ '0.2.1'
14
14
  end
15
15
  end
@@ -0,0 +1,86 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class ${ClassName}
12
+ post '/user/login/?' do
13
+ if logged_in?
14
+ return 'You are already logged in.'
15
+ end
16
+
17
+ if User.login params[:username], params[:password]
18
+ 'Login successful.'
19
+ else
20
+ 'Login failed.'
21
+ end
22
+ end
23
+
24
+ post '/user/logout/?' do
25
+ if logged_in?
26
+ current_user.logout!
27
+ 'Logout successful.'
28
+ else
29
+ 'You are not logged in.'
30
+ end
31
+ end
32
+
33
+ post '/user/signup/?' do
34
+ if logged_in?
35
+ return 'You are already logged in.'
36
+ end
37
+
38
+ if User.exists? params[:username]
39
+ 'The username you have chosen is already taken.'
40
+ else
41
+ user = User.new params[:username], params[:email], params[:password], User.user
42
+ if user.errors.any?
43
+ user.errors.first
44
+ else
45
+ 'Sign up successful.'
46
+ end
47
+ end
48
+ end
49
+
50
+ post '/user/lost_password/?' do
51
+ if logged_in?
52
+ return 'You are already logged in.'
53
+ end
54
+
55
+ if User.exists? params[:username]
56
+ User.lost_password params[:username]
57
+ else
58
+ 'The given username doesn\'t exists.'
59
+ end
60
+ end
61
+
62
+ post '/user/password_recovery/?' do
63
+ if logged_in?
64
+ return 'You are already logged in.'
65
+ end
66
+
67
+ if User.password_recovery params[:username], params[:passcode], params[:password]
68
+ 'Password set successful.'
69
+ else
70
+ 'Error setting the password.'
71
+ end
72
+ end
73
+
74
+ post '/user/new_password/?' do
75
+ unless logged_in?
76
+ return 'You need to log in.'
77
+ end
78
+
79
+ user = current_user.new_password params[:curr_password], params[:password]
80
+ if user
81
+ 'Your new password has been set.'
82
+ else
83
+ 'Error setting your new password.'
84
+ end
85
+ end
86
+ end
@@ -15,5 +15,10 @@ class ${ClassName}
15
15
  return guest unless cookie_exists? 'userid'
16
16
  User.first(:session => get_cookie('sessid')) || guest
17
17
  end
18
+
19
+ def logged_in?
20
+ current_user.is_a? User
21
+ end
22
+ alias_method :logged?, :logged_in?
18
23
  end
19
24
  end
@@ -72,6 +72,12 @@ class User
72
72
  self.session = ''
73
73
  true
74
74
  end
75
+ alias_method :logout!, :logout
76
+
77
+ def new_password(curr_password, password)
78
+ return false unless self.salted_password == BCrypt::Engine.hash_secret(curr_password, self.salt)
79
+ self.password = password
80
+ end
75
81
 
76
82
  class << self
77
83
  def banned
@@ -126,8 +132,9 @@ class User
126
132
  false
127
133
  end
128
134
  end
129
- alias_method :login, :authentication
130
- alias_method :signin, :authentication
135
+ alias_method :login, :authentication
136
+ alias_method :signin, :authentication
137
+ alias_method :authenticate, :authentication
131
138
 
132
139
  def logout(username)
133
140
  user = User.first(:username => username)
@@ -135,6 +142,7 @@ class User
135
142
  user.update(:session => '')
136
143
  user.session.empty?
137
144
  end
145
+ alias_method :logout!, :logout
138
146
 
139
147
  def logged?(username, session)
140
148
  User.count(:username => username, :session => session) == 1
@@ -160,5 +168,12 @@ class User
160
168
  :password => password
161
169
  })
162
170
  end
171
+
172
+ def new_password(username, curr_password, password)
173
+ user = User.first(:username => username)
174
+ return false unless user
175
+ return false unless user.salted_password == BCrypt::Engine.hash_secret(curr_password, user.salt)
176
+ user.update(:password => password)
177
+ end
163
178
  end
164
179
  end
@@ -60,4 +60,14 @@ describe 'App' do
60
60
 
61
61
  User.login(username, new_password).should be_true
62
62
  end
63
+
64
+ it 'set a new password' do
65
+ username = 'Gennaro'
66
+ curr_password = 'sonounnuovobullo!'
67
+ password = 'sonopropriounbullo!'
68
+
69
+ User.login(username, curr_password).should be_true
70
+ User.new_password(username, curr_password, password).should be_true
71
+ User.login(username, password).should be_true
72
+ end
63
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gennaro
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-15 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -50,6 +50,7 @@ files:
50
50
  - lib/gennaro/gennaro.rb
51
51
  - lib/gennaro/version.rb
52
52
  - lib/gennaro.rb
53
+ - templates/authentication/app/controllers/users.rb
53
54
  - templates/authentication/app/helpers/cookie.rb
54
55
  - templates/authentication/app/helpers/csrf.rb
55
56
  - templates/authentication/app/helpers/user.rb