mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Create a named route for the preferences page and use it. Rename "crypt_token" to "generate_token".
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@569 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
08e5d6069d
commit
64321f5c46
8 changed files with 22 additions and 19 deletions
|
|
@ -142,7 +142,7 @@ class UsersController < ApplicationController
|
|||
def update_password
|
||||
@user.change_password(params[:updateuser][:password], params[:updateuser][:password_confirmation])
|
||||
notify :notice, "Password updated."
|
||||
redirect_to :controller => 'preferences'
|
||||
redirect_to preferences_path
|
||||
rescue Exception => error
|
||||
notify :error, error.message
|
||||
redirect_to :action => 'change_password'
|
||||
|
|
@ -171,7 +171,7 @@ class UsersController < ApplicationController
|
|||
@user.auth_type = params[:user][:auth_type]
|
||||
if @user.save
|
||||
notify :notice, "Authentication type updated."
|
||||
redirect_to :controller => 'preferences'
|
||||
redirect_to preferences_path
|
||||
else
|
||||
notify :warning, "There was a problem updating your authentication type: #{ @user.errors.full_messages.join(', ')}"
|
||||
redirect_to :action => 'change_auth_type'
|
||||
|
|
@ -207,7 +207,7 @@ class UsersController < ApplicationController
|
|||
else
|
||||
notify :warning, "You have successfully verified #{openid_url} as your identity but there was a problem saving your authentication preferences."
|
||||
end
|
||||
redirect_to :controller => 'preferences', :action => 'index'
|
||||
redirect_to preferences_path
|
||||
|
||||
when OpenID::CANCEL
|
||||
notify :warning, "Verification cancelled."
|
||||
|
|
@ -220,10 +220,10 @@ class UsersController < ApplicationController
|
|||
|
||||
|
||||
def refresh_token
|
||||
@user.crypt_token
|
||||
@user.save
|
||||
@user.generate_token
|
||||
@user.save!
|
||||
notify :notice, "New token successfully generated"
|
||||
redirect_to :controller => 'preferences', :action => 'index'
|
||||
redirect_to preferences_path
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class User < ActiveRecord::Base
|
|||
validates_uniqueness_of :login, :on => :create
|
||||
validates_presence_of :open_id_url, :if => Proc.new{|user| user.auth_type == 'open_id'}
|
||||
|
||||
before_create :crypt_password, :crypt_token
|
||||
before_create :crypt_password, :generate_token
|
||||
before_update :crypt_password
|
||||
|
||||
def validate
|
||||
|
|
@ -151,6 +151,11 @@ class User < ActiveRecord::Base
|
|||
time.to_date
|
||||
end
|
||||
|
||||
def generate_token
|
||||
new_token = Digest::SHA1.hexdigest "#{Time.now.to_i}#{rand}"
|
||||
write_attribute("token", new_token)
|
||||
end
|
||||
|
||||
def remember_token?
|
||||
remember_token_expires_at && Time.now.utc < remember_token_expires_at
|
||||
end
|
||||
|
|
@ -170,12 +175,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
protected
|
||||
|
||||
def self.sha1(pass)
|
||||
Digest::SHA1.hexdigest("#{Tracks::Config.salt}--#{pass}--")
|
||||
end
|
||||
|
||||
def crypt_token
|
||||
write_attribute("token", self.class.sha1(login + Time.now.to_i.to_s + rand.to_s))
|
||||
def self.sha1(s)
|
||||
Digest::SHA1.hexdigest("#{Tracks::Config.salt}--#{s}--")
|
||||
end
|
||||
|
||||
def crypt_password
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ window.onload=function(){
|
|||
<li><%= navigation_link( "Tickler", tickler_path, :title => "Tickler" ) %></li>
|
||||
<li><%= navigation_link( "Done", done_path, {:accesskey=>"d", :title=>"Completed"} ) %></li>
|
||||
<li><%= navigation_link( "Notes", notes_path, {:accesskey => "o", :title => "Show all notes"} ) %></li>
|
||||
<li><%= navigation_link( "Preferences", {:controller => "preferences", :action => "index"}, {:accesskey => "u", :title => "Show my preferences"} ) %></li>
|
||||
<li><%= navigation_link( "Preferences", preferences_path, {:accesskey => "u", :title => "Show my preferences"} ) %></li>
|
||||
<li><%= navigation_link( "Import/Export", {:controller => "data", :action => "index"}, {:accesskey => "i", :title => "Import and export data"} ) %></li>
|
||||
<% if @user.is_admin? -%>
|
||||
<li><%= navigation_link("Admin", users_path, {:accesskey => "a", :title => "Add or delete users"} ) %></li>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<% form_tag :action => 'update_auth_type' do %>
|
||||
<div><label for="user_auth_type">Authentication type:</label> <%= select('user', 'auth_type', Tracks::Config.auth_schemes.collect {|p| [ p, p ] }) %></div>
|
||||
<div id="open_id" style="display:<%= @user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="user_open_id_url">Identity URL:</label> <input type="text" name="openid_url" value="<%= @user.open_id_url %>" class="open_id" /></div>
|
||||
<div class="actions"><%= submit_tag 'Change Authentication Type' %> <%= link_to 'Cancel', :controller => 'preferences' %></div>
|
||||
<div class="actions"><%= submit_tag 'Change Authentication Type' %> <%= link_to 'Cancel', preferences_path %></div>
|
||||
|
||||
<%= observe_field( :user_auth_type, :function => "$('open_id').style.display = value == 'open_id' ? 'block' : 'none'") %>
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<td><%= password_field "updateuser", "password_confirmation", :size => 40 %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= link_to 'Cancel', :controller => 'preferences' %></td>
|
||||
<td><%= link_to 'Cancel', preferences_path %></td>
|
||||
<td><%= submit_tag 'Change password' %></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ ActionController::Routing::Routes.draw do |map|
|
|||
|
||||
# Feed Routes
|
||||
map.connect 'feeds', :controller => 'feedlist', :action => 'index'
|
||||
|
||||
map.preferences 'preferences', :controller => 'preferences', :action => 'index'
|
||||
|
||||
# Install the default route as the lowest priority.
|
||||
map.connect ':controller/:action/:id'
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class UsersControllerTest < Test::Rails::TestCase
|
|||
assert_response :success
|
||||
assert_equal assigns['page_title'], "TRACKS::Change password"
|
||||
post :update_password, :updateuser => {:password => 'newpassword', :password_confirmation => 'newpassword'}
|
||||
assert_redirected_to :controller => 'preferences'
|
||||
assert_redirected_to preferences_path
|
||||
@updated_user = User.find(users(:admin_user).id)
|
||||
assert_equal @updated_user.crypted_password, Digest::SHA1.hexdigest("#{Tracks::Config.salt}--newpassword--")
|
||||
assert_equal "Password updated.", flash[:notice]
|
||||
|
|
|
|||
|
|
@ -178,9 +178,9 @@ class UserTest < Test::Rails::TestCase
|
|||
assert User.no_users_yet?
|
||||
end
|
||||
|
||||
def test_crypt_token_updates_token
|
||||
def test_generate_token_updates_token
|
||||
assert_value_changed @admin_user, :token do
|
||||
@admin_user.send :crypt_token
|
||||
@admin_user.send :generate_token
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue