<br><br><div class="gmail_quote">On Mon, Feb 25, 2008 at 6:24 PM, Aria Stewart &lt;<a href="mailto:aredridel@nbtsc.org">aredridel@nbtsc.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
On Feb 25, 2008, at 2:21 PM, Albert Ng wrote:<br>
<br>
&gt; I&#39;ll keep that in mind.<br>
&gt;<br>
&gt; As an aside, using this gem, how would I go about changing the user<br>
&gt; without closing the browser or raising «Unauthorized»? &nbsp;That last<br>
&gt; pops up a log-in window that can&#39;t authorize (have to press escape).<br>
<br>
</div>You can&#39;t. Browsers really really really should include a logout<br>
button, and they don&#39;t. File bugs with me!<br>
<div><div></div></div></blockquote><div>:)<br><br>After cursing at @state, wondering why it wasn&#39;t saving before I «raise Unauthorized» (for 3 hours *rolleyes*) , I&#39;ve finally gotten the expected behavior by creating a «Loginstate» table that belongs to «User», calling save explicitly, and working some logic with that.<br>
<br>It&#39;s horribly expensive on the database, but it&#39;s ok for my purposes, because the app is only accessible locally.<br><br>Another thing is that I changed password_for_user to record_for_user, as I&#39;m using @user for an AR record, and the gem kept turning it into a string :P<br>
<br>P.S. <a href="http://code.whytheluckystiff.net/camping/ticket/129">http://code.whytheluckystiff.net/camping/ticket/129</a> is very annoying, they changed mongrel/camping again (for the worse)<br><br>Module Ctd:Models<br>
&nbsp; class Loginstate &lt; Base<br>&nbsp;&nbsp;&nbsp; belongs_to :users<br>&nbsp; end<br>&nbsp; <br>&nbsp; ---<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; create_table :ctd_loginstates do |t|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.column :user_id, :integer, :null =&gt; false<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.column :reauthenticate, :boolean, :default =&gt; false<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.create_loginstate<br><br>---<br>Module Ctd:Controlers<br>&nbsp; class CloseSession<br>&nbsp;&nbsp;&nbsp; def get<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; authenticate<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @user.loginstate.reauthenticate = true<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @user.loginstate.save<br>
&nbsp; &nbsp;&nbsp;&nbsp; redirect R(Index)<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; end<br>---<br>module Ctd<br>&nbsp; include Camping::DigestAuth<br>&nbsp; REALM = &quot;ctd&quot;<br>&nbsp; <br>&nbsp; module_function<br>&nbsp; <br>&nbsp; def record_for_user(username)<br>&nbsp;&nbsp;&nbsp; include Ctd::Models<br>
&nbsp;&nbsp;&nbsp; user = User.find( :first, :conditions =&gt; [&#39;username = ?&#39;, username])<br>&nbsp;&nbsp;&nbsp; user = User.find( :first, :conditions =&gt; [&#39;username = ?&#39;, &#39;dummy&#39;]) unless user<br>&nbsp;&nbsp;&nbsp; if user.loginstate.reauthenticate == true<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.loginstate.reauthenticate = false<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.loginstate.save<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise Unauthorized<br>&nbsp;&nbsp;&nbsp; end if user<br>&nbsp;&nbsp;&nbsp; return user<br>&nbsp; end<br>end<br></div></div>