Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Devise and Database.com

jeffdonthemic edited this page Jan 7, 2013 · 3 revisions

Setup

Add [cs_api][accounts] field to config.yml file.(See config.example.yml file) Run migration with rake db:migrate Run Rails server and connect.

Account Model

Account model is introduced to wrap all API requests concened with accounts. I referenced cs-api source directly while working.

Examples are

account = Accoune.new(user) # or
account = user.account

account.authenticate(password)
account.create
account.reset_password

Account.find(username)

You can see tests from account_spec.rb file. VCR is awesome!!!

Migration

Added access_token sfdc_username profile_pic accountid attributes to users table.

Integrating Account with devise

This job was not easy. The big principal is 'API call first, and then devise'.

signup

User signing-up occurs with 2 ways, from email authentication and from third-party. For Email authentication added @user.create_account to Users::RegistrationsController, and for third-party authenticaiton added user.create_account to AuthenticationsController.

login

Users::SessionsController is responsible for login. Added authenticate_account filter before create action. If API call success, it updates access_token.

find a user

User account can be searched by Account.find method.

reset/update password####

I rewrote Users::PasswordsController since we did not need to send email notification with devise. With reset API call, reset_password_token(or passcode) is generated and notification email is sent to user by Salesforce.(right?) I assumed that reset password url in notification email sent by Salesforce has rest_password_token and username parameters. So url is something like http://HOSTNAME/resource/password/edit?reset_password_token=abcdef&username=testuser' If this usl is clicked, it shows edit form including rest_password_token and username as hdden field, and they are used to update API.

ApiModel

  • ApiModel.request method is added to handle requests that need authentication.
  • And some refactorings are added.

Clone this wiki locally