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, issuer = nil) ⇒ Object



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

def google_authenticator_qrcode(user, qualifier=nil, issuer=nil)
  username = username_from_email(user.email)
  app = user.class.ga_appname || Rails.application.class.parent_name
  data = "otpauth://totp/#{otpauth_user(username, app, qualifier)}?secret=#{user.gauth_secret}"
  data << "&issuer=#{issuer}" if !issuer.nil?
  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



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

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

#username_from_email(email) ⇒ Object



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

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