<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>restful-authentication &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/restful-authentication/</link>
	<description>Feed of posts on WordPress.com tagged "restful-authentication"</description>
	<pubDate>Sun, 26 May 2013 01:05:12 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Administrating restful-authentication users with ActiveScaffold]]></title>
<link>http://mtjhax.wordpress.com/2010/01/16/administrating-restful-authentication-users-with-activescaffold/</link>
<pubDate>Sat, 16 Jan 2010 21:51:42 +0000</pubDate>
<dc:creator>mtjhax</dc:creator>
<guid>http://mtjhax.wordpress.com/2010/01/16/administrating-restful-authentication-users-with-activescaffold/</guid>
<description><![CDATA[Needing a quick set of admin pages for a site that uses Restful-authentication, I decided to use one]]></description>
<content:encoded><![CDATA[<p style="text-align:justify;">Needing a quick set of admin pages for a site that uses <a href="http://github.com/technoweenie/restful-authentication">Restful-authentication</a>, I decided to use one of the many nifty scaffolding tools for Ruby on Rails to generate some customizable views. I settled on <a href="http://activescaffold.com/">ActiveScaffold</a> for reasons I will mention later.</p>
<p style="text-align:justify;">The normal way you use ActiveScaffold is to simply add an &#8216;active_scaffold&#8217; declaration to your controller that causes views to be dynamically generated. For example:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
class UsersController &#60; ApplicationController
  active_scaffold
end</pre>
<p style="text-align:justify;">The problem is that this code adds actions such as show, list, and create to your controller that are almost certainly already in use by your user-facing web site. The obvious answer is to create a separate controller and configure ActiveScaffold to  specify which model to use. Easy enough, but there are a couple useful tricks worth considering.</p>
<p><strong>Why ActiveScaffold?</strong></p>
<p style="text-align:justify;">ActiveScaffold caught my eye for a number of reasons including the fact that their main page has links directly to their competition in case &#8220;ActiveScaffold isn&#8217;t what you&#8217;re looking for&#8221;. I&#8217;m not sure if that&#8217;s a friendly open-source attitude or a bit of a boast&#8211;maybe a little of both&#8211;it&#8217;s all good either way. <a href="http://hobocentral.net/">Hobo</a> and <a href="http://streamlinedframework.org/">Streamlined</a> both looked really cool but were a bigger investment in learning curve than I cared to make that afternoon. Lightweight is always good when patching stuff on to an existing site and refactoring isn&#8217;t in the budget.</p>
<p style="text-align:justify;">An interesting feature of ActiveScaffold is that the views are dynamically generated and customized through configuration options, helpers, and CSS (as opposed to code being emitted and then customized directly). There seems to be a minor movement in some Rails circles away from code generators towards configurable, customizable plugins/gems. Another example is <a href="http://github.com/binarylogic/authlogic">authlogic</a>, the hot new flavor for user authentication in Rails. This all seems a little contrary to Rails doctrine (convention over configuration) but the configuration is lightweight and it reduces the amount of cruft I have to add to my code that is tangential to my application&#8217;s purpose. For a plugin that makes a ton of sense.</p>
<p><strong>Approaches<br />
</strong></p>
<p style="text-align:justify;"><a href="http://stackoverflow.com/questions/107674/backend-administration-in-rails">One interesting approach</a> to make a user admin interface is to use the map.namespace feature in routes.rb. With this you can create restful routes such as /admin_users, /new_admin_users, /delete_admin_users, etc. Something like this:</p>
<pre class="brush: ruby; title: ; notranslate" title="">map.namespace :admin do &#124;admin&#124;
    admin.resources :users
end</pre>
<p style="text-align:justify;">Then you can create new admin controllers and views in app/controllers/admin, app/views/admin/users, etc. This is a great pattern but it&#8217;s a little tricky to implement with something like ActiveScaffold that is automatically generating your views.</p>
<p style="text-align:justify;">The simpler approach with ActiveScaffold is to simply create a new controller, say AdminUsersController, and specify the model name in your active_scaffold configuration:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
active_scaffold :&#60;your_model_name&#62;</pre>
<p style="text-align:justify;">There&#8217;s only one hitch. Everyone in Rails these days is pushing the &#8220;thin controller, fat model&#8221; doctrine. What happens when you need special logic only available to administrators? Obviously you can add to your controller, but you might not be able to access everything in your model to provide this special behavior without opening some potential security holes. The best way for me turned out to be subclassing the User model as well as creating a new controller.</p>
<p><strong>Implementation<br />
</strong></p>
<p style="text-align:justify;">In my case, I wanted to automatically activate users that are created by the admin without sending activation emails.</p>
<p style="text-align:justify;">Step 1, subclass your normal Users model in models/user.rb:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
# model subclass only used by admin backend
class AdminViewUser &#60; User
  # override method instead of using callback macro to prevent super from being called
  def before_create
    auto_activate
  end
  # (optional) skip post-activation email for users created by admin
  def recently_activated?
    false
  end
protected
  def auto_activate
    @created = false  # (optional) skip sending signup email for users created by admin
    self.activated_at = Time.now.utc
    self.activation_code = nil
  end
end</pre>
<p style="text-align:justify;">Step 2, modify models/user_observer.rb to checks for automatic activation before sending out emails (optional):</p>
<pre class="brush: ruby; title: ; notranslate" title="">
class UserObserver &#60; ActiveRecord::Observer
  def after_create(user)
    UserMailer.deliver_signup_notification(user) if user.recently_created?
  end
  def after_save(user)
    UserMailer.deliver_activation(user) if user.recently_activated?
  end
end</pre>
<p style="text-align:justify;">Step 3, add a new controller that uses ActiveScaffold, restricted to admin users only, in controllers/admin_view_user_controller.rb:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
class AdminViewUserController &#60; ApplicationController
  before_filter :admin_required  # see authenticated_system.rb below
  active_scaffold do &#124;config&#124;
    config.label = &#34;My Fancy User Admin Page&#34;
    config.columns = [:login, :email, :password, :password_confirmation, :created_at, :updated_at]
    # exclude some columns from specific views, for more config options see ActiveScaffold web site
    list.columns.exclude :password, :password_confirmation
    show.columns.exclude :password, :password_confirmation
    update.columns.exclude :created_at, :updated_at
    create.columns.exclude :created_at, :updated_at
  end
end</pre>
<p style="text-align:justify;">Final step, implement the :admin_required method. I added a column called &#8216;is_admin&#8217; to my users table and created some new methods in lib/authenticated_system.rb:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
module AuthenticatedSystem
  protected
  def is_admin?
    logged_in? &#38;&#38; current_user.is_admin?
  end
  def admin_required
    is_admin? &#124;&#124; access_denied
  end
end</pre>
<p style="text-align:justify;">This is just an example to get you started. There are probably security enhancements that could be made and, obviously, you can administrate models other than just User. In my version I also added a UserGroup model that is also administrated by ActiveScaffold.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Jumping on the Rails Pt.3 - Getting Authenticated]]></title>
<link>http://baphled.wordpress.com/2009/07/03/jumping-on-the-rails-pt-3-getting-authenticated/</link>
<pubDate>Fri, 03 Jul 2009 11:54:30 +0000</pubDate>
<dc:creator>baphled</dc:creator>
<guid>http://baphled.wordpress.com/2009/07/03/jumping-on-the-rails-pt-3-getting-authenticated/</guid>
<description><![CDATA[Carrying on from my last post, I&#8217;ll introduce Rest Authentication to the Story Board project.]]></description>
<content:encoded><![CDATA[Carrying on from my last post, I&#8217;ll introduce Rest Authentication to the Story Board project.]]></content:encoded>
</item>
<item>
<title><![CDATA[BackgrounDRb, BackgroundJob, Restful authentication ---- important links]]></title>
<link>http://muhammadnoman.wordpress.com/2008/08/11/backgroundrb-backgroundjob-restful-authentication-important-links/</link>
<pubDate>Mon, 11 Aug 2008 10:59:14 +0000</pubDate>
<dc:creator>muhammadnoman</dc:creator>
<guid>http://muhammadnoman.wordpress.com/2008/08/11/backgroundrb-backgroundjob-restful-authentication-important-links/</guid>
<description><![CDATA[:: Tutorial to integrate Restful-authentication &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;]]></description>
<content:encoded><![CDATA[<p>:: Tutorial to integrate Restful-authentication</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1) <a href="http://www.railsforum.com/viewtopic.php?id=14216&#038;p=1" rel="nofollow">http://www.railsforum.com/viewtopic.php?id=14216&#038;p=1</a></p>
<p>2) <a href="http://railscasts.com/tags/9" rel="nofollow">http://railscasts.com/tags/9</a></p>
<p>:: Ruby job server and scheduler</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1)*  <a href="http://backgroundrb.rubyforge.org/" rel="nofollow">http://backgroundrb.rubyforge.org/</a></p>
<p>2)   <a href="http://backgroundrb.rubyforge.org/manual/" rel="nofollow">http://backgroundrb.rubyforge.org/manual/</a></p>
<p>3)   <a href="http://www.infoq.com/articles/BackgrounDRb" rel="nofollow">http://www.infoq.com/articles/BackgrounDRb</a></p>
<p>4)*  <a href="http://warpspire.com/tipsresources/programming/long-running-tasks-in-rails-backgroundrb/" rel="nofollow">http://warpspire.com/tipsresources/programming/long-running-tasks-in-rails-backgroundrb/</a></p>
<p>5)   <a href="http://brainspl.at/articles/2006/07/02/backgroundrb-updated" rel="nofollow">http://brainspl.at/articles/2006/07/02/backgroundrb-updated</a></p>
<p>6)   <a href="http://trix.pl/blog/running-long-background-tasks-in-ruby-on-rails-made-dead-simple.html" rel="nofollow">http://trix.pl/blog/running-long-background-tasks-in-ruby-on-rails-made-dead-simple.html</a></p>
<p>7)   <a href="http://railsforum.com/viewtopic.php?id=1033" rel="nofollow">http://railsforum.com/viewtopic.php?id=1033</a></p>
<p>8)   <a href="http://workingwithrails.com/railsplugin/4758-backgroundrb" rel="nofollow">http://workingwithrails.com/railsplugin/4758-backgroundrb</a></p>
<p>9)* <a href="http://www.blognow.com.au/q/64722/Ruby_on_Rails_and_BackgroundRB_-_multiple_progress_bars_with_ActiveScaffold.html" rel="nofollow">http://www.blognow.com.au/q/64722/Ruby_on_Rails_and_BackgroundRB_-_multiple_progress_bars_with_ActiveScaffold.html</a></p>
<p>10)* <a href="http://snippets.aktagon.com/snippets/161-Using-backgroundrb-to-execute-tasks-asynchronously-in-Rails" rel="nofollow">http://snippets.aktagon.com/snippets/161-Using-backgroundrb-to-execute-tasks-asynchronously-in-Rails</a></p>
<p>11)  <a href="http://blarg.slackworks.com/posts/bj-makes-attachment_fu-happy" rel="nofollow">http://blarg.slackworks.com/posts/bj-makes-attachment_fu-happy</a> (for BJ)</p>
<p>12)  <a href="http://www.ruby-forum.com/topic/135018" rel="nofollow">http://www.ruby-forum.com/topic/135018</a> (for BJ)</p>
<p>:: RESTful RoR</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1) <a href="http://www.gaugeus.com/ramblings/2007/10/27/building-a-restful-ruby-on-rails-application-from-the-ground-up-with-a-site-wide-layout" rel="nofollow">http://www.gaugeus.com/ramblings/2007/10/27/building-a-restful-ruby-on-rails-application-from-the-ground-up-with-a-site-wide-layout</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Criando uma Tela de Login]]></title>
<link>http://railsgirl.wordpress.com/2008/07/29/criando-uma-tela-de-login/</link>
<pubDate>Tue, 29 Jul 2008 01:32:40 +0000</pubDate>
<dc:creator>amandavarella</dc:creator>
<guid>http://railsgirl.wordpress.com/2008/07/29/criando-uma-tela-de-login/</guid>
<description><![CDATA[Atenção: eu fiz isso com rails 2.1, não sei como funciona com as versões anteriores. Depois de briga]]></description>
<content:encoded><![CDATA[<p>Atenção: eu fiz isso com rails 2.1, não sei como funciona com as versões anteriores.</p>
<p>Depois de brigar um dia inteiro (e ao final do dia perceber que não precisava nada disso&#8230;) consegui criar uma interface de login, que como vocês verão aqui é muito simples.<br />
Eu sabia que existia uma gem, ou um plugin sei lá.. que já gerava as interfaces para cadastro de usuário, login no sistema e talz.. mas eu não sabia qual era, e fiquei inutilmente o dia inteiro tentando tentar um plugin com um nome bastante sugestivo &#8220;login_generator&#8221;. Depois de muito pesquisar e bater cabeça, cheguei finalmente ao &#8220;restful_authentication&#8221; o plugin de nome nada sugestivo para a criação das nossas interfaces de acesso de usuário.<br />
Para começarmos precisamos de um projeto, se vc ainda não o tem, para criá-lo digite:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
rails meuprojeto
</pre>
<p>Com o seu projeto criado, vc deverá então instalar este plugin, com os seguintes comandos:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
script/plugin source http://svn.techno-weenie.net/projects/plugins/
</pre>
<pre class="brush: ruby; title: ; notranslate" title="">
script/plugin install restful_authentication
</pre>
<p>Em seguida, gere os seus controles da seguinte maneira:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
script/generate authenticated user sessions
</pre>
<p>MUITA CALMA NESSA HORA! REPARE, RESPEITE O SINGULAR E O PLURAL!!! user (no singular) sessions (no plural), gerará dois controllers um &#8220;users&#8221;e outro &#8220;sessions&#8221;. No tutorial que eu estava lendo estava errado! E eu perdi mais um tempo com isso&#8230; bem, eu ainda não entendi muito bem essa coisa de singular e plural do rails não, mas segundo o carinha de um mini-curso que eu assisti, isto é normal e a gente se acostuma com o tempo</p>
<p>Altere o seu arquivo routes.rb (dentro do diretório config) para que ele fique assim:</p>
<pre class="brush: ruby; title: ; notranslate" title="">
ActionController::Routing::Routes.draw do &amp;#124;map&amp;#124;
  map.resources :users
  map.resource :session, :controller =&gt; :sessions
  map.signup '/signup', :controller =&gt; 'users', :action =&gt; 'new'
  map.login  '/login', :controller =&gt; 'sessions', :action =&gt; 'new'
  map.logout '/logout', :controller =&gt; 'sessions', :action =&gt; 'destroy'  
end
</pre>
<p>Cuidado que no final do arquivo vem por default uns map.connect, tira essas linhas e deixa o arquivo como está mostrado acima.<br />
Agora vamos criar a tabela de usuários com</p>
<pre class="brush: ruby; title: ; notranslate" title="">
rake db:migrate
</pre>
<p>Se o servidor estiver rodando, acesse a aplicação <a href="http://localhost:3000/signup" rel="nofollow">http://localhost:3000/signup</a>.<br />
Tente cadastrar os dados e Voilá! Vc tem uma tela de cadastro de usuários (após o cadastro, ele vai para a tela principal do rails, depois vc terá que configurar para onde vc quer que após o login do usuário o sistema vá)<br />
Teste também <a href="http://localhost:3000/login" rel="nofollow">http://localhost:3000/login</a>, informando os dados do usuário que vc cadastrou para testar se está funcionando.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Restful Authentication for Rails 2.0]]></title>
<link>http://deadbadger.wordpress.com/2008/04/08/restful-authentication-for-rails-20/</link>
<pubDate>Tue, 08 Apr 2008 07:22:19 +0000</pubDate>
<dc:creator>deadbadger</dc:creator>
<guid>http://deadbadger.wordpress.com/2008/04/08/restful-authentication-for-rails-20/</guid>
<description><![CDATA[You should look to the following article link to find out how to do it for Rails 2.0. I won&#8217;t]]></description>
<content:encoded><![CDATA[<p>You should look to the following article link to find out how to do it for Rails 2.0. I won&#8217;t post here the whole thing as I&#8217;d only be copying (roughly) someone else&#8217;s work anyway. Just a few points to note though.</p>
<p><code>include AuthenticatedSystem</code><br />should go under your class declaration in the app/controllers/application.rb file. Also, in the application.html.erb layout you want (right have the very end of the document) the following:<br />
<code>&#60;%= yield %&#62;</code></p>
<p>Don&#8217;t be a twat and forget that like I did, and then sit there wondering why the hell it wasn&#8217;t showing the content.</p>
<p>Anyway, here&#8217;s the post: <a href="http://www.railsforum.com/viewtopic.php?id=14216" target="_blank">Restful Authentication Rails 2.0</a>.</p>
]]></content:encoded>
</item>

</channel>
</rss>
