Conversation
TODO: add to signin options and add facebook
also test it
Conflicts:
app/assets/stylesheets/app/registrations/new.scss
app/views/registrations/_signup_form.html.haml
app/views/registrations/new.html.haml
config/locales/en/mconf_com.yml
config/locales/pt-br/mconf_com.yml
TODO: finish it (still need the apitokens and routes) and create tests
Social login is disabled if key or secret are missing for authentication methods
This prevents a lot of errors on sign_in due to redirecting to :back
| # otherwise AhoyEmail will change links and break tests | ||
| MCONF_EMAIL_TRACK_CLICKED=false | ||
| MCONF_EMAIL_TRACK_OPENED=true | ||
|
|
There was a problem hiding this comment.
Do we really need configs set for tests? If not you can just remove them from here.
There was a problem hiding this comment.
Yes. We need them so that devise can initialize the omniauth
app/models/user.rb
Outdated
| # define the creation for social omniauth | ||
| def self.from_omniauth(access_token) | ||
| data = access_token.info | ||
| user = User.where(email: data['email']).first |
There was a problem hiding this comment.
User.find_by(email: data['email'])
There was a problem hiding this comment.
Completely forgot I could do that. Fixed.
| @@ -0,0 +1,18 @@ | |||
| #social-login-section | |||
| - if (Rails.application.config.omniauth_google_key.present? && Rails.application.config.omniauth_google_secret.present?) || (Rails.application.config.omniauth_facebook_key.present? && Rails.application.config.omniauth_facebook_secret.present?) | |||
There was a problem hiding this comment.
Done. Looks much better now
.env.development
Outdated
| # Omniauth for google and facebook need API keys. | ||
| # More instructions can be found on https://github.com/omniauth/omniauth/wiki/List-of-Strategies | ||
| # Then add the following: | ||
| # MCONF_OMNIAUTH_GOOGLE_KEY = 'yourgooglekey' |
There was a problem hiding this comment.
Usually env vars are defined without using spaces around the =.
config/locales/en/mconf.yml
Outdated
| register: "Create a new account" | ||
| resend_confirmation_email: "Resend confirmation email" | ||
| social_login: | ||
| social_facebook: "Login with Facebook Account" |
config/locales/en/mconf.yml
Outdated
| resend_confirmation_email: "Resend confirmation email" | ||
| social_login: | ||
| social_facebook: "Login with Facebook Account" | ||
| social_google: "Login with Google Account" |
config/locales/pt-br/mconf.yml
Outdated
| register: "Criar uma nova conta" | ||
| resend_confirmation_email: "Reenviar e-mail de confirmação" | ||
| social_login: | ||
| social_facebook: "Acessar com a conta Facebook" |
config/locales/pt-br/mconf.yml
Outdated
| resend_confirmation_email: "Reenviar e-mail de confirmação" | ||
| social_login: | ||
| social_facebook: "Acessar com a conta Facebook" | ||
| social_google: "Acessar com a conta Google" |
| def self.from_omniauth(access_token) | ||
| data = access_token.info | ||
| user = User.where(email: data['email']).first | ||
| user = User.find_by_email(data['email']) |
There was a problem hiding this comment.
This is an old syntax, it's better to use find_by(email: data['email']).
| @@ -1,15 +1,16 @@ | |||
| #social-login-section | |||
| - if (Rails.application.config.omniauth_google_key.present? && Rails.application.config.omniauth_google_secret.present?) || (Rails.application.config.omniauth_facebook_key.present? && Rails.application.config.omniauth_facebook_secret.present?) | |||
| - if Site.current.social_login_enabled? | |||
There was a problem hiding this comment.
We have a current_site helper that caches the site, it's usually better to use it in views.

Adding Facebook and Google authentication Login to Mconf login