pretzel-accounts 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +30 -0
- data/lib/pretzel/ext/accounts.rb +54 -0
- data/pretzel.gemspec +22 -0
- data/test/environment.rb +3 -0
- data/test/scrap.db +0 -0
- data/test/scrap.rb +49 -0
- data/test/views/auth_error.liquid +1 -0
- data/test/views/index.liquid +3 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71378d588daa8eb2b325b6b8c51a62a91c68b478
|
4
|
+
data.tar.gz: 5d85e3a1c9dab252dbb7444ae41e5587f35d5406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f4a2f5998f8698e746acbf8e0915a82cb0f8dd0eb8eeb234a8b1b78c1288a1468b6dd2990539f56cd8ba0296b517bc18bfd0dda09a2460e3f790fc5b0b4c6aa
|
7
|
+
data.tar.gz: ddf238a6cd57659547be8cab4552b4d609130384b7261c5dce52409201b8ed921966e19e64304891083b3cea5eb8d5501e75458e3be10655aaf34413da63532a
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pretzel-accounts (0.1.0)
|
5
|
+
bcrypt (~> 3.1)
|
6
|
+
pretzel-orm (~> 0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
bcrypt (3.1.10)
|
12
|
+
liquid (3.0.1)
|
13
|
+
minitest (5.5.1)
|
14
|
+
pretzel-orm (0.1.0)
|
15
|
+
liquid (~> 3.0)
|
16
|
+
sequel (~> 4)
|
17
|
+
sqlite3 (~> 1.3)
|
18
|
+
rack (1.6.0)
|
19
|
+
rack-test (0.6.3)
|
20
|
+
rack (>= 1.0)
|
21
|
+
sequel (4.20.0)
|
22
|
+
sqlite3 (1.3.10)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
minitest (~> 5.5)
|
29
|
+
pretzel-accounts!
|
30
|
+
rack-test (~> 0.6)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "pretzel/orm"
|
2
|
+
require "bcrypt"
|
3
|
+
|
4
|
+
module Pretzel
|
5
|
+
module Accounts
|
6
|
+
|
7
|
+
begin
|
8
|
+
connection = Pretzel::ORM.all_connections[0] # Grab the first initialized connection.
|
9
|
+
connection.create_table? :pretzel_users do
|
10
|
+
primary_key :id
|
11
|
+
string :name
|
12
|
+
string :email
|
13
|
+
string :salt
|
14
|
+
string :password
|
15
|
+
|
16
|
+
unique :name
|
17
|
+
end
|
18
|
+
|
19
|
+
class User < Pretzel::ORM::Model
|
20
|
+
set_dataset :pretzel_users # Set table name
|
21
|
+
exposes :id, :name, :email # Expose attributes to Liquid
|
22
|
+
|
23
|
+
def before_create
|
24
|
+
self.salt = BCrypt::Engine.generate_salt # Make salt
|
25
|
+
self.password = BCrypt::Engine.hash_secret(self.password, self.salt) # Hash password
|
26
|
+
end
|
27
|
+
|
28
|
+
def authenticate?(password)
|
29
|
+
if self.password == BCrypt::Engine.hash_secret(password, self.salt)
|
30
|
+
true
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue Sequel::Error
|
37
|
+
puts "ERROR: Establish a database connection BEFORE requiring pretzel-accounts."
|
38
|
+
end
|
39
|
+
|
40
|
+
module Route
|
41
|
+
def self.included(application)
|
42
|
+
end
|
43
|
+
|
44
|
+
def requires_authentication
|
45
|
+
halt 401 unless !!session[:user]
|
46
|
+
end
|
47
|
+
|
48
|
+
def login(user)
|
49
|
+
session[:user] = user[:id]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/pretzel.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "pretzel-accounts"
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.licenses = "MIT"
|
5
|
+
s.summary = "An accounts system for the Pretzel development suite"
|
6
|
+
s.description = "An accounts system for the Pretzel development suite"
|
7
|
+
s.authors = ["Richard Blechinger"]
|
8
|
+
s.email = ["richard@blechi.at"]
|
9
|
+
s.homepage = "http://github.com/pretzelhands/accounts"
|
10
|
+
|
11
|
+
s.required_ruby_version = ">= 2.0.0"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_runtime_dependency("pretzel-orm", "~> 0")
|
18
|
+
s.add_runtime_dependency("bcrypt", "~> 3.1")
|
19
|
+
|
20
|
+
s.add_development_dependency("rack-test", "~> 0.6")
|
21
|
+
s.add_development_dependency("minitest", "~> 5.5")
|
22
|
+
end
|
data/test/environment.rb
ADDED
data/test/scrap.db
ADDED
Binary file
|
data/test/scrap.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative "environment"
|
2
|
+
|
3
|
+
require "pretzel/core"
|
4
|
+
require "pretzel/orm"
|
5
|
+
Database = Pretzel::ORM::Database.sqlite("scrap.db")
|
6
|
+
|
7
|
+
require "pretzel/ext/templating"
|
8
|
+
require "pretzel/ext/accounts"
|
9
|
+
|
10
|
+
Database.alter_table :pretzel_users do
|
11
|
+
add_column :role, :string
|
12
|
+
end
|
13
|
+
|
14
|
+
class CustomUser < Pretzel::Accounts::User
|
15
|
+
set_dataset :pretzel_users
|
16
|
+
exposes :name, :password, :role
|
17
|
+
end
|
18
|
+
|
19
|
+
user = CustomUser.create(
|
20
|
+
:name => "Richard",
|
21
|
+
:password => "something",
|
22
|
+
:role => "Admin"
|
23
|
+
)
|
24
|
+
|
25
|
+
class Application < Pretzel::Core
|
26
|
+
extends Pretzel::Extension::Templating
|
27
|
+
extends Pretzel::Accounts
|
28
|
+
end
|
29
|
+
|
30
|
+
Application.get "/login" do
|
31
|
+
if user.authenticate? "something"
|
32
|
+
login user
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Application.error 401 do
|
37
|
+
render :auth_error
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
Application.get "/" do
|
42
|
+
requires_authentication
|
43
|
+
render :index, {
|
44
|
+
"something" => "Test!",
|
45
|
+
"current_user" => CustomUser.find(:id => session[:user])
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
Rack::Handler::Thin.run Application.new
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Who are you? And what are you doing here?</h1>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretzel-accounts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Blechinger
|
@@ -74,7 +74,16 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
77
79
|
- LICENSE
|
80
|
+
- lib/pretzel/ext/accounts.rb
|
81
|
+
- pretzel.gemspec
|
82
|
+
- test/environment.rb
|
83
|
+
- test/scrap.db
|
84
|
+
- test/scrap.rb
|
85
|
+
- test/views/auth_error.liquid
|
86
|
+
- test/views/index.liquid
|
78
87
|
homepage: http://github.com/pretzelhands/accounts
|
79
88
|
licenses:
|
80
89
|
- MIT
|
@@ -99,4 +108,9 @@ rubygems_version: 2.2.2
|
|
99
108
|
signing_key:
|
100
109
|
specification_version: 4
|
101
110
|
summary: An accounts system for the Pretzel development suite
|
102
|
-
test_files:
|
111
|
+
test_files:
|
112
|
+
- test/environment.rb
|
113
|
+
- test/scrap.db
|
114
|
+
- test/scrap.rb
|
115
|
+
- test/views/auth_error.liquid
|
116
|
+
- test/views/index.liquid
|