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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cca8bc4a6426e0d967af3cc4746ff35f0ec24d43
4
- data.tar.gz: 70f0ad7d7a4b46f9603aee952b7451be197c0eba
3
+ metadata.gz: 7a6270eb20148c6bebb1da458c2a6430ace408da
4
+ data.tar.gz: 2d901a0419f4604cb4a65e85c6a6b7c74a7e266b
5
5
  SHA512:
6
- metadata.gz: 55cfd4067825ff8db777b0d188c95f7a631a12d201b335503c037ca2c50e25c9f923c41f4d8b3e1cc5532802b473aa161340d3029980fa6f05501a0c06fc7e14
7
- data.tar.gz: 46d8f465f92b40b9c606a844850fadee936fc131c70717a5e74693de617d9267b40c4e4fd28426f590a869316d2c941f572008f28e8b0b9f00cc4063c322d498
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. Add the `userbin` gem to your `Gemfile`
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
- 1. Configure the Userbin module with the credentials you got from signing up.
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
- *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.*
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
- 1. Implement getter and setter for your user model.
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
- ### Authenticating
52
+ ### Forms
79
53
 
80
- #### Rails
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
- Userbin keeps track of the currently logged in user which can be accessed through `current_user` in controllers, views, and helpers. This automatically taps into libraries such as the authorization solution [CanCan](https://github.com/ryanb/cancan).
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
- ```haml
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
- <!-- **Rack/Sinatra apps only**: Since above helpers aren't available outside Rails, instead use `Userbin.current_user` and `Userbin.logged_in?`.
92
- -->
60
+ ```html
61
+ <a class="ub-login">Log in</a>
62
+ ```
93
63
 
94
- To set up a controller with user authentication, just add this before_filter:
64
+ ```html
65
+ <a class="ub-signup">Sign up</a>
66
+ ```
95
67
 
96
- ```ruby
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
- def index
101
- current_user.articles
102
- end
103
- end
70
+ ```html
71
+ <a class="ub-logout">Log out</a>
104
72
  ```
105
73
 
106
- #### Sinatra
74
+ ### The current user
107
75
 
108
- Helpers are accessed through the global Userbin object:
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
- ```haml
111
- - if Userbin.logged_in?
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 set up routes with user authentication, just wrap them like this:
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
- ```ruby
120
- authenticate_user do
121
- get "/articles" do
122
- "Restricted page that logged in users can access"
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
- ### Forms
92
+ Configuration
93
+ -------------
129
94
 
130
- #### Ready-made forms
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
- These are opened in a popup.
97
+ ### protected_path
133
98
 
134
- ```haml
135
- %a{href: "/account", rel: "login"} Log in
136
- %a{href: "/account", rel: "signup"} Sign up
137
- %a{href: "/", rel: 'logout'} Log out
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
- #### Social buttons
107
+ ### root_path
141
108
 
142
- These require you to first configure your social apps in the dashboard.
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
- ```haml
145
- %a{href: "/account", rel: "facebook"} Connect with Facebook
146
- %a{href: "/account", rel: "twitter"} Connect with Twitter
111
+ ```ruby
112
+ config.root_path = '/login'
147
113
  ```
148
114
 
149
- #### Custom forms
150
-
151
- Only
152
-
153
- ```haml
154
- %form{action: "/account", name: "signup"}
155
- %span.errors
156
- .form-row
157
- %label
158
- %span E-mail
159
- %input{name: "email", type: "text"}
160
- .form-row
161
- %label
162
- %span Password
163
- %input{name: "password", type: "password"}
164
- %button{type: "submit"} Sign up
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
- Further configuration
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
- Admin dashboard
181
- ---------------
148
+ Further configuration and customization
149
+ ---------------------------------------
182
150
 
183
- Your [dashboard](https://userbin.com/dashboard) gives you access to a range of functionality:
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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Userbin
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
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
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: Plug n' play user accounts. The simplest way to integrate a full authentication
98
- and user management stack into your web application.
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: []