Class: Devise::Strategies::Meteor

Inherits:
Authenticatable
  • Object
show all
Defined in:
lib/devise/strategies/meteor.rb,
lib/devise_meteor/strategies/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/devise/strategies/meteor.rb', line 11

def authenticate!
  self.password = params_auth_hash[:password]

  # search for user email
  devise_resource = valid_for_params_auth? && mapping.to.find_for_database_authentication(authentication_hash)
  meteor_resource = User.where(:emails.elem_match => {address: params_auth_hash[:email]}).first unless devise_resource
  resource = devise_resource || meteor_resource

  return fail!(:not_found_in_database) unless resource

  # before continuing authentication process
  # check existing passwords and synchronize them
  if meteor_auth_missing?(resource)
    # when already devise credentials stored
    # assign them to devise_meteor fields
    new_hashed_password = User.new(:password => password).encrypted_password
    resource.services.set(password: {bcrypt: new_hashed_password})

  elsif devise_auth_missing?(resource)
    # when user registered through devise_meteor
    # and credentials for devise not present
    email = params_auth_hash[:email]
    crypt = resource.services.password[:bcrypt]

    unless resource.update_attributes(encrypted_password: crypt, email: email)
      fail(resource.unauthenticated_message)
    end
    resource.reload

  elsif both_auth_present?(resource)
    #when both passwords already set
  else
    return pass
  end

  # now do validation
  # this code is copied from Devise::Strategies::DatabaseAuthenticable
  encrypted = false
  if validate(resource) { encrypted = true; resource.valid_password?(password) }
    remember_me(resource)
    resource.after_database_authentication
    success!(resource)
  end

  mapping.to.new.password = password if !encrypted && Devise.paranoid
  fail(:not_found_in_database) unless resource
end

#valid?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/devise/strategies/meteor.rb', line 7

def valid?
  valid_for_params_auth? || valid_for_http_auth?
end