From 32a7cdafb3f29dbc48a411b69bbcf197f8e5de51 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 25 Jun 2013 12:10:45 +0400 Subject: [PATCH] #192: updated tokens_controller, added token.ru.yml --- .../platforms/tokens_controller.rb | 4 ++- app/models/token.rb | 2 +- app/views/platforms/tokens/index.html.haml | 2 +- app/views/platforms/tokens/show.html.haml | 9 ++++- config/locales/models/token.ru.yml | 34 +++++++++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 config/locales/models/token.ru.yml diff --git a/app/controllers/platforms/tokens_controller.rb b/app/controllers/platforms/tokens_controller.rb index eb42b76b9..2eb71e21c 100644 --- a/app/controllers/platforms/tokens_controller.rb +++ b/app/controllers/platforms/tokens_controller.rb @@ -17,7 +17,9 @@ class Platforms::TokensController < Platforms::BaseController end def withdraw - if @token.block + if @token.block + @token.updater = current_user + @token.save redirect_to :back, :notice => t('layout.tokens.withdraw_success') else redirect_to :back, :notice => t('layout.tokens.withdraw_fail') diff --git a/app/models/token.rb b/app/models/token.rb index 1e53ffa7c..9c2c2e50e 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -22,7 +22,7 @@ class Token < ActiveRecord::Base def generate_token self.authentication_token = loop do - token = SecureRandom.urlsafe_base64(64) + token = SecureRandom.urlsafe_base64(32) break token unless Token.where(:authentication_token => token).exists? end end diff --git a/app/views/platforms/tokens/index.html.haml b/app/views/platforms/tokens/index.html.haml index 7828df92b..0a23f6140 100644 --- a/app/views/platforms/tokens/index.html.haml +++ b/app/views/platforms/tokens/index.html.haml @@ -8,7 +8,7 @@ %tr %th= t('activerecord.attributes.token.id') %th.th1= t('activerecord.attributes.token.description') - %th= t('layout.tokens.creator') + %th= t('activerecord.attributes.token.creator') %th= t('activerecord.attributes.token.status') %tbody - @tokens.each do |token| diff --git a/app/views/platforms/tokens/show.html.haml b/app/views/platforms/tokens/show.html.haml index 982f40e22..7f41332de 100644 --- a/app/views/platforms/tokens/show.html.haml +++ b/app/views/platforms/tokens/show.html.haml @@ -28,6 +28,13 @@ %td %b= "#{t('activerecord.attributes.token.status')}:" %td= @token.status + %tr + %td + %b= "#{t('activerecord.attributes.token.authentication_token')}:" + %td= @token.authentication_token .buttons_block - = link_to I18n.t('layout.tokens.withdraw'), withdraw_platform_token_path(@platform, @token), :class => 'button left_floated' + = link_to t('layout.tokens.withdraw'), + withdraw_platform_token_path(@platform, @token), + :method => :post, :class => 'button', + :confirm => t('layout.tokens.withdraw_confirm') diff --git a/config/locales/models/token.ru.yml b/config/locales/models/token.ru.yml new file mode 100644 index 000000000..de0719df4 --- /dev/null +++ b/config/locales/models/token.ru.yml @@ -0,0 +1,34 @@ +ru: + layout: + tokens: + list_header: Токены + new: Новый токен + new_header: Новый токен + about: Токен платформы + withdraw: Отозвать + withdraw_confirm: Уверены, что хотите отозвать токен? + + statuses: + active: Активный + blocked: Отозван + + flash: + token: + saved: Токен успешно добавлен + save_error: Не удалось добавить токен + withdraw_success: Токен успешно отозван! + withdraw_fail: Не удалось отозвать токен! + + activerecord: + models: + token: Токен + attributes: + token: + id: Id + description: Описание + status: Статус + authentication_token: Токен + created_at: Создан + updated_at: Обновлен + creator: Создатель + updater: Обновитель