Class: DeviseTokenAuth::ConfirmationsController

Inherits:
Devise::ConfirmationsController
  • Object
show all
Includes:
Devise::Controllers::Helpers
Defined in:
app/controllers/devise_token_auth/confirmations_controller.rb

Instance Method Summary collapse

Instance Method Details

#generate_url(url, params = {}) ⇒ Object



30
31
32
33
34
# File 'app/controllers/devise_token_auth/confirmations_controller.rb', line 30

def generate_url(url, params = {})
  uri = URI(url)
  uri.query = params.to_query
  uri.to_s
end

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/devise_token_auth/confirmations_controller.rb', line 5

def show
  @user = User.confirm_by_token(params[:confirmation_token])

  if @user.id
    # create client id
    client_id  = SecureRandom.urlsafe_base64(nil, false)
    token      = SecureRandom.urlsafe_base64(nil, false)
    token_hash = BCrypt::Password.create(token)
    @user.tokens[client_id] = {
      token:  token_hash,
      expiry: Time.now + 2.weeks
    }

    @user.save!

    redirect_to generate_url(@user.confirm_success_url, {
      token:     token,
      client_id: client_id,
      uid:       @user.uid
    })
  else
    raise ActionController::RoutingError.new('Not Found')
  end
end