-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add github oauth * bundle lock --add-platform x86_64-linux * fix schema * remove system tests * add another test * amin stuffs * fix Github user name * make redirect to configurable * fix test
- Loading branch information
1 parent
ac9c7e8
commit 7f98bd5
Showing
29 changed files
with
447 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# id :integer | ||
# uid :string | ||
# provider :string | ||
# username :string | ||
# user_id :integer | ||
# access_token :string | ||
# expires_at :datetime | ||
# created_at :datetime | ||
# updated_at :datetime | ||
|
||
class Avo::Resources::ConnectedAccount < Avo::BaseResource | ||
# self.includes = [] | ||
# self.attachments = [] | ||
self.search = { | ||
query: -> { query.ransack(id_eq: params[:q], uid_cont: params[:q], m: "or").result(distinct: false) } | ||
} | ||
|
||
def fields | ||
field :id, as: :id | ||
field :uid, as: :text | ||
field :provider, as: :text, sortable: true | ||
field :username, as: :text, sortable: true | ||
field :user_id, as: :text, sortable: true, hide_on: [:index] | ||
field :access_token, as: :text, hide_on: [:index] | ||
field :expires_at, as: :date_time, hide_on: [:index] | ||
field :created_at, as: :date_time, hide_on: [:index] | ||
field :updated_at, as: :date_time, hide_on: [:index] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This controller has been generated to enable Rails' resource routes. | ||
# More information on https://docs.avohq.io/3.0/controllers.html | ||
class Avo::ConnectedAccountsController < Avo::ResourcesController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Sessions::OmniauthController < ApplicationController | ||
skip_before_action :verify_authenticity_token | ||
skip_before_action :authenticate_user! | ||
|
||
def create | ||
connected_account = ConnectedAccount.find_or_initialize_by(provider: omniauth.provider, uid: omniauth.uid) | ||
|
||
if connected_account.new_record? | ||
@user = User.create_with(user_params).find_or_create_by(email: omniauth.info.email) | ||
connected_account.user = @user | ||
connected_account.access_token = omniauth.credentials&.try(:token) | ||
connected_account.username = omniauth.info&.try(:nickname) | ||
connected_account.save! | ||
else | ||
@user = connected_account.user | ||
end | ||
|
||
if @user.persisted? | ||
session_record = @user.sessions.create! | ||
cookies.signed.permanent[:session_token] = {value: session_record.id, httponly: true} | ||
|
||
redirect_to redirect_to_path, notice: "Signed in successfully" | ||
else | ||
redirect_to sign_in_path, alert: "Authentication failed" | ||
end | ||
end | ||
|
||
def failure | ||
redirect_to sign_in_path, alert: params[:message] | ||
end | ||
|
||
private | ||
|
||
def redirect_to_path | ||
query_params["redirect_to"] || root_path | ||
end | ||
|
||
def user_params | ||
{email: omniauth.info.email, password: SecureRandom.base58, verified: true} | ||
end | ||
|
||
def omniauth_params | ||
{provider: omniauth.provider, uid: omniauth.uid, username: omniauth.info.try(:nickname)}.compact_blank | ||
end | ||
|
||
def omniauth | ||
request.env["omniauth.auth"] | ||
end | ||
|
||
def query_params | ||
request.env["omniauth.params"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# rubocop:disable Layout/LineLength | ||
# == Schema Information | ||
# | ||
# Table name: connected_accounts | ||
# | ||
# id :integer not null, primary key | ||
# uid :string | ||
# provider :string | ||
# username :string | ||
# user_id :integer not null | ||
# access_token :string | ||
# expires_at :datetime | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# rubocop:enable Layout/LineLength | ||
class ConnectedAccount < ApplicationRecord | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
<p style="color: green"><%= notice %></p> | ||
<p style="color: red"><%= alert %></p> | ||
<% redirect_to_path = params.delete(:redirect_to) || root_path %> | ||
|
||
<h1>Sign in</h1> | ||
<div class="flex items-center justify-center py-24 px-4 sm:px-6 lg:px-8"> | ||
<div class="max-w-md w-full space-y-8"> | ||
<div> | ||
<h1 class="mt-6 text-center text-3xl font-semibold text-neutral"> | ||
Sign in to your account | ||
</h1> | ||
</div> | ||
<div class="mt-8 space-y-6"> | ||
<div> | ||
<%= button_to "/auth/github?redirect_to=#{redirect_to_path}", method: :post, data: {turbo: false}, class: "btn w-full btn-neutral" do %> | ||
<%= icon "github", size: :sm, class: "mr-2" %> | ||
Sign in with GitHub | ||
<% end %> | ||
</div> | ||
|
||
<%= form_with(url: sign_in_path) do |form| %> | ||
<div> | ||
<%= form.label :email, style: "display: block" %> | ||
<%= form.email_field :email, value: params[:email_hint], required: true, autofocus: true, autocomplete: "email" %> | ||
<% if Rails.env.development? %> | ||
<div> | ||
<%= button_to "/auth/developer", method: :post, data: {turbo: false}, class: "btn w-full btn-accent" do %> | ||
Sign in with OmniAuth (Development) | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :password, style: "display: block" %> | ||
<%= form.password_field :password, required: true, autocomplete: "current-password" %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit "Sign in" %> | ||
</div> | ||
<% end %> | ||
|
||
<br> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Sign up", sign_up_path %> | | ||
<%= link_to "Forgot your password?", new_identity_password_reset_path %> | ||
</div> |
Oops, something went wrong.