diff --git a/tracks/app/controllers/user_controller.rb b/tracks/app/controllers/user_controller.rb index 23137e9a..24e6351f 100644 --- a/tracks/app/controllers/user_controller.rb +++ b/tracks/app/controllers/user_controller.rb @@ -50,6 +50,12 @@ class UserController < ApplicationController end end + def refresh_token + @user.crypt_word + @user.save + redirect_to :controller => 'user', :action => 'preferences' + end + protected def do_change_password_for(user) diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb index d5ab77b6..72b04f7a 100644 --- a/tracks/app/models/user.rb +++ b/tracks/app/models/user.rb @@ -24,6 +24,10 @@ class User < ActiveRecord::Base self.password_confirmation = pass_confirm end + def crypt_word + write_attribute("word", self.class.sha1(login + Time.now.to_i.to_s + rand.to_s)) + end + protected def self.sha1(pass) @@ -31,14 +35,13 @@ protected Digest::SHA1.hexdigest("#{SALT}--#{pass}--") end - before_create :crypt_password_and_word - before_update :crypt_password_and_word + before_create :crypt_password, :crypt_word + before_update :crypt_password - def crypt_password_and_word + def crypt_password write_attribute("password", self.class.sha1(password)) if password == @password_confirmation - write_attribute("word", self.class.sha1(login + Time.now.to_i.to_s + rand.to_s)) end - + validates_presence_of :password, :login validates_length_of :password, :within => 5..40 validates_confirmation_of :password diff --git a/tracks/app/views/user/preferences.rhtml b/tracks/app/views/user/preferences.rhtml index 3ed2ac1e..d367e411 100644 --- a/tracks/app/views/user/preferences.rhtml +++ b/tracks/app/views/user/preferences.rhtml @@ -1,48 +1,58 @@
-

Your preferences

+

Your preferences

-<% for name in ["notice", "warning", "message"] %> - <% if flash[name] %> - <%= "
#{flash[name]}
" %> + <% for name in ["notice", "warning", "message"] %> + <% if flash[name] %> + <%= "
#{flash[name]}
" %> + <% end %> <% end %> -<% end %> - -<%= link_to "Edit preferences", :controller => 'user', :action => 'edit_preferences' %> | -<%= link_to 'Change password', :controller => 'user', :action => 'change_password' %> + + <%= link_to "Edit preferences", :controller => 'user', :action => 'edit_preferences' %> | + <%= link_to 'Change password', :controller => 'user', :action => 'change_password' %> +
+
Token (for feeds and API use):
+
<%= @user.word %>
+
+ <%= button_to "Generate a new token", { :controller => 'user', :action => 'refresh_token'}, + :confirm => "Are you sure? Generating a new token will replace the existing one and break any external usages of this token." %> +
+ +
+
diff --git a/tracks/public/stylesheets/standard.css b/tracks/public/stylesheets/standard.css index 86cfa2c1..cf981cac 100644 --- a/tracks/public/stylesheets/standard.css +++ b/tracks/public/stylesheets/standard.css @@ -637,6 +637,17 @@ div.message { } ul#prefs {list-style-type: disc; margin-left: 5px;} +#token_area { + text-align:center; + margin-top:20px; +} +#token_area .description{ + font-weight:bold; +} +#token_area form { + width:100%; + text-align:center; +} #feedlegend { padding: 2px;