Commit ef9afcda40328c98744069f094244f641079af73
1 parent
2a6a945e
Restores old plugin behavior
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Showing
1 changed file
with
17 additions
and
4 deletions
Show diff stats
plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
| ... | ... | @@ -4,13 +4,13 @@ class OauthClientPluginPublicController < PublicController |
| 4 | 4 | |
| 5 | 5 | def callback |
| 6 | 6 | auth = request.env["omniauth.auth"] |
| 7 | - auth_user = environment.users.where(email: auth.info.email).first | |
| 8 | 7 | |
| 9 | 8 | oauth_params = request.env["omniauth.params"] |
| 10 | 9 | if oauth_params && oauth_params["action"] == "external_login" |
| 11 | - login(auth) | |
| 10 | + external_person_login(auth) | |
| 12 | 11 | else |
| 13 | - signup(auth) | |
| 12 | + auth_user = environment.users.where(email: auth.info.email).first | |
| 13 | + if auth_user then login(auth_user.person) else signup(auth) end | |
| 14 | 14 | end |
| 15 | 15 | end |
| 16 | 16 | |
| ... | ... | @@ -26,7 +26,7 @@ class OauthClientPluginPublicController < PublicController |
| 26 | 26 | |
| 27 | 27 | protected |
| 28 | 28 | |
| 29 | - def login auth | |
| 29 | + def external_person_login(auth) | |
| 30 | 30 | provider = OauthClientPlugin::Provider.find(session[:provider_id]) |
| 31 | 31 | |
| 32 | 32 | if provider.enabled? |
| ... | ... | @@ -62,4 +62,17 @@ class OauthClientPluginPublicController < PublicController |
| 62 | 62 | redirect_to :controller => :account, :action => :signup, :user => {:login => login, :email => auth.info.email}, :profile_data => {:name => name} |
| 63 | 63 | end |
| 64 | 64 | |
| 65 | + def login person | |
| 66 | + provider = OauthClientPlugin::Provider.find(session[:provider_id]) | |
| 67 | + auth = person.oauth_auths.where(provider_id: provider.id).first | |
| 68 | + auth ||= person.oauth_auths.create! profile: person, provider: provider, enabled: true | |
| 69 | + if auth.enabled? && provider.enabled? | |
| 70 | + self.current_user = person.user | |
| 71 | + else | |
| 72 | + session[:notice] = _("Can't login with %s") % provider.name | |
| 73 | + end | |
| 74 | + | |
| 75 | + redirect_to :controller => :account, :action => :login | |
| 76 | + end | |
| 77 | + | |
| 65 | 78 | end | ... | ... |