Module: Google::OpenId

Defined in:
lib/TheresNoBox/google.rb

Class Method Summary collapse

Class Method Details

.headerObject



85
86
87
88
89
90
91
# File 'lib/TheresNoBox/google.rb', line 85

def self.header
  return {:identifier => 'https://www.google.com/accounts/o8/id',
          :required => ["http://axschema.org/contact/email",
                      "http://axschema.org/namePerson/first",
                      "http://axschema.org/namePerson/last"],
          :method => 'post'}
end

.login(resp) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/TheresNoBox/google.rb', line 67

def self.(resp)
  ax = OpenID::AX::FetchResponse.from_success_response(resp)
  email =  ax.get_single("http://axschema.org/contact/email")
  user = User.where(:email => email).first
  if user.nil?
    user = User.create()
    user.email = email.downcase
    user.provider = 'Google'
    user.name = ax.get_single("http://axschema.org/namePerson/first") << ' ' << ax.get_single("http://axschema.org/namePerson/last")
    user.save
  end

  unless user.provider = 'Google'
    raise 'User email already in use.'
  end
  return user
end