Class: Crm::Contact

Overview

A JustRelate WebCRM contact represents contact information about a person. It can be associated with an account.

Authentication and password management collapse

Methods included from Crm::Core::Mixins::Findable::ClassMethods

find

Methods included from Crm::Core::Mixins::Modifiable::ClassMethods

create

Methods included from Crm::Core::Mixins::Searchable::ClassMethods

all, first, query, search_configurator, where, where_not

Methods included from Crm::Core::Mixins::Inspectable

#inspect

Methods included from Crm::Core::Mixins::MergeAndDeletable

#merge_and_delete

Methods included from Crm::Core::Mixins::ChangeLoggable

#changes

Methods included from Crm::Core::Mixins::Modifiable

#delete, #update

Methods inherited from Crm::Core::BasicResource

base_type, #eql?, #id, path, #path, #reload, resource_name, #type

Methods included from Crm::Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Class Method Details

.authenticate(login, password) ⇒ Contact?

Authenticates a contact using their login and password.

Examples:

contact = Crm::Contact.authenticate('[email protected]', 'correct')
# => Crm::Contact

contact.
# => '[email protected]'

Crm::Contact.authenticate('[email protected]', 'wrong')
# => nil

Parameters:

  • login (String)

    the login of the contact.

  • password (String)

    the password of the contact.

Returns:

  • (Contact, nil)

    the authenticated contact. nil if authentication failed.



54
55
56
57
58
# File 'lib/crm/contact.rb', line 54

def self.authenticate(, password)
  authenticate!(, password)
rescue Errors::AuthenticationFailed
  nil
end

.authenticate!(login, password) ⇒ Contact

Authenticates a contact using their login and password.

Examples:

contact = Crm::Contact.authenticate!('[email protected]', 'correct')
# => Crm::Contact

contact.
# => '[email protected]'

Crm::Contact.authenticate!('[email protected]', 'wrong')
# => raises AuthenticationFailed

Parameters:

  • login (String)

    the login of the contact.

  • password (String)

    the password of the contact.

Returns:

  • (Contact)

    the authenticated contact.

Raises:



35
36
37
38
# File 'lib/crm/contact.rb', line 35

def self.authenticate!(, password)
  new(Core::RestApi.instance.put("#{path}/authenticate",
      {'login' => , 'password' => password}))
end

.set_password_by_token(new_password, token) ⇒ Contact

Sets a contact’s new password by means of the token. Generate a token by calling #send_password_token_email or #generate_password_token.

Use case: A contact clicks a link (that includes a token) in an email to get to a password change page.

Parameters:

  • new_password (String)

    the new password.

  • token (String)

    the given token.

Returns:

  • (Contact)

    the updated contact.

Raises:



91
92
93
94
95
96
# File 'lib/crm/contact.rb', line 91

def self.set_password_by_token(new_password, token)
  new(Core::RestApi.instance.put("#{path}/set_password_by_token", {
    'password' => new_password,
    'token' => token,
  }))
end

Instance Method Details

#clear_passwordself

Clears the contact’s password.

Returns:

  • (self)

    the updated contact.



101
102
103
# File 'lib/crm/contact.rb', line 101

def clear_password
  load_attributes(Core::RestApi.instance.put("#{path}/clear_password", {}))
end

#generate_password_tokenString

Generates a password token.

Use case: A project sends an email to the contact. The email contains a link to the project web app. The link contains the param ?token=…. The web app retrieves and parses the token and passes it to set_password_by_token.

Returns:

  • (String)

    the generated token.



77
78
79
# File 'lib/crm/contact.rb', line 77

def generate_password_token
  Core::RestApi.instance.post("#{path}/generate_password_token", {})['token']
end

#send_password_token_emailvoid

This method returns an undefined value.

Sends a password token by email to this contact.

Put a link to the project web app into the password_request_email_body template. The link should contain the ?token=… parameter, e.g.:

https://example.com/user/set_password?token={{password_request_token}}

The web app can then pass the token to set_password_by_token.



115
116
117
# File 'lib/crm/contact.rb', line 115

def send_password_token_email
  Core::RestApi.instance.post("#{path}/send_password_token_email", {})
end

#set_password(new_password) ⇒ self

Sets the new password.

Parameters:

  • new_password (String)

    the new password.

Returns:

  • (self)

    the updated contact.



64
65
66
67
# File 'lib/crm/contact.rb', line 64

def set_password(new_password)
  load_attributes(Core::RestApi.instance.put("#{path}/set_password",
      {'password' => new_password}))
end