mirror of https://github.com/docusealco/docuseal
parent
f7ef99a624
commit
6f3fe1dd7b
@ -0,0 +1,16 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
|
def google_oauth2
|
||||||
|
@user = Users.from_omniauth(request.env['omniauth.auth'])
|
||||||
|
|
||||||
|
if @user.persisted?
|
||||||
|
flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: 'Google')
|
||||||
|
|
||||||
|
sign_in_and_redirect @user, event: :authentication
|
||||||
|
else
|
||||||
|
redirect_to new_registration_path(oauth_callback: true, user: @user.slice(:email, :first_name, :last_name)),
|
||||||
|
notice: 'Please complete registration with Google auth'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SessionsController < Devise::SessionsController
|
||||||
|
def create
|
||||||
|
if Docuseal.multitenant? && !User.exists?(email: sign_in_params[:email])
|
||||||
|
return redirect_to new_registration_path(sign_up: true, user: sign_in_params.slice(:email)),
|
||||||
|
notice: 'Create a new account'
|
||||||
|
end
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
<div class="max-w-xl mx-auto px-2">
|
||||||
|
<h1 class="text-4xl font-bold text-center my-8">Sign up</h1>
|
||||||
|
<%= form_for(User.new, html: { class: 'space-y-6' }, url: new_registration_path, method: :get) do |f| %>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<div class="form-control">
|
||||||
|
<%= f.label :email, class: 'label' %>
|
||||||
|
<%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'base-input' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<%= f.button button_title(title: 'Sign up', disabled_with: 'Sign up'), name: 'sign_up', value: true, class: 'base-button' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if devise_mapping.omniauthable? %>
|
||||||
|
<%= button_to button_title(title: 'Sign up with Google', icon: svg_icon('brand_google', class: 'w-6 h-6')), omniauth_authorize_path(resource_name, :google_oauth2), class: 'white-button w-full mt-4', data: { turbo: false }, method: :post %>
|
||||||
|
<% end %>
|
||||||
|
<%= render 'devise/shared/links' %>
|
||||||
|
</div>
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Users
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def from_omniauth(oauth)
|
||||||
|
user = User.find_by(email: oauth.info.email)
|
||||||
|
|
||||||
|
return user if user
|
||||||
|
|
||||||
|
User.new(email: oauth.info.email,
|
||||||
|
first_name: oauth.extra.id_info.given_name,
|
||||||
|
last_name: oauth.extra.id_info.family_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in new issue