userbin 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -96
- data/lib/userbin/userbin.rb +8 -0
- data/lib/userbin/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a6270eb20148c6bebb1da458c2a6430ace408da
|
4
|
+
data.tar.gz: 2d901a0419f4604cb4a65e85c6a6b7c74a7e266b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1f7c44451117fed832fc641fcf0116656c43d6ec9639065da58d8173974d48020a89e4c12f7b34dd304325b73e1952fce8b044dead9cd8aabdb17a8330be333
|
7
|
+
data.tar.gz: 02de0cea84a2f0bc8e3830e91754623f44b7e2d4fb0926b0ba90037b8e8b649397e67ea2b8cf5619eb548edb6f99770168243149f8c634cf827ef04763c7bd30
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Userbin for Ruby adds user authentication, login flows and user management to yo
|
|
14
14
|
Installation
|
15
15
|
------------
|
16
16
|
|
17
|
-
1.
|
17
|
+
1. Add the `userbin` gem to your `Gemfile`
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
gem "userbin"
|
@@ -26,7 +26,7 @@ Installation
|
|
26
26
|
bundle install
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
2. Configure the Userbin module with the credentials you got from signing up.
|
30
30
|
|
31
31
|
In a Rails app, put the following code into a new file at `config/initializers/userbin.rb`, and in Sinatra put it in your main application file and add `require "userbin"`.
|
32
32
|
|
@@ -37,35 +37,9 @@ Installation
|
|
37
37
|
end
|
38
38
|
```
|
39
39
|
|
40
|
-
|
40
|
+
If you don't configure the `app_id` and `api_secret`, the Userbin module will read the `USERBIN_APP_ID` and `USERBIN_API_SECRET` environment variables. This may come in handy on Heroku.
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
# will be called when accessing `current_user`
|
46
|
-
config.find_user = -> (userbin_id) do
|
47
|
-
User.find_by_userbin_id(userbin_id)
|
48
|
-
}
|
49
|
-
|
50
|
-
# will be called when a user signs up
|
51
|
-
config.create_user = -> (profile) do
|
52
|
-
User.create! do |user|
|
53
|
-
user.userbin_id = profile.id
|
54
|
-
user.email = profile.email
|
55
|
-
user.photo = profile.image
|
56
|
-
end
|
57
|
-
end
|
58
|
-
```
|
59
|
-
|
60
|
-
*For more information about the available attributes in the profile see the [Userbin profile](https://userbin.com/docs/concepts) documentation.*
|
61
|
-
|
62
|
-
1. Migrate your users (or do it manually if not using Rails) and add a reference to the Userbin profile:
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
rails g migration AddUserbinIdToUsers userbin_id:integer:index
|
66
|
-
```
|
67
|
-
|
68
|
-
1. **Rack/Sinatra apps only**: Activate the Userbin Rack middleware
|
42
|
+
3. **Rack/Sinatra apps only**: Activate the Userbin Rack middleware
|
69
43
|
|
70
44
|
```ruby
|
71
45
|
use Userbin::Authentication
|
@@ -75,98 +49,92 @@ Installation
|
|
75
49
|
Usage
|
76
50
|
-----
|
77
51
|
|
78
|
-
###
|
52
|
+
### Forms
|
79
53
|
|
80
|
-
|
54
|
+
An easy way to integrate Userbin is via the [Widget](https://userbin.com/docs/javascript#widget), which will take care of building forms, validating input and provides a drop-in design that adapts nicely to all devices.
|
81
55
|
|
82
|
-
|
56
|
+
The Widget is fairly high level, so remember that you can still use Userbin with your [own forms](https://userbin.com) if it doesn't fit your use-case.
|
83
57
|
|
84
|
-
|
85
|
-
- if logged_in?
|
86
|
-
= current_user.email
|
87
|
-
- else
|
88
|
-
Not logged in
|
89
|
-
```
|
58
|
+
The following links will open up the Widget with the login or the signup form respectively.
|
90
59
|
|
91
|
-
|
92
|
-
|
60
|
+
```html
|
61
|
+
<a class="ub-login">Log in</a>
|
62
|
+
```
|
93
63
|
|
94
|
-
|
64
|
+
```html
|
65
|
+
<a class="ub-signup">Sign up</a>
|
66
|
+
```
|
95
67
|
|
96
|
-
|
97
|
-
class ArticlesController < ApplicationController
|
98
|
-
before_filter :authenticate_user!
|
68
|
+
The logout link will clear the session and redirect the user back to your root path:
|
99
69
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
70
|
+
```html
|
71
|
+
<a class="ub-logout">Log out</a>
|
104
72
|
```
|
105
73
|
|
106
|
-
|
74
|
+
### The current user
|
107
75
|
|
108
|
-
|
76
|
+
Userbin keeps track of the currently logged in user which can be accessed through the `current_user` property. This automatically taps into libraries such as the authorization solution [CanCan](https://github.com/ryanb/cancan).
|
109
77
|
|
110
|
-
```
|
111
|
-
|
112
|
-
= Userbin.current_user.email
|
113
|
-
- else
|
114
|
-
Not logged in
|
78
|
+
```erb
|
79
|
+
Welcome to your account, <%= current_user.email %>
|
115
80
|
```
|
116
81
|
|
117
|
-
To
|
82
|
+
To check if a user is logged in, use `user_logged_in?` (or its alias `user_signed_in?` if you prefer Devise conventions)
|
118
83
|
|
119
|
-
```
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
84
|
+
```erb
|
85
|
+
<% if user_logged_in? %>
|
86
|
+
You are logged in!
|
87
|
+
<% end %>
|
125
88
|
```
|
126
89
|
|
90
|
+
**Rack/Sinatra apps only**: Since above helpers aren't available outside Rails, instead use `Userbin.current_user` and `Userbin.user_logged_in?`.
|
127
91
|
|
128
|
-
|
92
|
+
Configuration
|
93
|
+
-------------
|
129
94
|
|
130
|
-
|
95
|
+
The `Userbin.configure` block supports a range of options additional to the Userbin credentials. None of the following options are mandatory.
|
131
96
|
|
132
|
-
|
97
|
+
### protected_path
|
133
98
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
99
|
+
By default, Userbin reloads the current page on a successful login. If you set the `protected_path` option, users will be redirected to this path instead.
|
100
|
+
|
101
|
+
Once set, this path and any sub-path of it will be protected from unauthenticated users by instead rendering a login form.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
config.protected_path = '/dashboard'
|
138
105
|
```
|
139
106
|
|
140
|
-
|
107
|
+
### root_path
|
141
108
|
|
142
|
-
|
109
|
+
By default, Userbin reloads the current page on a successful logout. If you set the `root_path` option, users will be redirected to this path instead.
|
143
110
|
|
144
|
-
```
|
145
|
-
|
146
|
-
%a{href: "/account", rel: "twitter"} Connect with Twitter
|
111
|
+
```ruby
|
112
|
+
config.root_path = '/login'
|
147
113
|
```
|
148
114
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
```
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
115
|
+
### create_user and find_user
|
116
|
+
|
117
|
+
By default, `current_user` will reference a *limited* Userbin profile, enabling you to work without a database. If you override the functions `create_user` and `find_user`, the current user will instead reference one of your models. The `profile` object is an *extended* Userbin profile. For more information about the available attributes in the profile see the [Userbin profile](https://userbin.com/docs/concepts) documentation.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
config.create_user = Proc.new { |profile|
|
121
|
+
User.create! do |user|
|
122
|
+
user.userbin_id = profile.id
|
123
|
+
user.email = profile.email
|
124
|
+
user.photo = profile.image
|
125
|
+
end
|
126
|
+
}
|
127
|
+
|
128
|
+
config.find_user = Proc.new { |userbin_id|
|
129
|
+
User.find_by_userbin_id(userbin_id)
|
130
|
+
}
|
165
131
|
```
|
166
132
|
|
133
|
+
You'll need to migrate your users and add a reference to the Userbin profile:
|
167
134
|
|
168
|
-
|
169
|
-
|
135
|
+
```ruby
|
136
|
+
rails g migration AddUserbinIdToUsers userbin_id:integer:index
|
137
|
+
```
|
170
138
|
|
171
139
|
### skip_script_injection
|
172
140
|
|
@@ -177,10 +145,10 @@ config.skip_script_injection = true
|
|
177
145
|
```
|
178
146
|
|
179
147
|
|
180
|
-
|
181
|
-
|
148
|
+
Further configuration and customization
|
149
|
+
---------------------------------------
|
182
150
|
|
183
|
-
Your
|
151
|
+
Your Userbin dashboard gives you access to a range of functionality:
|
184
152
|
|
185
153
|
- Configure the appearance of the login widget to feel more integrated with your service
|
186
154
|
- Connect 10+ OAuth providers like Facebook, Github and Google.
|
data/lib/userbin/userbin.rb
CHANGED
@@ -48,6 +48,10 @@ module Userbin
|
|
48
48
|
current.authenticated? rescue false
|
49
49
|
end
|
50
50
|
|
51
|
+
def self.logged_in?
|
52
|
+
authenticated?
|
53
|
+
end
|
54
|
+
|
51
55
|
def self.user_logged_in?
|
52
56
|
authenticated?
|
53
57
|
end
|
@@ -60,6 +64,10 @@ module Userbin
|
|
60
64
|
current.user if current
|
61
65
|
end
|
62
66
|
|
67
|
+
def self.current_profile
|
68
|
+
_current_user
|
69
|
+
end
|
70
|
+
|
63
71
|
def self.current_user
|
64
72
|
if _current_user
|
65
73
|
if Userbin.config.find_user
|
data/lib/userbin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userbin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan
|
@@ -94,8 +94,9 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
|
97
|
+
description: Drop-in user login for mobile and web apps. Add a full user authentication
|
98
|
+
stack to your application in minutes. Userbin is easily customized to fit your current
|
99
|
+
design and infrastructure.
|
99
100
|
email: johan@userbin.com
|
100
101
|
executables: []
|
101
102
|
extensions: []
|