Module: UserAuth::Web::Helpers

Defined in:
lib/user_auth/web/helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_jwt(data) ⇒ Object



33
34
35
36
# File 'lib/user_auth/web/helpers.rb', line 33

def build_jwt(data)
  exp = Time.now.to_i + UserAuth.configuration.jwt_exp
  Token.new.create(data.merge(exp: exp))
end

#current_userObject



8
9
10
# File 'lib/user_auth/web/helpers.rb', line 8

def current_user
  @current_user ||= UserAuth::Models::User.with_pk!(warden.user.user_id)
end

#deliver_email(options) ⇒ Object



16
17
18
# File 'lib/user_auth/web/helpers.rb', line 16

def deliver_email(options)
  UserAuth.configuration.deliver_mail.call(options)
end

#json(data) ⇒ Object



20
21
22
23
# File 'lib/user_auth/web/helpers.rb', line 20

def json(data)
  content_type(:json)
  JSON.dump(data)
end

#json_user_token(user) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/user_auth/web/helpers.rb', line 25

def json_user_token(user)
  json(
    token_type: "Bearer",
    token: build_jwt(user.to_json),
    refresh_token: user.refresh_token!
  )
end

#paramsObject



12
13
14
# File 'lib/user_auth/web/helpers.rb', line 12

def params
  super.symbolize_keys.with_indifferent_access
end

#wardenObject



4
5
6
# File 'lib/user_auth/web/helpers.rb', line 4

def warden
  env["warden"]
end