Commit ed5e19a518ebe62aeb2db87c55a45854df2dcb37

Authored by Nihad Abbasov
1 parent 32ca0b8c

allow user to reset his private token

app/controllers/profile_controller.rb
... ... @@ -25,4 +25,9 @@ class ProfileController < ApplicationController
25 25 render :action => "password"
26 26 end
27 27 end
  28 +
  29 + def reset_private_token
  30 + current_user.reset_authentication_token!
  31 + redirect_to profile_password_path
  32 + end
28 33 end
... ...
app/views/layouts/profile.html.haml
... ... @@ -18,7 +18,7 @@
18 18 .fixed
19 19 %aside
20 20 = link_to "Profile", profile_path, :class => current_page?(:controller => "profile", :action => :show) ? "current" : nil
21   - = link_to "Password", profile_password_path, :class => current_page?(:controller => "profile", :action => :password) ? "current" : nil
  21 + = link_to "Password & token", profile_password_path, :class => current_page?(:controller => "profile", :action => :password) ? "current" : nil
22 22 = link_to keys_path, :class => controller.controller_name == "keys" ? "current" : nil do
23 23 Keys
24 24 - unless current_user.keys.empty?
... ...
app/views/profile/password.html.haml
... ... @@ -18,3 +18,16 @@
18 18 .actions
19 19 = f.submit 'Save', :class => "lbutton vm"
20 20  
  21 +%br
  22 +%br
  23 +%br
  24 +
  25 += form_for @user, :url => profile_reset_private_token_path, :method => :put do |f|
  26 + %p
  27 + Current private token:
  28 + %strong
  29 + = current_user.private_token
  30 + %em.cred
  31 + keep it in secret!
  32 + .actions
  33 + = f.submit 'Reset', :confirm => "Are you sure?", :class => "lbutton vm"
... ...
config/routes.rb
... ... @@ -17,6 +17,7 @@ Gitlab::Application.routes.draw do
17 17 get "errors/gitosis"
18 18 get "profile/password", :to => "profile#password"
19 19 put "profile/password", :to => "profile#password_update"
  20 + put "profile/reset_private_token", :to => "profile#reset_private_token"
20 21 put "profile/edit", :to => "profile#social_update"
21 22 get "profile", :to => "profile#show"
22 23 get "dashboard", :to => "dashboard#index"
... ...
spec/requests/profile_spec.rb
... ... @@ -29,6 +29,19 @@ describe "Profile" do
29 29 it { @user.twitter.should == 'testtwitter' }
30 30 end
31 31  
  32 + describe "Reset private token" do
  33 + before do
  34 + visit profile_password_path
  35 + end
  36 +
  37 + it "should reset private token" do
  38 + user_first_token = @user.private_token
  39 + click_button "Reset"
  40 + @user.reload
  41 + @user.private_token.should_not == user_first_token
  42 + end
  43 + end
  44 +
32 45 describe "Password update" do
33 46 before do
34 47 visit profile_password_path
... ...