ruby on rails - Implicit user creation with Authlogic and Authlogic OAuth plugin -


I am trying to write a simple oyph consumer app in Rail. I am using Authlogic to handle authentication and I am using the Oath Scientific OAuth plugin to do ahath thing.

The Oath Plugin provides some helpful helpers to submit the sign in button: oauth_login_button and oauth_register_button With Authlogic logics and requesting plugins, these two buttons in some way create sessions / users.

What happens next is as follows: - If I use the oauth_login_button assistant, then the session fails to save the object because such a user is not locally - if I use the oauth_register_button assistant So, first, on any login, Rail complains that the token has already been taken ... This means that it can not make a second copy for the same user, which is correct. / P>

The issue is that: I do not want to have both register and login button on my site.

In the user's favor, what I want to achieve, is a button in the beginning, saying smth. Such as "Sign in with Twitter", on which the user has to click to proceed to the inside pages of the site.

On the server side, I want to root the local user account, if the user is for the first time

All samples on Athologic + OAuth I do not seem to care about only one Was able to find a button for sign in: (

Looks like I I'm going to answer the question myself. / P>

I use the following code to generate the sign in button (in HAML):

< Pre = - form_tag ({: controller = & gt; "users" ,: action = & gt; "create"}, {: method => "post"}) do = oauth_register_button: value = & gt; ; "Sign in with Twitter"

and after that I just create the user's session object user method of the controller class, if the user already exists:

< Pre> def can be made @ user = user.NU (perm [[user]) @ user save dot | results | # line if result flash [: notice] = "account registered!" Some_right_path_re_ redirect_to and when Not even @ user.oauth_token.nil? @user = User.find_by_oauth_token (@ user.oauth_token) Unless @ user.nil? UserSession.create (@user) Flash. Now [: message] = "welcome back!" Redirect_to some_inner_path else redirect_back_or_default root_path else else redirect_back_or_default root_path End and End End

If user is the first time the visitor, the user object is successfully saved in line A. And if it is not and an available token is available, then we try to bring the user to DB and log him in.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -