moved auth token to admins page, and added a link in the dropdown

This commit is contained in:
Maxwell Salzberg 2011-05-19 14:23:04 -07:00
parent 925292a7b2
commit 3c4c62abd5
8 changed files with 23 additions and 14 deletions

View file

@ -28,6 +28,13 @@ class AdminsController < ApplicationController
redirect_to :back, :notice => notice, :user => {:id => u.id} redirect_to :back, :notice => notice, :user => {:id => u.id}
end end
def generate_new_token
current_user.reset_authentication_token!
current_user.authentication_token
redirect_to user_search_path, :notice => "auth token reset"
end
def admin_inviter def admin_inviter
opts = {:service => 'email', :identifier => params[:identifier]} opts = {:service => 'email', :identifier => params[:identifier]}
existing_user = Invitation.find_existing_user('email', params[:identifier]) existing_user = Invitation.find_existing_user('email', params[:identifier])

View file

@ -76,9 +76,9 @@ class ApplicationController < ActionController::Base
end end
def redirect_unless_admin def redirect_unless_admin
admins = AppConfig[:admins] unless current_user.admin?
unless admins.present? && admins.include?(current_user.username) redirect_to root_url, :notice => 'you need to be an admin to do that'
redirect_to root_url return
end end
end end

View file

@ -141,14 +141,4 @@ class UsersController < ApplicationController
tar_path = PhotoMover::move_photos(current_user) tar_path = PhotoMover::move_photos(current_user)
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" ) send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
end end
before_filter :redirect_unless_admin, :only => :generate_new_token
def generate_new_token
if current_user.reset_authentication_token!
@token = current_user.authentication_token
else
@token = "No token created"
end
render :text => @token
end
end end

View file

@ -322,6 +322,10 @@ class User < ActiveRecord::Base
OpenSSL::PKey::RSA.new(serialized_private_key) OpenSSL::PKey::RSA.new(serialized_private_key)
end end
def admin?
AppConfig[:admins].present? && AppConfig[:admins].include?(self.username)
end
protected protected
def remove_person def remove_person

View file

@ -40,6 +40,11 @@
= link_to "add 10 invites for this user", add_invites_path(:user_id => user.id) = link_to "add 10 invites for this user", add_invites_path(:user_id => user.id)
%br %br
%br %br
%br
%h3 your auth token
%h2= current_user.authentication_token
= link_to "reset auth token", new_auth_token_path
%br
= javascript_include_tag 'apiconsole' = javascript_include_tag 'apiconsole'
#query #query
%h3 api console %h3 api console

View file

@ -42,6 +42,8 @@
= link_to current_user.name, '#' = link_to current_user.name, '#'
%li= link_to t('.profile'), current_user.person %li= link_to t('.profile'), current_user.person
%li= link_to t('.settings'), edit_user_path %li= link_to t('.settings'), edit_user_path
-if current_user.admin?
%li= link_to t('.admin'), user_search_path
%li= link_to t('.logout'), destroy_user_session_path %li= link_to t('.logout'), destroy_user_session_path
-unless @landing_page -unless @landing_page

View file

@ -270,6 +270,7 @@ en:
blog: "blog" blog: "blog"
login: "log in" login: "log in"
code: "code" code: "code"
admin: "admin"
application: application:
powered_by: "POWERED BY DIASPORA*" powered_by: "POWERED BY DIASPORA*"
whats_new: "what's new?" whats_new: "what's new?"

View file

@ -61,7 +61,6 @@ Diaspora::Application.routes.draw do
end end
# generating a new user token (for devise) # generating a new user token (for devise)
match 'users/generate_new_token' => 'users#generate_new_token'
# ActivityStreams routes # ActivityStreams routes
scope "/activity_streams", :module => "activity_streams" do scope "/activity_streams", :module => "activity_streams" do
@ -75,6 +74,7 @@ Diaspora::Application.routes.draw do
match 'user_search' => :user_search match 'user_search' => :user_search
get 'admin_inviter' => :admin_inviter get 'admin_inviter' => :admin_inviter
get 'add_invites' => :add_invites, :as => 'add_invites' get 'add_invites' => :add_invites, :as => 'add_invites'
get 'generate_new_token' => :generate_new_token, :as => 'new_auth_token'
end end
resource :profile resource :profile