cheapskate 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/README.md +11 -8
- data/app/controllers/cheapskate/application_controller.rb +13 -13
- data/app/helpers/cheapskate/application_helper.rb +7 -13
- data/lib/cheapskate.rb +13 -11
- data/lib/cheapskate/client.rb +9 -13
- data/lib/cheapskate/client/default.rb +7 -0
- data/lib/cheapskate/version.rb +1 -1
- metadata +9 -9
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef6c244f9a38e352da8495c6bf0536d25e5995bc
|
4
|
+
data.tar.gz: 2244b1698ae888983ede85a9737d6364deb550e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 435e98b5eaf0b0e832c8da619616af2952f66671d78a8895186db85f6529e7251a265e4fa70c8c662ad20b175bea86044d995fb557da5861b20c3e2a27bfbd71
|
7
|
+
data.tar.gz: e2946684506aa93d6a3e3cd0404204aa9a35ac55c46207e2b3b7f20e3d5a8cf492d8de7fc87be9dddbe8ee95b1526f29a5372dc133ebdf3dde406ff0f315d023
|
data/README.md
CHANGED
@@ -29,18 +29,21 @@ The gem provides its own Rails engine, which adds the following to your app:
|
|
29
29
|
|
30
30
|
### Customization
|
31
31
|
|
32
|
-
Both the **/logged_in** and **/registered** routes redirect back to `Cheapskate::ROOT_PATH`,
|
33
|
-
defaults to `"/"`.
|
32
|
+
Both the **/logged_in** and **/registered** routes redirect back to `Cheapskate::CONFIG['ROOT_PATH']`,
|
33
|
+
which defaults to `"/"`.
|
34
34
|
|
35
35
|
Internally much of the logic where the gem hooks into your application is found in the
|
36
|
-
`Cheapskate::Client`
|
36
|
+
`Cheapskate::Client` module. You can include this module and override any of these methods if you
|
37
37
|
want:
|
38
38
|
|
39
|
-
- `create_user(params)`
|
40
|
-
|
39
|
+
- `create_user(params)` - will create user from `params[:user]` with keys `:name` and `:email` (and
|
40
|
+
password w/ confirmation) by default
|
41
|
+
- `find_user(params)` - will look up user by `params[:email]` by default
|
41
42
|
- `authenticate_user(user, params)`
|
42
43
|
- `user_name(user)`
|
43
|
-
- `store_user_in_session(user, session)`
|
44
|
+
- `store_user_in_session(user, session)` - will set `session[:user_id] = user.id` by default
|
45
|
+
- `alert_notice(controller, message)` - uses `flash[:notice]` by default
|
46
|
+
- `alert_error(controller, message)` - uses `flash[:notice]` by default
|
44
47
|
|
45
|
-
If you implement your own client
|
46
|
-
|
48
|
+
If you implement your own client (by defining a class that includes `Cheapskate::Client`),
|
49
|
+
Cheapskate will automatically use your implementation.
|
@@ -14,43 +14,43 @@ module Cheapskate
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def complete_registration
|
17
|
-
alert_and_redirect("Thank you for registering.", Cheapskate::ROOT_PATH)
|
17
|
+
alert_and_redirect("Thank you for registering.", Cheapskate::CONFIG['ROOT_PATH'])
|
18
18
|
end
|
19
19
|
|
20
20
|
def login
|
21
21
|
user = @client.find_user(params)
|
22
22
|
if user.nil?
|
23
|
-
return alert_and_redirect('That user does not exist.', login_path)
|
23
|
+
return alert_and_redirect('That user does not exist.', login_path, :error)
|
24
24
|
end
|
25
25
|
|
26
26
|
if !@client.authenticate_user(user, params)
|
27
|
-
return alert_and_redirect('You have entered an incorrect password.', login_path)
|
27
|
+
return alert_and_redirect('You have entered an incorrect password.', login_path, :error)
|
28
28
|
end
|
29
29
|
|
30
|
-
login =
|
30
|
+
login = SingleUseLogin.create!(:user => user)
|
31
31
|
redirect_to(logged_in_url(url_options_for_protocol(:http).merge(:token => login.token)))
|
32
32
|
end
|
33
33
|
|
34
34
|
def complete_login
|
35
|
-
login =
|
35
|
+
login = SingleUseLogin.find_by_token(params[:token])
|
36
36
|
if login.nil?
|
37
|
-
alert_and_redirect('Unable to verify login. Try again?', login_path)
|
37
|
+
alert_and_redirect('Unable to verify login. Try again?', login_path, :error)
|
38
38
|
end
|
39
39
|
|
40
40
|
user = login.get_user_and_destroy!
|
41
41
|
@client.store_user_in_session(user, session)
|
42
|
-
alert_and_redirect("Welcome, #{@client.user_name(user)}!", Cheapskate::ROOT_PATH)
|
42
|
+
alert_and_redirect("Welcome, #{@client.user_name(user)}!", Cheapskate::CONFIG['ROOT_PATH'])
|
43
43
|
end
|
44
44
|
|
45
45
|
protected
|
46
46
|
|
47
|
-
def alert_and_redirect(message, path)
|
47
|
+
def alert_and_redirect(message, path, alert_type=:notice)
|
48
48
|
uri = URI(path)
|
49
49
|
if uri.absolute? && uri.host != request.host
|
50
|
-
notice =
|
50
|
+
notice = SingleUseNotice.create!(:message => message)
|
51
51
|
uri.query = add_to_query(uri.query, :notice => notice.token)
|
52
52
|
else
|
53
|
-
|
53
|
+
@client.send(:"alert_#{alert_type}", self, message)
|
54
54
|
end
|
55
55
|
|
56
56
|
logger.info("CHEAPSKATE - Redirecting...")
|
@@ -70,13 +70,13 @@ module Cheapskate
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def initialize_client
|
73
|
-
@client = Cheapskate::CLIENT_CLASS.new
|
73
|
+
@client = Cheapskate::CONFIG['CLIENT_CLASS'].new
|
74
74
|
end
|
75
75
|
|
76
76
|
def check_for_notification
|
77
77
|
if params.include?(:notice)
|
78
|
-
@notification =
|
79
|
-
|
78
|
+
@notification = SingleUseNotice.find_by_token(params.delete(:notice))
|
79
|
+
@client.alert_notice(self, @notification.get_message_and_destroy!)
|
80
80
|
|
81
81
|
redirect_to(request.path, params)
|
82
82
|
end
|
@@ -1,19 +1,13 @@
|
|
1
1
|
module Cheapskate
|
2
2
|
module ApplicationHelper
|
3
3
|
def url_options_for_protocol(protocol)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
|
11
|
-
{
|
12
|
-
:protocol => Cheapskate::HTTP_PROTOCOL,
|
13
|
-
:host => Cheapskate::HTTP_HOST,
|
14
|
-
:port => Cheapskate::HTTP_PORT
|
15
|
-
}
|
16
|
-
end
|
4
|
+
prefix = protocol.to_s.upcase
|
5
|
+
|
6
|
+
{
|
7
|
+
:protocol => Cheapskate::CONFIG["#{prefix}_PROTOCOL"],
|
8
|
+
:host => Cheapskate::CONFIG["#{prefix}_HOST"],
|
9
|
+
:port => Cheapskate::CONFIG["#{prefix}_PORT"]
|
10
|
+
}
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
data/lib/cheapskate.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
require "cheapskate/client"
|
2
|
-
require "cheapskate/engine"
|
3
|
-
|
4
1
|
module Cheapskate
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
CONFIG = {
|
3
|
+
'HTTP_PROTOCOL' => 'http',
|
4
|
+
'HTTP_HOST' => Rails.env.development? && 'localhost' || nil,
|
5
|
+
'HTTP_PORT' => Rails.env.development? && 3000 || nil,
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
'HTTPS_PROTOCOL' => Rails.env.development? && 'http' || 'https',
|
8
|
+
'HTTPS_HOST' => Rails.env.development? && 'localhost' || nil,
|
9
|
+
'HTTPS_PORT' => Rails.env.development? && 8000 || nil,
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
'ROOT_PATH' => '/'
|
12
|
+
}
|
15
13
|
end
|
14
|
+
|
15
|
+
require "cheapskate/client"
|
16
|
+
require "cheapskate/client/default"
|
17
|
+
require "cheapskate/engine"
|
data/lib/cheapskate/client.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Cheapskate
|
2
|
-
|
2
|
+
module Client
|
3
|
+
def self.included(client_class)
|
4
|
+
Cheapskate::CONFIG['CLIENT_CLASS'] = client_class
|
5
|
+
end
|
6
|
+
|
3
7
|
def create_user(params)
|
4
8
|
User.create!(params.require(:user).permit(:name, :email, :password, :password_confirmation))
|
5
9
|
end
|
@@ -20,20 +24,12 @@ module Cheapskate
|
|
20
24
|
session[:user_id] = user.id
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_single_use_login(token)
|
28
|
-
SingleUseLogin.find_by_token(token)
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_single_use_notice!(message)
|
32
|
-
SingleUseNotice.create!(:message => message)
|
27
|
+
def alert_notice(controller, message)
|
28
|
+
controller.flash[:notice] = message
|
33
29
|
end
|
34
30
|
|
35
|
-
def
|
36
|
-
|
31
|
+
def alert_error(controller, message)
|
32
|
+
alert_notice(controller, message)
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/cheapskate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheapskate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Tao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -45,19 +45,19 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- app/models/single_use_notice.rb
|
49
|
-
- app/models/single_use_login.rb
|
50
|
-
- app/helpers/cheapskate/application_helper.rb
|
51
48
|
- app/controllers/cheapskate/application_controller.rb
|
49
|
+
- app/helpers/cheapskate/application_helper.rb
|
50
|
+
- app/models/single_use_login.rb
|
51
|
+
- app/models/single_use_notice.rb
|
52
52
|
- config/routes.rb
|
53
53
|
- db/migrate/20130808161902_create_single_use_logins.rb
|
54
54
|
- db/migrate/20130808161920_create_single_use_notices.rb
|
55
|
-
- lib/cheapskate/
|
55
|
+
- lib/cheapskate/client/default.rb
|
56
56
|
- lib/cheapskate/client.rb
|
57
57
|
- lib/cheapskate/engine.rb
|
58
|
-
- lib/
|
58
|
+
- lib/cheapskate/version.rb
|
59
59
|
- lib/cheapskate.rb
|
60
|
-
-
|
60
|
+
- lib/tasks/cheapskate_tasks.rake
|
61
61
|
- Rakefile
|
62
62
|
- README.md
|
63
63
|
homepage: https://github.com/dtao/cheapskate
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.0.
|
83
|
+
rubygems_version: 2.0.5
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Seamlessly jump to a separate domain for HTTPS login and then back
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Dan Tao
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|