Skip to content

Commit

Permalink
Added Api key to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Roendal committed Jun 29, 2011
1 parent 030216e commit 1bb09ab
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 47 deletions.
35 changes: 35 additions & 0 deletions app/assets/javascripts/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var notifications_open = false;
var api_key_open = false;

closeAllSettings = function() {
$("#notifications_settings_content").hide("slow");
$("#notifications_settings_briefing").show("slow");
notifications_open = false;
$("#api_key_settings_content").hide("slow");
$("#api_key_settings_briefing").show("slow");
api_key_open = false;
}
showNotificationsSettings = function() {
if (notifications_open) {
$("#notifications_settings_content").hide("slow");
$("#notifications_settings_briefing").show("slow");
notifications_open = false;
} else {
closeAllSettings();
$("#notifications_settings_content").show("slow");
$("#notifications_settings_briefing").hide("slow");
notifications_open = true;
}
}
showApiKeySettings = function() {
if (api_key_open) {
$("#api_key_settings_content").hide("slow");
$("#api_key_settings_briefing").show("slow");
api_key_open = false;
} else {
closeAllSettings();
$("#api_key_settings_content").show("slow");
$("#api_key_settings_briefing").hide("slow");
api_key_open = true;
}
}
10 changes: 7 additions & 3 deletions app/assets/stylesheets/settings.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/******************** Common ***********************/
.settings_block {
display:block;
padding-left:10px;
}
display:block;
padding-left:10px;
}
#api_token {
font-weight: bold;
font-style: italic;
}
4 changes: 4 additions & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class ApiController < ApplicationController

def create_key
current_user.reset_authentication_token!
if params[:api_settings].present?
redirect_to settings_path(:api_settings => true)
return
end
redirect_to :controller => :users, :action => :show, :id => current_user.to_param, :auth_token => params[:auth_token]
end

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class SettingsController < ApplicationController

before_filter :authenticate_user!

def index
end

Expand Down
26 changes: 26 additions & 0 deletions app/views/settings/_api_key.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="block" id="api_key_settings">
<div class="header">
<div class="header_text">
<%= t('settings.api_key.name')%>
</div>
<div class="header_icon_right">
<%= link_to (image_tag('btn/edit.png')), "javascript:showApiKeySettings();" %>
</div>
</div>
<div class="content" id="api_key_settings_briefing">
<div class="form_row">
<%= t('settings.api_key.briefing')%>
</div>
</div>
<div class="content" id="api_key_settings_content" style="display:none;">
<div class="settings_block">
<div class="form_row">
<%=t('settings.api_key.explanation') %>: <span id="api_token"><%= current_subject.authentication_token.blank? ? t('settings.api_key.empty') : current_subject.authentication_token %></span>
</div>
<div class="form_sub_row">
<%= link_to t('settings.api_key.regenerate'), api_keygen_path(:api_settings => true), :confirm => t('settings.api_key.confirm'), :remote => true %>
</div>

</div>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/settings/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<div class="space_center">
</div>
<%= render :partial => "notifications" %>
<%= render :partial => "api_key" %>
36 changes: 1 addition & 35 deletions app/views/settings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,11 @@
<% content_for :headers do %>
<%= stylesheet_link_tag "settings.css", :media => "screen, projection" %>
<%= javascript_include_tag 'settings.js' %>
<% end %>
<% content_for :javascript do %>
var notifications_open = false;
var edit_user_open = false;
closeAllSettings = function(){
$("#notifications_settings_content").hide("slow");
$("#notifications_settings_briefing").show("slow");
notifications_open = false;
$("#edit_user_settings_content").hide("slow");
$("#edit_user_settings_briefing").show("slow");
edit_user_open = false;
}

showNotificationsSettings = function(){
if (notifications_open){
$("#notifications_settings_content").hide("slow");
$("#notifications_settings_briefing").show("slow");
notifications_open = false;
}else{
closeAllSettings();
$("#notifications_settings_content").show("slow");
$("#notifications_settings_briefing").hide("slow");
notifications_open = true;
}
}
showEditUserSettings = function(){
if (edit_user_open){
$("#edit_user_settings_content").hide("slow");
$("#edit_user_settings_briefing").show("slow");
edit_user_open = false;
}else{
closeAllSettings();
$("#edit_user_settings_content").show("slow");
$("#edit_user_settings_briefing").hide("slow");
edit_user_open = true;
}
}
<% end %>
<%= render :partial => 'index' %>
9 changes: 9 additions & 0 deletions app/views/settings/index.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% if params[:api_settings].present? %>
$('#api_token').html('<%= current_subject.authentication_token.blank? ? t('settings.api_key.empty') : current_subject.authentication_token %>')
<% else %>
$("#content").html("<%= escape_javascript(render :partial => 'index') %>");
$("head").append($("<%= escape_javascript(stylesheet_link_tag "settings.css", :media => "screen, projection") %>"));
$("head").append($("<%= escape_javascript(javascript_include_tag 'settings.js') %>"));
<%= toolbar %>
<% end %>

16 changes: 7 additions & 9 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,13 @@ en:
main: "Main settings"
one: "Settings"
success: "Your settings where correctly changed"
edit_user:
briefing: "Change your email or password"
name: "Edit user data"
email: "Email"
new_password: "Password"
new_password_confirmation: "Password confirmation"
new_password_comment: "Leave blank if you don't want to change it"
current_password: "Current password"
current_password_comment: "We need your current password to confirm your changes"
api_key:
briefing: "Manage your API key"
confirm: "Are you sure?"
empty: "Empty Token"
explanation: "This is your API key"
name: "API Key"
regenerate: "Regenerate API key"
notifications:
briefing: "Settings about notifications behaviour and mail alerts"
name: "Notifications"
Expand Down

0 comments on commit 1bb09ab

Please sign in to comment.