Module: DeviseGoogleAuthenticator::Controllers::Helpers

Defined in:
lib/devise_google_authenticatable/controllers/helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#google_authenticator_qrcode(user, qualifier = nil) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/devise_google_authenticatable/controllers/helpers.rb', line 4

def google_authenticator_qrcode(user,qualifier=nil)
  username = username_from_email(user.email)
  app = Rails.application.class.parent_name
  data = "otpauth://totp/#{otpauth_user(username, app, qualifier)}?secret=#{user.gauth_secret}"
  data = Rack::Utils.escape(data)
  url = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=#{data}"
  return image_tag(url, :alt => 'Google Authenticator QRCode')
end

#otpauth_user(username, app, qualifier = nil) ⇒ Object



13
14
15
# File 'lib/devise_google_authenticatable/controllers/helpers.rb', line 13

def otpauth_user(username, app, qualifier=nil)
  "#{username}@#{app}#{qualifier}"
end

#username_from_email(email) ⇒ Object



17
18
19
# File 'lib/devise_google_authenticatable/controllers/helpers.rb', line 17

def username_from_email(email)
  (/^(.*)@/).match(email)[1]
end