entrance 0.2.1 → 0.2.2
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.
- data/README.md +0 -2
- data/examples/rails-app/db/migrate/20150107032724_create_users.rb +5 -1
- data/examples/rails-app/db/schema.rb +4 -0
- data/examples/sinatra-app/Gemfile +8 -0
- data/examples/sinatra-app/app/models.rb +36 -0
- data/examples/sinatra-app/app/routes.rb +64 -0
- data/examples/sinatra-app/app/views/layout.erb +26 -0
- data/examples/sinatra-app/app/views/login.erb +22 -0
- data/examples/sinatra-app/app/views/signup.erb +25 -0
- data/examples/sinatra-app/app/views/welcome.erb +3 -0
- data/examples/sinatra-app/config.ru +5 -0
- data/lib/entrance/controller.rb +1 -1
- data/lib/entrance/model.rb +4 -3
- data/lib/entrance/version.rb +1 -1
- data/lib/entrance.rb +2 -5
- metadata +10 -3
- data/examples/rails-app/Gemfile.lock +0 -96
data/README.md
CHANGED
@@ -4,7 +4,7 @@ class CreateUsers < ActiveRecord::Migration
|
|
4
4
|
t.string :name
|
5
5
|
|
6
6
|
# email/password
|
7
|
-
t.string :email
|
7
|
+
t.string :email
|
8
8
|
t.string :password_hash
|
9
9
|
|
10
10
|
# 'remember me' support
|
@@ -17,5 +17,9 @@ class CreateUsers < ActiveRecord::Migration
|
|
17
17
|
|
18
18
|
t.timestamps
|
19
19
|
end
|
20
|
+
|
21
|
+
add_index :users, :email, :unique => true
|
22
|
+
add_index :users, :remember_token
|
23
|
+
add_index :users, :reset_token
|
20
24
|
end
|
21
25
|
end
|
@@ -25,4 +25,8 @@ ActiveRecord::Schema.define(version: 20150107032724) do
|
|
25
25
|
t.datetime "updated_at"
|
26
26
|
end
|
27
27
|
|
28
|
+
add_index "users", ["email"], name: "index_users_on_email", unique: true
|
29
|
+
add_index "users", ["remember_token"], name: "index_users_on_remember_token"
|
30
|
+
add_index "users", ["reset_token"], name: "index_users_on_reset_token"
|
31
|
+
|
28
32
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'mongo_mapper'
|
4
|
+
require 'entrance'
|
5
|
+
|
6
|
+
MongoMapper.connection = Mongo::Connection.new('localhost')
|
7
|
+
MongoMapper.database = 'entrance-example'
|
8
|
+
|
9
|
+
Entrance.configure do |config|
|
10
|
+
config.remember_for = 1.month
|
11
|
+
config.cookie_secure = false # for testing
|
12
|
+
config.access_denied_redirect_to = '/login'
|
13
|
+
end
|
14
|
+
|
15
|
+
class User
|
16
|
+
include MongoMapper::Document
|
17
|
+
|
18
|
+
key :state, :default => 'active'
|
19
|
+
|
20
|
+
key :name
|
21
|
+
key :email, :unique => true
|
22
|
+
key :password_hash
|
23
|
+
|
24
|
+
key :remember_token
|
25
|
+
key :remember_token_expires_at, Time
|
26
|
+
|
27
|
+
key :reset_token
|
28
|
+
key :reset_token_expires_at, Time
|
29
|
+
|
30
|
+
include Entrance::Model # needs to be included after the properties are declared
|
31
|
+
|
32
|
+
def active?
|
33
|
+
state.to_sym == :active
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
%w(./app/models logger sinatra/base sinatra/flash entrance).each { |lib| require lib }
|
2
|
+
|
3
|
+
module Example
|
4
|
+
|
5
|
+
class Routes < Sinatra::Base
|
6
|
+
|
7
|
+
include Entrance::Controller
|
8
|
+
register Sinatra::Flash
|
9
|
+
|
10
|
+
set :sessions, :secret => 'veryverysecretkey'
|
11
|
+
set :views, File.expand_path(File.dirname(__FILE__)) + '/views'
|
12
|
+
|
13
|
+
before do
|
14
|
+
login_required :except => ['/login', '/signup']
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/' do
|
18
|
+
erb :welcome
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/signup' do
|
22
|
+
erb :signup
|
23
|
+
end
|
24
|
+
|
25
|
+
post '/signup' do
|
26
|
+
if @user = User.new(params[:user]) and @user.save
|
27
|
+
flash[:success] = 'Signed up! Please log in now.'
|
28
|
+
redirect to('/login')
|
29
|
+
else
|
30
|
+
flash[:error] = "Something's wrong. Try again."
|
31
|
+
redirect to('/signup')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
get '/login' do
|
36
|
+
if logged_in?
|
37
|
+
redirect(to('/'))
|
38
|
+
else
|
39
|
+
erb :login
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
post '/login' do
|
44
|
+
if user = User.authenticate(params[:email], params[:password]) and user.active?
|
45
|
+
remember = ['on', '1'].include?(params[:remember_me])
|
46
|
+
login!(user, remember)
|
47
|
+
|
48
|
+
flash[:success] = 'Welcome back!'
|
49
|
+
redirect(session[:return_to] || to('/'))
|
50
|
+
else
|
51
|
+
flash[:error] = "Couldn't log you in. Please try again."
|
52
|
+
redirect to('/login')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
get '/logout' do
|
57
|
+
logout!
|
58
|
+
flash[:notice] = 'Logged out! See you soon.'
|
59
|
+
redirect to('/login')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html xml:lang="en" lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
6
|
+
|
7
|
+
<title>Example Entrance App</title>
|
8
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
9
|
+
</head>
|
10
|
+
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<div id="container" class="clearfix">
|
14
|
+
|
15
|
+
<% [:error, :notice, :success].each do |msg| %>
|
16
|
+
<% if flash && flash[msg] %>
|
17
|
+
<%= "<div class='alert alert-#{msg}'>#{flash[msg]}</div>" %>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<%= yield %>
|
22
|
+
|
23
|
+
</div>
|
24
|
+
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h2>Log in</h2>
|
2
|
+
|
3
|
+
<form accept-charset="UTF-8" action="<%= url('/login') %>" method="post">
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<input id="email" name="email" placeholder="Email" tabindex="1" type="email" />
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<input id="password" name="password" placeholder="Password" tabindex="2" type="password" />
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<label for="remember_me">Remember me</label>
|
15
|
+
<input checked="checked" id="remember_me" name="remember_me" type="checkbox" />
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<input class="right btn btn-primary" data-disable-with="Logging in..." name="commit" tabindex="4" type="submit" value="Log in" />
|
19
|
+
|
20
|
+
</form>
|
21
|
+
|
22
|
+
<p>Don't have an account? <a href="<%= url('/signup') %>">Sign up</a>.</p>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h2>Sign up</h2>
|
2
|
+
|
3
|
+
<form accept-charset="UTF-8" action="/signup" class="new_user" method="post">
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<input id="user_name" name="user[name]" placeholder="Your name" tabindex="1" type="text" />
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<input id="user_email" name="user[email]" placeholder="Your email" tabindex="2" type="text" />
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<input id="user_password" name="user[password]" placeholder="Your password" tabindex="3" type="password" />
|
15
|
+
</p>
|
16
|
+
|
17
|
+
<p>
|
18
|
+
<input id="user_password_confirmation" name="user[password_confirmation]" placeholder="Retype password" tabindex="4" type="password" />
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<input class="right btn btn-primary" data-disable-with="Creating account..." name="commit" tabindex="4" type="submit" value="Sign up" />
|
22
|
+
|
23
|
+
</form>
|
24
|
+
|
25
|
+
<p>Have an account? <a href="<%= url('/login') %>">Log in</a></p>
|
data/lib/entrance/controller.rb
CHANGED
@@ -110,7 +110,7 @@ module Entrance
|
|
110
110
|
|
111
111
|
def set_remember_cookie
|
112
112
|
values = {
|
113
|
-
:expires => Entrance.config.remember_for.to_i
|
113
|
+
:expires => Time.now + Entrance.config.remember_for.to_i,
|
114
114
|
:httponly => Entrance.config.cookie_httponly,
|
115
115
|
:path => Entrance.config.cookie_path,
|
116
116
|
:secure => Entrance.config.cookie_secure,
|
data/lib/entrance/model.rb
CHANGED
@@ -89,7 +89,8 @@ module Entrance
|
|
89
89
|
def request_password_reset!
|
90
90
|
send(Entrance.config.reset_token_attr + '=', Entrance.generate_token)
|
91
91
|
if Doorman.config.reset_until_attr
|
92
|
-
|
92
|
+
timestamp = Time.now + Entrance.config.reset_password_window
|
93
|
+
update_attribute(Entrance.config.reset_until_attr, timestamp)
|
93
94
|
end
|
94
95
|
if save(:validate => false)
|
95
96
|
method = Entrance.config.reset_password_method
|
@@ -107,8 +108,8 @@ module Entrance
|
|
107
108
|
end
|
108
109
|
|
109
110
|
def update_remember_token_expiration!(until_date = nil)
|
110
|
-
|
111
|
-
update_attribute(Entrance.config.remember_until_attr,
|
111
|
+
timestamp = Time.now + (until_date || Entrance.config.remember_for).to_i
|
112
|
+
update_attribute(Entrance.config.remember_until_attr, timestamp)
|
112
113
|
end
|
113
114
|
|
114
115
|
def forget_me!
|
data/lib/entrance/version.rb
CHANGED
data/lib/entrance.rb
CHANGED
@@ -3,8 +3,6 @@ require 'entrance/model'
|
|
3
3
|
require 'entrance/ciphers'
|
4
4
|
require 'entrance/config'
|
5
5
|
|
6
|
-
require 'active_support/core_ext/numeric/time'
|
7
|
-
|
8
6
|
module Entrance
|
9
7
|
|
10
8
|
def self.config
|
@@ -21,9 +19,8 @@ module Entrance
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def self.generate_token(length = 40)
|
24
|
-
str =
|
25
|
-
|
26
|
-
str.encode('UTF-8')
|
22
|
+
str = Digest::SHA1.hexdigest([Time.now, rand].join)
|
23
|
+
str[0..(length-1)]
|
27
24
|
end
|
28
25
|
|
29
26
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Tom\xC3\xA1s Pollak"
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- entrance.gemspec
|
60
60
|
- examples/rails-app/.gitignore
|
61
61
|
- examples/rails-app/Gemfile
|
62
|
-
- examples/rails-app/Gemfile.lock
|
63
62
|
- examples/rails-app/README.rdoc
|
64
63
|
- examples/rails-app/Rakefile
|
65
64
|
- examples/rails-app/app/assets/images/.keep
|
@@ -122,6 +121,14 @@ files:
|
|
122
121
|
- examples/rails-app/test/test_helper.rb
|
123
122
|
- examples/rails-app/vendor/assets/javascripts/.keep
|
124
123
|
- examples/rails-app/vendor/assets/stylesheets/.keep
|
124
|
+
- examples/sinatra-app/Gemfile
|
125
|
+
- examples/sinatra-app/app/models.rb
|
126
|
+
- examples/sinatra-app/app/routes.rb
|
127
|
+
- examples/sinatra-app/app/views/layout.erb
|
128
|
+
- examples/sinatra-app/app/views/login.erb
|
129
|
+
- examples/sinatra-app/app/views/signup.erb
|
130
|
+
- examples/sinatra-app/app/views/welcome.erb
|
131
|
+
- examples/sinatra-app/config.ru
|
125
132
|
- lib/entrance.rb
|
126
133
|
- lib/entrance/ciphers.rb
|
127
134
|
- lib/entrance/config.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ./../../
|
3
|
-
specs:
|
4
|
-
entrance (0.2.0)
|
5
|
-
activesupport (>= 3.0)
|
6
|
-
bcrypt (~> 3.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionmailer (4.0.4)
|
12
|
-
actionpack (= 4.0.4)
|
13
|
-
mail (~> 2.5.4)
|
14
|
-
actionpack (4.0.4)
|
15
|
-
activesupport (= 4.0.4)
|
16
|
-
builder (~> 3.1.0)
|
17
|
-
erubis (~> 2.7.0)
|
18
|
-
rack (~> 1.5.2)
|
19
|
-
rack-test (~> 0.6.2)
|
20
|
-
activemodel (4.0.4)
|
21
|
-
activesupport (= 4.0.4)
|
22
|
-
builder (~> 3.1.0)
|
23
|
-
activerecord (4.0.4)
|
24
|
-
activemodel (= 4.0.4)
|
25
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
26
|
-
activesupport (= 4.0.4)
|
27
|
-
arel (~> 4.0.0)
|
28
|
-
activerecord-deprecated_finders (1.0.3)
|
29
|
-
activesupport (4.0.4)
|
30
|
-
i18n (~> 0.6, >= 0.6.9)
|
31
|
-
minitest (~> 4.2)
|
32
|
-
multi_json (~> 1.3)
|
33
|
-
thread_safe (~> 0.1)
|
34
|
-
tzinfo (~> 0.3.37)
|
35
|
-
arel (4.0.2)
|
36
|
-
bcrypt (3.1.9)
|
37
|
-
builder (3.1.4)
|
38
|
-
erubis (2.7.0)
|
39
|
-
hike (1.2.3)
|
40
|
-
i18n (0.7.0)
|
41
|
-
kgio (2.9.1)
|
42
|
-
mail (2.5.4)
|
43
|
-
mime-types (~> 1.16)
|
44
|
-
treetop (~> 1.4.8)
|
45
|
-
mime-types (1.25.1)
|
46
|
-
minitest (4.7.5)
|
47
|
-
multi_json (1.10.1)
|
48
|
-
polyglot (0.3.5)
|
49
|
-
rack (1.5.2)
|
50
|
-
rack-test (0.6.2)
|
51
|
-
rack (>= 1.0)
|
52
|
-
rails (4.0.4)
|
53
|
-
actionmailer (= 4.0.4)
|
54
|
-
actionpack (= 4.0.4)
|
55
|
-
activerecord (= 4.0.4)
|
56
|
-
activesupport (= 4.0.4)
|
57
|
-
bundler (>= 1.3.0, < 2.0)
|
58
|
-
railties (= 4.0.4)
|
59
|
-
sprockets-rails (~> 2.0.0)
|
60
|
-
railties (4.0.4)
|
61
|
-
actionpack (= 4.0.4)
|
62
|
-
activesupport (= 4.0.4)
|
63
|
-
rake (>= 0.8.7)
|
64
|
-
thor (>= 0.18.1, < 2.0)
|
65
|
-
raindrops (0.12.0)
|
66
|
-
rake (10.4.2)
|
67
|
-
sprockets (2.12.3)
|
68
|
-
hike (~> 1.2)
|
69
|
-
multi_json (~> 1.0)
|
70
|
-
rack (~> 1.0)
|
71
|
-
tilt (~> 1.1, != 1.3.0)
|
72
|
-
sprockets-rails (2.0.1)
|
73
|
-
actionpack (>= 3.0)
|
74
|
-
activesupport (>= 3.0)
|
75
|
-
sprockets (~> 2.8)
|
76
|
-
sqlite3 (1.3.10)
|
77
|
-
thor (0.19.1)
|
78
|
-
thread_safe (0.3.4)
|
79
|
-
tilt (1.4.1)
|
80
|
-
treetop (1.4.15)
|
81
|
-
polyglot
|
82
|
-
polyglot (>= 0.3.1)
|
83
|
-
tzinfo (0.3.42)
|
84
|
-
unicorn (4.8.2)
|
85
|
-
kgio (~> 2.6)
|
86
|
-
rack
|
87
|
-
raindrops (~> 0.7)
|
88
|
-
|
89
|
-
PLATFORMS
|
90
|
-
ruby
|
91
|
-
|
92
|
-
DEPENDENCIES
|
93
|
-
entrance!
|
94
|
-
rails (= 4.0.4)
|
95
|
-
sqlite3
|
96
|
-
unicorn
|