add users controller and intermediate username step

This commit is contained in:
Zachary Chai
2016-10-19 11:47:37 -04:00
parent d26d4a86bd
commit 015dd7cda4
10 changed files with 95 additions and 8 deletions

View File

@ -1,10 +1,13 @@
class User < ApplicationRecord
validates :username, uniqueness: true
def self.from_omniauth(auth_hash)
user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil
user.name = auth_hash['info']['name']
user.save!
user = find_or_initialize_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
unless user.persisted?
# user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil
user.name = auth_hash['info']['name']
end
user
end