gennaro 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/gennaro +61 -0
- data/lib/gennaro.rb +15 -0
- data/lib/gennaro/file.rb +39 -0
- data/lib/gennaro/gennaro.rb +57 -0
- data/lib/gennaro/version.rb +15 -0
- data/templates/authentication/Gemfile +8 -0
- data/templates/authentication/Rakefile +11 -0
- data/templates/authentication/_class_name_.rb +38 -0
- data/templates/authentication/app/helpers/cookie.rb +36 -0
- data/templates/authentication/app/helpers/csrf.rb +21 -0
- data/templates/authentication/app/helpers/user.rb +19 -0
- data/templates/authentication/app/models/guest.rb +19 -0
- data/templates/authentication/app/models/user.rb +164 -0
- data/templates/authentication/spec/spec.rb +38 -0
- data/templates/authentication/spec/user_spec.rb +63 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89687f2500425a38190395abd9602bcf0324b4fe
|
4
|
+
data.tar.gz: 54564b681863d3e03ea7c3e92cbfebd4d9c6390a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf3b67e0fffd70396e4c32995c477f238dad15a20e51597bdb2b0be4ca5cde400adc5399c1490f29a7456d7a792fcbf89d6722e3eab5a336a864ba4018efc560
|
7
|
+
data.tar.gz: f9353363fe4b3cefd5986cb696206a1ed8d2c723d27548000df04441ef267d72b22ba80064c8a2a836ee4e22c28fe6d35cb3275c1b4416fef387e782fc3ce8be
|
data/bin/gennaro
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
4
|
+
# Version 2, December 2004
|
5
|
+
#
|
6
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
7
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
8
|
+
#
|
9
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
10
|
+
#++
|
11
|
+
|
12
|
+
require 'optparse'
|
13
|
+
require 'gennaro'
|
14
|
+
|
15
|
+
options = {
|
16
|
+
:classname => 'App',
|
17
|
+
:path => Dir.pwd,
|
18
|
+
:force => false,
|
19
|
+
:template_path => File.expand_path('../../templates', __FILE__)
|
20
|
+
}
|
21
|
+
|
22
|
+
opt = OptionParser.new { |o|
|
23
|
+
o.on '-c', '--classname CLASSNAME', 'main class name' do |classname|
|
24
|
+
options[:classname] = classname
|
25
|
+
end
|
26
|
+
|
27
|
+
o.on '-p', '--path PATH', 'installation path' do |path|
|
28
|
+
options[:path] = File.expand_path path
|
29
|
+
end
|
30
|
+
|
31
|
+
o.on '-f', '--force', 'eventually overwrite target app folder' do
|
32
|
+
options[:force] = true
|
33
|
+
end
|
34
|
+
|
35
|
+
o.on '-l', '--list', 'get a list of available templates' do
|
36
|
+
abort Gennaro.get_templates(options[:template_path]).join ', '
|
37
|
+
end
|
38
|
+
|
39
|
+
o.on '-g', '--generate TEMPLATE', 'generate the given template' do |template|
|
40
|
+
options[:template] = template
|
41
|
+
end
|
42
|
+
|
43
|
+
o.on '-t', '--template-path PATH', 'use given template folder' do |path|
|
44
|
+
options[:template_path] = File.expand_path path
|
45
|
+
end
|
46
|
+
}
|
47
|
+
|
48
|
+
help = opt.to_s
|
49
|
+
opt.parse!
|
50
|
+
|
51
|
+
abort help unless options.include? :template
|
52
|
+
|
53
|
+
unless Gennaro.template_exists? options[:template_path], options[:template]
|
54
|
+
puts 'Template not found.'
|
55
|
+
else
|
56
|
+
template = File.join options[:template_path], options[:template]
|
57
|
+
gennaro = Gennaro.new template, options[:classname], options[:path], options[:force]
|
58
|
+
gennaro.generate!
|
59
|
+
gennaro.replace_tags!
|
60
|
+
puts "All done. Execute 'cd #{gennaro.path} && bundle install && rake test'"
|
61
|
+
end
|
data/lib/gennaro.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
4
|
+
# Version 2, December 2004
|
5
|
+
#
|
6
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
7
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
8
|
+
#
|
9
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
10
|
+
#++
|
11
|
+
|
12
|
+
require 'fileutils'
|
13
|
+
require 'gennaro/file'
|
14
|
+
require 'gennaro/gennaro'
|
15
|
+
require 'gennaro/version'
|
data/lib/gennaro/file.rb
ADDED
@@ -0,0 +1,39 @@
|
|
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 Gennaro
|
12
|
+
protected
|
13
|
+
def mkdir(path)
|
14
|
+
Dir.mkdir path unless Dir.exists? path
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def copy(what, where)
|
19
|
+
FileUtils.copy_entry what, where
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def each_file(path, &block)
|
24
|
+
Dir.glob("#{path}/**/*").each { |f|
|
25
|
+
next if File.directory? f
|
26
|
+
yield f
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def rename(file, first, after)
|
32
|
+
new_file = file.gsub(first, after)
|
33
|
+
FileUtils.mv file, new_file if file != new_file
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_dir(path)
|
37
|
+
FileUtils.rm_r path if Dir.exists? path
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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 Gennaro
|
12
|
+
attr_accessor :template, :classname, :appname, :path
|
13
|
+
|
14
|
+
def initialize(template, classname, path, force = false)
|
15
|
+
@template = template
|
16
|
+
@classname = classname
|
17
|
+
@appname = classname.downcase
|
18
|
+
@path = File.join path, @appname
|
19
|
+
|
20
|
+
delete_dir @path if force
|
21
|
+
raise ArgumentError, "#{@path} already exists." if Dir.exists? @path
|
22
|
+
raise ArgumentError, "#{@template} not found." unless Dir.exists? @template
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_random_string(length = 8)
|
26
|
+
dict = (?a..?z).to_a + (?A..?Z).to_a + (0..9).to_a
|
27
|
+
(0..length).map { dict.sample}.join
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate!
|
31
|
+
mkdir @path
|
32
|
+
copy @template, @path
|
33
|
+
end
|
34
|
+
|
35
|
+
def replace_tags!
|
36
|
+
each_file(@appname) { |f|
|
37
|
+
rename f, /_class_name_/, @appname
|
38
|
+
}
|
39
|
+
|
40
|
+
each_file(@appname) { |f|
|
41
|
+
s = File.read f
|
42
|
+
File.open(f, ?w) { |f|
|
43
|
+
s.gsub! '${ClassName}', @classname
|
44
|
+
s.gsub! '${GenerateString}', get_random_string(36)
|
45
|
+
f.write s
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.get_templates(path)
|
51
|
+
Dir.glob("#{path}/*").map { |f| File.basename f}
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.template_exists?(path, template)
|
55
|
+
self.get_templates(path).include? template
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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 Gennaro
|
12
|
+
def self.version
|
13
|
+
'0.1'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
require 'sinatra/base'
|
12
|
+
require 'bcrypt'
|
13
|
+
require 'data_mapper'
|
14
|
+
require 'dm-sqlite-adapter'
|
15
|
+
require 'rack/csrf'
|
16
|
+
|
17
|
+
class ${ClassName} < Sinatra::Base
|
18
|
+
db_path = File.join Dir.pwd, 'db'
|
19
|
+
Dir.mkdir db_path unless Dir.exists? db_path
|
20
|
+
DataMapper.setup :default, "sqlite3://#{db_path}/app.db"
|
21
|
+
|
22
|
+
configure {
|
23
|
+
use Rack::Session::Cookie,
|
24
|
+
:path => '/',
|
25
|
+
:secret => '${GenerateString}'
|
26
|
+
|
27
|
+
use Rack::Csrf,
|
28
|
+
:raise => true,
|
29
|
+
:field => '_csrf'
|
30
|
+
}
|
31
|
+
|
32
|
+
Dir.glob("#{Dir.pwd}/app/helpers/*.rb") { |h| require h.chomp }
|
33
|
+
Dir.glob("#{Dir.pwd}/app/models/*.rb") { |m| require m.chomp }
|
34
|
+
Dir.glob("#{Dir.pwd}/app/controllers/*.rb") { |c| require c.chomp }
|
35
|
+
|
36
|
+
DataMapper.finalize
|
37
|
+
User.auto_migrate!
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
+
helpers do
|
13
|
+
def set_cookie(key, value, path = '/', expires = nil)
|
14
|
+
response.set_cookie key, {
|
15
|
+
:value => value,
|
16
|
+
:path => path,
|
17
|
+
:expires => expires || Time.now + 24 * 60 * 60
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_cookie(key)
|
22
|
+
response.set_cookie key, {
|
23
|
+
:value => '',
|
24
|
+
:expires => Time.now
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def cookie_exists?(key)
|
29
|
+
request.cookies.include? key
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_cookie(key)
|
33
|
+
cookie_exists?(key) ? request.cookies[key] : nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
helpers do
|
13
|
+
def csrf_token
|
14
|
+
Rack::Csrf.csrf_token env
|
15
|
+
end
|
16
|
+
|
17
|
+
def csrf_tag
|
18
|
+
Rack::Csrf.csrf_tag env
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
helpers do
|
13
|
+
def current_user
|
14
|
+
guest = Guest.new
|
15
|
+
return guest unless cookie_exists? 'userid'
|
16
|
+
User.first(:session => get_cookie('sessid')) || guest
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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 Guest
|
12
|
+
def guest?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def permission_level
|
17
|
+
User.guest
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,164 @@
|
|
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 User
|
12
|
+
include DataMapper::Resource
|
13
|
+
|
14
|
+
property :id, Serial
|
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
|
+
|
21
|
+
property :permission_level, Integer, :default => 3,
|
22
|
+
:max => 3
|
23
|
+
|
24
|
+
property :salt, String, :length => 29
|
25
|
+
property :salted_password, String, :length => 60
|
26
|
+
property :lost_password, String
|
27
|
+
property :session, String
|
28
|
+
|
29
|
+
property :created_at, DateTime
|
30
|
+
property :updated_at, DateTime
|
31
|
+
|
32
|
+
def password=(password)
|
33
|
+
self.salt = BCrypt::Engine.generate_salt
|
34
|
+
self.salted_password = BCrypt::Engine.hash_secret password, self.salt
|
35
|
+
end
|
36
|
+
|
37
|
+
def founder?
|
38
|
+
self.id == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def admin?
|
42
|
+
self.permission_level == User.admin
|
43
|
+
end
|
44
|
+
|
45
|
+
def smod?
|
46
|
+
self.permission_level == User.smod
|
47
|
+
end
|
48
|
+
alias_method :gmod?, :smod?
|
49
|
+
|
50
|
+
def mod?
|
51
|
+
self.permission_level == User.mod
|
52
|
+
end
|
53
|
+
|
54
|
+
def user?
|
55
|
+
self.permission_level == User.user
|
56
|
+
end
|
57
|
+
|
58
|
+
def banned?
|
59
|
+
self.permission_level == User.banned
|
60
|
+
end
|
61
|
+
|
62
|
+
def guest?
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def logged?(session)
|
67
|
+
self.session == session
|
68
|
+
end
|
69
|
+
alias_method :logged_in?, :logged?
|
70
|
+
|
71
|
+
def logout
|
72
|
+
self.session = ''
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
class << self
|
77
|
+
def banned
|
78
|
+
-1
|
79
|
+
end
|
80
|
+
|
81
|
+
def admin
|
82
|
+
0
|
83
|
+
end
|
84
|
+
|
85
|
+
def smod
|
86
|
+
1
|
87
|
+
end
|
88
|
+
alias_method :gmod, :smod
|
89
|
+
|
90
|
+
def mod
|
91
|
+
2
|
92
|
+
end
|
93
|
+
|
94
|
+
def user
|
95
|
+
3
|
96
|
+
end
|
97
|
+
|
98
|
+
def guest
|
99
|
+
4
|
100
|
+
end
|
101
|
+
|
102
|
+
def get(username)
|
103
|
+
User.first(:username => username)
|
104
|
+
end
|
105
|
+
|
106
|
+
def exists?(username)
|
107
|
+
User.count(:username => username) == 1
|
108
|
+
end
|
109
|
+
|
110
|
+
def registration(username, email, password, permission_level, stuff = {})
|
111
|
+
User.create({
|
112
|
+
:username => username,
|
113
|
+
:email => email,
|
114
|
+
:password => password,
|
115
|
+
:permission_level => permission_level
|
116
|
+
}.merge(stuff))
|
117
|
+
end
|
118
|
+
alias_method :signup, :registration
|
119
|
+
|
120
|
+
def authentication(username, password)
|
121
|
+
user = User.first(:username => username)
|
122
|
+
return false unless user
|
123
|
+
if user.salted_password == BCrypt::Engine.hash_secret(password, user.salt)
|
124
|
+
user.update(:session => BCrypt::Engine.generate_salt)
|
125
|
+
else
|
126
|
+
false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
alias_method :login, :authentication
|
130
|
+
alias_method :signin, :authentication
|
131
|
+
|
132
|
+
def logout(username)
|
133
|
+
user = User.first(:username => username)
|
134
|
+
return false unless user
|
135
|
+
user.update(:session => '')
|
136
|
+
user.session.empty?
|
137
|
+
end
|
138
|
+
|
139
|
+
def logged?(username, session)
|
140
|
+
User.count(:username => username, :session => session) == 1
|
141
|
+
end
|
142
|
+
alias_method :logged_in?, :logged?
|
143
|
+
|
144
|
+
def lost_password(username)
|
145
|
+
user = User.first(:username => username)
|
146
|
+
return false unless user
|
147
|
+
user.update(:lost_password => BCrypt::Engine.generate_salt)
|
148
|
+
user.lost_password
|
149
|
+
end
|
150
|
+
|
151
|
+
def password_recovery(username, lost_password, password)
|
152
|
+
user = User.first({
|
153
|
+
:username => username,
|
154
|
+
:lost_password => lost_password
|
155
|
+
})
|
156
|
+
return false unless user
|
157
|
+
return false if user.lost_password.empty?
|
158
|
+
user.update({
|
159
|
+
:lost_password => '',
|
160
|
+
:password => password
|
161
|
+
})
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
require 'sinatra/base'
|
12
|
+
require 'bcrypt'
|
13
|
+
require 'data_mapper'
|
14
|
+
require 'dm-sqlite-adapter'
|
15
|
+
require 'rack/csrf'
|
16
|
+
|
17
|
+
class ${ClassName} < Sinatra::Base
|
18
|
+
db_path = File.join Dir.pwd, '../', 'db'
|
19
|
+
Dir.mkdir db_path unless Dir.exists? db_path
|
20
|
+
DataMapper.setup :default, "sqlite3://#{db_path}/spec.db"
|
21
|
+
|
22
|
+
configure {
|
23
|
+
use Rack::Session::Cookie,
|
24
|
+
:path => '/',
|
25
|
+
:secret => '${GenerateString}'
|
26
|
+
|
27
|
+
use Rack::Csrf,
|
28
|
+
:raise => true,
|
29
|
+
:field => '_csrf'
|
30
|
+
}
|
31
|
+
|
32
|
+
Dir.glob('../app/helpers/*.rb') { |h| require h.chomp }
|
33
|
+
Dir.glob('../app/models/*.rb') { |m| require m.chomp }
|
34
|
+
Dir.glob('../app/controllers/*.rb') { |c| require c.chomp }
|
35
|
+
|
36
|
+
DataMapper.finalize
|
37
|
+
User.auto_migrate!
|
38
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require './spec'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
describe 'App' do
|
8
|
+
def app
|
9
|
+
Sinatra::Application
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates an user' do
|
13
|
+
username = 'Gennaro'
|
14
|
+
email = 'gennaro@gennaro.ext'
|
15
|
+
password = 'sonopropriounbullo!'
|
16
|
+
permission_level = User.user
|
17
|
+
|
18
|
+
User.exists?(username).should be_false
|
19
|
+
user = User.signup username, email, password, permission_level
|
20
|
+
user.errors.should be_empty
|
21
|
+
user.guest?.should be_false
|
22
|
+
user.user?.should be_true
|
23
|
+
User.exists?(username).should be_true
|
24
|
+
|
25
|
+
user = User.signup username, email, password, permission_level
|
26
|
+
user.errors.should_not be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'logs in a user' do
|
30
|
+
username = 'Gennaro'
|
31
|
+
password = 'sonopropriounbullo!'
|
32
|
+
|
33
|
+
User.exists?(username).should be_true
|
34
|
+
User.login(username, password).should be_true
|
35
|
+
user = User.get username
|
36
|
+
user.session.should have(29).chars
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'logs out a user' do
|
40
|
+
username = 'Gennaro'
|
41
|
+
|
42
|
+
user = User.get username
|
43
|
+
user.session.should have(29).chars
|
44
|
+
user.logout
|
45
|
+
user.session.should be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'recovers lost password' do
|
49
|
+
username = 'Gennaro'
|
50
|
+
new_password = 'sonounnuovobullo!'
|
51
|
+
|
52
|
+
User.login(username, new_password).should be_false
|
53
|
+
|
54
|
+
passcode = User.lost_password username
|
55
|
+
passcode.should_not be_false
|
56
|
+
passcode.should have(29).chars
|
57
|
+
|
58
|
+
recovery = User.password_recovery username, passcode, new_password
|
59
|
+
recovery.should be_true
|
60
|
+
|
61
|
+
User.login(username, new_password).should be_true
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gennaro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Generate templates for Sinatra. The built-in template provide a user
|
14
|
+
authentication model, but you can add as many templates as you want.
|
15
|
+
email: webmaster@giovannicapuano.net
|
16
|
+
executables:
|
17
|
+
- gennaro
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/gennaro/file.rb
|
22
|
+
- lib/gennaro/gennaro.rb
|
23
|
+
- lib/gennaro/version.rb
|
24
|
+
- lib/gennaro.rb
|
25
|
+
- templates/authentication/app/helpers/cookie.rb
|
26
|
+
- templates/authentication/app/helpers/csrf.rb
|
27
|
+
- templates/authentication/app/helpers/user.rb
|
28
|
+
- templates/authentication/app/models/guest.rb
|
29
|
+
- templates/authentication/app/models/user.rb
|
30
|
+
- templates/authentication/Gemfile
|
31
|
+
- templates/authentication/Rakefile
|
32
|
+
- templates/authentication/spec/spec.rb
|
33
|
+
- templates/authentication/spec/user_spec.rb
|
34
|
+
- templates/authentication/_class_name_.rb
|
35
|
+
- bin/gennaro
|
36
|
+
homepage: http://www.giovannicapuano.net
|
37
|
+
licenses:
|
38
|
+
- WTFPL
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.3
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Sinatra template generator.
|
60
|
+
test_files: []
|