Archive for October, 2009

A Plataforma Tecnologia começou suas operações há menos de um ano e está em ritmo de crescimento acelerado. \o/

Crescer rapidamente e ao mesmo tempo de forma saudável é um desafio para qualquer empresa, pois é fácil cair na armadilha de hiper-focar no crescimento financeiro quase instantâneo e deixar os valores fundamentais da empresa de lado. Aquelas que deixam isso acontecer, cedo ou tarde, acabam pagando o preço deste crescimento desestruturado e “desvalorizado”. Nós não queremos este tipo de crescimento.

Como temos grande preocupação em preservar o espírito da Plataforma Tecnologia, nós estamos procurando desenvolvedores que compartilhem da nossa cultura “hacker”, que amem seu trabalho e que vejam na atividade de programar não só um trabalho, mas sim, uma atividade de lazer.

Portanto, se você é um geek que curte fazer um trabalho bem feito com código limpo e bonito, por favor assista o vídeo que o Hugo Baraúna e José Valim gravaram. ;)

Ajude a divulgar o vídeo para aqueles que possam se interessar.

Nós estamos esperando o seu currículo, e mais importante, algum código ou contribuição open source que você já tenha feito!

UPDATE 1: Não há restrições quanto a trabalhar remoto.

UPDATE 2: Pessoal, a fluência em klingon é apenas uma brincadeira, e não um requisito! ;)

Valeu galera!

UPDATE: This post was an introduction to Devise and a couple of things changed since then. There is a more recent post which describes the same steps as below using generators and, for a more complete and always updated explanation, please check the README.

In Rails Summit Latin America 2009, we showed Devise in a lightning talk and today we are officially releasing it! Before we show you some code, we are going to explain what we want to achieve with Devise, starting with the most used authentication solution nowadays: Clearance and Authlogic.

Clearance

Clearance is a full stack authentication solution, implementing all Model, View and Controller layers using Rails Engines. It deals with account confirmation and password recovery. You just need to plug and play! However, you are required to use the model User and it does not allow you have add and/or customize different roles.

Authlogic

When comes to the Model, Authlogic is definitely the most complete solution out there. It handles several cryptography providers and many other goodies which are completely configurable. However, it’s not a full stack solution (it does not say how users should confirm their account or recover their password) and it has a little bit of controversy since it handles the session in a model. So here is the question, where the session could be handled then?

Here comes Warden!

Warden is a general rack authentication framework, developed by Daniel Neighman, which handles the session in a rack middleware. The main benefit from it is that you can share your authentication strategies with several apps, so if you are using Sinatra, Rails and some others middlewares at the same time, they all rely on the same rules!

Devise: strategies for authentication

After we fell in love with Warden and used it in some projects, we decided to create a full stack solution as Clearance, but flexible as Authlogic, on top of Warden. The solution is Devise, a Rails Engine which handles multiple roles, each one of them with different strategies. Devise currently comes with 5 strategies:

  • Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in;
  • Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions;
  • Recoverable: takes care of reseting the user password and send reset instructions;
  • Rememberable: generates and clears a token to remember the user from a saved cookie;
  • Validatable: creates all needed validations for email and password. It’s totally optional, so you’re able to to customize validations by yourself.

The nice thing is: imagine that you are building an app which needs to handle invitations. You just need to create a Invitable strategy on Devise and never implement it again!

Show me the code!

In the README, you will find all the information you need to start using Devise in your projects, so here we are going to cover the main aspects of it. Let’s suppose you are creating an user model, which needs to be authenticated and recover his password. The first step is to create the columns using Devise migration helpers:

create_table :users do |t|
  # creates email, encrypted_password and password_salt
  t.authenticatable
 
  # creates reset_password_token
  t.recoverable
end

Then you need to declare inside your model which strategies you want to use:

class User < ActiveRecord::User
  # Authenticatable is always included
  devise :recoverable, :validatable
end

And create the routes:

ActionController::Routing::Routes.draw do |map|
  # Check for configuration params on README
  map.devise_for :users
end

The route will access your model and create only the routes for the strategies declared. That ensures that your user won’t access the confirmations controller inside Devise. Devise also adds a couple of helpers and filters to be used inside your controllers:

  # Inside your protected controller
  before_filter :authenticate_user!
 
  # Inside your controllers and views
  user_signed_in?
  current_user
  user_session

user_session is a hash scoped only to the user. So if you have two roles, they will have different session hashes and their data won’t conflict! This awesome feature come straights from Warden!

Devise also has I18n support and since it’s an engine, you can customize your views just by placing a copy of it in your application. A small application build as example is also available on Github!

What’s more to come?

We are planning to add several other strategies to Devise, including brute force protection, session timeouts and also other features, as generators. You can spy our TODO list whenever you want.

Our many thanks to

Carlos Antônio which worked on Devise and made it ready for prime time! Jonas Nicklas, which introduced us to Warden and Daniel Neighman for building and maintaining it!

We also want to thank Thoughtbot guys, which wrote several decisions and tips they took while developing Clearance which helped us while building Devise.

Finally, thanks to Fábio Akita for giving us the chance to release it at Rails Summit and Gregg Pollack for releasing Devise on Ruby 5!

Pessoal, obrigado por todo feedback no twitter, seguem os meus slides sobre geração de código no Rails 3.0 e Thor:

Além do mais, George Guimarães e Carlos Antonio fizeram o release oficial do Devise, abaixo vocês podem ver a apresentação:

Tanto o Devise, quanto o exemplo usado na apresentação, estão disponíveis no GitHub da Plataforma Tecnologia. Esperamos ver vocês por lá!

A segunda edição do maior evento de Ruby on Rails da América Latina está chegando e nós da Plataforma Tecnologia estamos ansiosos. Serão dois dias para poder conhecer, conversar, discutir e trocar experiências com velhos e novos amigos que esperamos encontrar.

No Rails Summit de 2008, o George Guimarães palestrou sobre as minúncias de monitoração de infra-estrutura e como colocar aplicações Rails em produção.

Este ano será a vez do José Valim falar sobre algumas novidades do Rails 3. Ele vai explicar como adaptar os geradores de código da sua aplicação no Rails 3, falará também sobre o Thor (visto que os geradores de código do Rails 3 são desenvolvidos sobre o Thor) e como utilizá-lo para fazer pequenas tarefas para automatizar o seu dia a dia e binários para os seus plugins/gems em Ruby.

Além da palestra do José Valim, não perca a oportunidade de assistir aos outros grandes palestrantes. Veja a programação completa.  Se você ainda não se inscreveu, corra e não perca esta oportunidade. O Rails Summit é, sem dúvidas, um dos melhores eventos do ano.

Nos vemos lá! ;)

Veja o convite do Fabio Akita no vídeo acima