Skip to content

Commit

Permalink
Admin panel now shows last login and time logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Sosinski committed Jul 24, 2008
1 parent facb4f6 commit 88c665e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 53 deletions.
10 changes: 7 additions & 3 deletions app/views/accounts/index.html.erb
Expand Up @@ -4,16 +4,20 @@

<tr>
<th>Email Address</th>
<th width="200px">Created</th>
<th width="100px">Activated?</th>
<th width="100px">Banned?</th>
<th width="175px">Created</th>
<th width="175px">Last Login</th>
<th width="75px">Logins</th>
<th width="75px">Activated?</th>
<th width="75px">Banned?</th>
</tr>

<% for account in @accounts %>

<tr id="account_<%= account.id %>">
<td><%= link_to account.email_address, edit_account_path(account) %>
<td><%= account.created_at.to_s(:standard) %></td>
<td><%= account.logins.empty? ? "None Yet" : account.logins.last.created_at.to_s(:standard) %></td>
<td><%= account.logins.size %></td>

<td>
<span id="activate_account_<%= account.id %>" <%= 'style="display: none;"' if account.activated? %>>
Expand Down
100 changes: 50 additions & 50 deletions doc/README_FOR_APP
@@ -1,17 +1,17 @@
=Summery
= Summary

Capansis Authentication is web service that allows you to easily implement a very secure and robust authentication system into your
application. It provides a fully RESTful API using XML over HTTP and is secured using HTTP Basic Authentication. This document describes
how to interact with the Capansis Authentication service using cURL and ActiveRecord.

Throughout this document, you will see code examples. There will always be two, first a cURL example, followed by an ActiveResource example.

How to interact with Capansis Authentication using cURL
How to interact with Capansis Authentication using cURL

How to interact with Capansis Authentication using ActiveResource
How to interact with Capansis Authentication using ActiveResource


=Site Domain and API Key
= Site Domain and API Key

In order to incorporate Capansis Authentication into your application, you will first need a valid domain and API key, such as:

Expand All @@ -22,13 +22,13 @@ API Key: c144dccfa6d57711185083fb0336dcfa9b33ac61
These credentials can then be used as a username and password with HTTP Basic Authentication to interface your application with the
authentication service.

http(s)://capansis.com:c144dccfa6d57711185083fb0336dcfa9b33ac61@authentication.capansis.net
http(s)://capansis.com:c144dccfa6d57711185083fb0336dcfa9b33ac61@authentication.capansis.net

self.site = "authentication.capansis.net"
self.user = "capansis.com"
self.password = "c144dccfa6d57711185083fb0336dcfa9b33ac61"
self.site = "http(s)://authentication.capansis.net"
self.user = "capansis.com"
self.password = "c144dccfa6d57711185083fb0336dcfa9b33ac61"

=Making Requests
= Making Requests

Requests to the authentication service are made via URLs and HTTP verbs. The URL represents a resource within the authentication service
(e.g. an account), while the HTTP verb describes method to interact with it (e.g. retrieve, add, change or delete). There are four
Expand All @@ -44,50 +44,50 @@ different verbs you can use to interact with the authentication service.

These methods are used to interact with two objects via the API.

==Account
== Account

Represents the account for a user. An account contains the users email address and encrypted password.

==Login
== Login

Represents the authenticated session for a user. A login contains the time and date that a user successfully authenticated via the service.

=Accounts
= Accounts

There are seven ways to interact with the Account resource API.

==Getting a Collection of Accounts
== Getting a Collection of Accounts

To get a full collection of all accounts, pass a GET request to the Accounts resource.

curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts.xml
curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts.xml

Account.find(:all)
Account.find(:all)

You can also filter the collection by the first letter in an accounts email address by passing the letter parameter.

curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts.xml?letter=a
curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts.xml?letter=a

Account.find(:all, :params => {:letter => "a"})
Account.find(:all, :params => {:letter => "a"})

==Getting a Single Account
== Getting a Single Account

To get a single account, pass a GET request to an Accounts resource member.

curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts/12345.xml
curl -X GET -i -u domain:api_key http(s)://authentication.capansis.com/accounts/12345.xml

Account.find(12345)
Account.find(12345)

==Creating a New Account
== Creating a New Account

To create a new account, pass a POST request to the Accounts resource with properly formated account data.

curl -X POST -i -u domain:api_key -d \
"account[email_address]=name@domain.com&account[password]=password&account[password_confirmation]=password" \
http(s)://authentication.capansis.com/accounts.xml
curl -X POST -i -u domain:api_key \
-d "account[email_address]=name@domain.com&account[password]=password&account[password_confirmation]=password" \
http(s)://authentication.capansis.com/accounts.xml

@account = Account.new(params[:account])
@account.save
@account = Account.new(params[:account])
@account.save

If the new account can be created, the authentication service will return the XML representation of the account.

Expand All @@ -99,14 +99,14 @@ include a verification link, that once clicked, will activate the account and lo

NOTE: Users will not be able to login through the authentication service until their account is activated.

==Verifying an Accounts Email Address
== Verifying an Accounts Email Address

To activate or recover an account, pass a PUT request to an Accounts resource member with a verification key.

curl -X PUT -i -u domain:api_key http(s)://localhost:3001/accounts/842437485.xml?verification_key=6a57a7d7430418b3fb579c9c7558ec2719aa9edb37b6940a381d72af16c3619e
curl -X PUT -i -u domain:api_key http(s)://localhost:3001/accounts/842437485.xml?verification_key=6a57a7d7430418b3fb579c9c7558ec2719aa9edb37b6940a381d72af16c3619e

@account = Account.find(12345)
@account.put(:verify, :verification_key => "6a57a7d7430418b3fb579c9c7558ec2719aa9edb37b6940a381d72af16c3619e")
@account = Account.find(12345)
@account.put(:verify, :verification_key => "6a57a7d7430418b3fb579c9c7558ec2719aa9edb37b6940a381d72af16c3619e")

If the account and verification key are valid, the authentication service will return a HTTP 200 OK. Otherwise, it will return a
HTTP 404 Not Found.
Expand All @@ -116,50 +116,50 @@ HTTP 404 Not Found.
You can check if the Account is being activated or recovered by checking the activated attribute. This is helpful if you want
activating users to be redirected to a "Home" page, while recovering users to be redirected to a "Change Password" page.

# Example using ActiveResource

# If the verification is for an activation
@account.activated? => false
# If the verification is for a recovery
@account.activated? => true
# Example using ActiveResource
# If the verification is for an activation
@account.activated? => false
# If the verification is for a recovery
@account.activated? => true

==Updating an Existing Account
== Updating an Existing Account

To update account, pass a PUT request to an Accounts resource member with properly formatted account data.

curl -X PUT -i -u domain:api_key \
-d "account[email_address]=name@domain.com&account[password]=password&account[password_confirmation]=password" \
http(s)://authentication.capansis.com/12345/accounts.xml
curl -X PUT -i -u domain:api_key \
-d "account[email_address]=name@domain.com&account[password]=password&account[password_confirmation]=password" \
http(s)://authentication.capansis.com/12345/accounts.xml

@account = Account.find(12345).load(params[:account])
@account.save
@account = Account.find(12345).load(params[:account])
@account.save

If the account can be updated, the authentication service will return the XML representation of the account.

If the account cannot be updated, the authentication service will return an HTTP 422 Unprocessable Entity code and an XML
representation of the errors.

==Recovering an Existing Account
== Recovering an Existing Account

To have a recovery letter with verification link sent to an account owners email address of record, pass a POST request to the Accounts
resource with an email address.

curl -X POST -i -u domain:api_key -d "email_address=name@domain.com" http(s)://localhost:3001/accounts/recover.xml
curl -X POST -i -u domain:api_key -d "email_address=name@domain.com" http(s)://localhost:3001/accounts/recover.xml

Account.post(:recover, :email_address => name@domain.com)
Account.post(:recover, :email_address => name@domain.com)

If the account can be found, the authentication service will send an email to the address on record, thus allowing the account owner to
login via the verify action.

=Logins
= Logins

There is one way to interact with the Account resource API.

==Creating a new Login
== Creating a new Login

To verify an accounts credentials and create a new Login, pass a POST request to the Logins resource with properly formated login data.

curl -X POST -i -u domain.com:api_key -d "login[email_address]=name@domain.com&login[password]=secret" http(s)://localhost:3001/logins.xml
curl -X POST -i -u domain.com:api_key -d "login[email_address]=name@domain.com&login[password]=secret" http(s)://localhost:3001/logins.xml

@login = Login.new(params[:login])
@login.save
@login = Login.new(params[:login])
@login.save
3 changes: 3 additions & 0 deletions spec/fixtures/logins.yml
@@ -0,0 +1,3 @@
login_for_alice:
account: alice
created_at: <%= Time.now %>

0 comments on commit 88c665e

Please sign in to comment.