Skip to content

Commit

Permalink
Oauth fixes (#869)
Browse files Browse the repository at this point in the history
* Oauth fixes

* Lint
  • Loading branch information
wilco375 authored May 7, 2023
1 parent 9442b2f commit 7a21a97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class User < ApplicationRecord
class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
devise :omniauthable, omniauth_providers: [:amber_oauth2]
has_many :orders, dependent: :destroy
has_many :order_rows, through: :orders, dependent: :destroy
Expand Down Expand Up @@ -84,11 +84,17 @@ def archive!

# TODO: Spec this method
# :nocov:
def self.from_omniauth(auth)
def self.from_omniauth(auth) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
user = where(provider: auth.provider, uid: auth.uid).first_or_create do |u|
u.name = auth[:info][:name]
end
user.update_role(auth[:info][:groups])
user.update(
name: auth[:info][:name],
email: auth[:info][:email],
avatar_thumb_url: auth[:info][:avatar_thumb_url],
birthday: auth[:info][:birthday]
)
user
end

Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20170922175055_add_user_model.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class AddUserModel < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :username, null: false

t.datetime :deleted_at
t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions lib/omniauth/strategies/amber_oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def authorize_params
info do
{
uid: raw_info['id'],
username: raw_info['attributes']['username'],
name: full_name(raw_info),
avatar_url: raw_info['attributes']['avatar_url'],
email: raw_info['attributes']['email'],
avatar_thumb_url: raw_info['attributes']['avatar_thumb_url'],
birthday: raw_info['attributes']['birthday'],
groups: groups_from_json(raw_info['relationships']['active_groups']['data'])
}
end
Expand Down

0 comments on commit 7a21a97

Please sign in to comment.