From e378ede5102d048efc993995db7f28f24b41b7e4 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 26 Feb 2018 19:08:21 -0300 Subject: [PATCH] =?UTF-8?q?cerrar=20la=20sesi=C3=B3n=20y=20cambiar=20de=20?= =?UTF-8?q?idioma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/application.scss | 5 +++++ app/controllers/application_controller.rb | 5 +++++ app/controllers/login_controller.rb | 10 ++++++++++ app/views/layouts/_breadcrumb.haml | 1 + app/views/login/_logout.haml | 4 ++++ app/views/login/new.haml | 4 ++++ config/locales/en.yml | 4 ++++ config/locales/es.yml | 4 ++++ config/routes.rb | 2 ++ 9 files changed, 39 insertions(+) create mode 100644 app/views/login/_logout.haml diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5e9554ac..f71b8c7c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -92,3 +92,8 @@ textarea.post-content { direction: rtl; text-align: right; } + +.btn-text { + background-color: transparent; + border: none; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5200e602..85e969cb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ # Forma de ingreso a Sutty class ApplicationController < ActionController::Base protect_from_forgery with: :exception + before_action :set_locale # No tenemos índice de sutty, vamos directamente a ver el listado de # sitios @@ -36,4 +37,8 @@ class ApplicationController < ActionController::Base def find_lang params.fetch(:lang, I18n.locale.to_s) end + + def set_locale + I18n.locale = session[:lang] if session[:lang].present? + end end diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index b8978a98..a0ce18b8 100644 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -12,10 +12,20 @@ class LoginController < ApplicationController def create authenticate + session[:lang] = params[:lang] if authenticated? # TODO enviar a la URL de donde vinimos redirect_to sites_path + else + flash[:error] = t('login.error') + render 'login/new' end end + + def delete + warden.logout + + redirect_to login_new_path + end end diff --git a/app/views/layouts/_breadcrumb.haml b/app/views/layouts/_breadcrumb.haml index 47736311..4862d69c 100644 --- a/app/views/layouts/_breadcrumb.haml +++ b/app/views/layouts/_breadcrumb.haml @@ -1,5 +1,6 @@ %nav{'aria-label': 'breadcrumb', role: 'navigation'} %ol.breadcrumb + %li.breadcrumb-item= render 'login/logout' - crumbs.compact.each do |crumb| - if crumb == crumbs.last %li.breadcrumb-item.active{'aria-current': 'page'}= crumb diff --git a/app/views/login/_logout.haml b/app/views/login/_logout.haml new file mode 100644 index 00000000..c15d4cff --- /dev/null +++ b/app/views/login/_logout.haml @@ -0,0 +1,4 @@ += form_tag login_logout_path, method: :delete, class: 'form-inline' do + = button_tag type: 'submit', class: 'btn-text', + data: { toggle: 'tooltip' }, title: t('help.logout') do + = fa_icon('sign-out') diff --git a/app/views/login/new.haml b/app/views/login/new.haml index ef63cbe2..c16b77bc 100644 --- a/app/views/login/new.haml +++ b/app/views/login/new.haml @@ -9,6 +9,10 @@ %input{type: 'email', name: 'username', class: 'form-control', placeholder: t('login.email')} .form-group %input{type: 'password', name: 'password', class: 'form-control', placeholder: t('login.password')} + .form-group + %select.form-control{name: 'lang', placeholder: t('login.lang')} + %option{value: 'en'} English + %option{value: 'es'} Castellano .form-group %input{type: 'submit', value: t('login.submit'), class: 'btn btn-lg btn-primary btn-block'} diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bccb5ae..1ccd0bee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,7 @@ en: argument_error: 'Argument `%{argument}` must be an instance of %{class}' unknown_locale: 'Unknown %{locale} locale' help: + logout: 'Close the session' breadcrumbs: "What you see up here are the bread crumbs for this site. When you enter a new section, you will see the previous ones and also have a path for where you\'re standing." @@ -86,6 +87,9 @@ en: email: 'E-mail' password: 'Password' submit: 'Log in' + logout: 'Log out' + lang: 'Language' + error: 'There was an error during log in. Did you type your credentials correctly?' sites: actions: 'Actions' posts: 'View and edit posts' diff --git a/config/locales/es.yml b/config/locales/es.yml index df3d83e1..93b5e185 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -3,6 +3,7 @@ es: argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}' unknown_locale: 'El idioma %{locale} es desconocido' help: + logout: 'Cierra la sesión' breadcrumbs: 'Lo que ves arriba son las migas de pan de este sitio. Cuando ingreses a una sección, podrás volver a las secciones anteriores y además tener una ruta de donde estás parada.' @@ -88,6 +89,9 @@ es: email: 'Dirección de correo' password: 'Contraseña' submit: 'Ingresar' + lang: 'Idioma' + logout: 'Salir' + error: 'Hubo un error al iniciar la sesión. ¿Escribiste bien tus credenciales?' sites: actions: 'Acciones' posts: 'Ver y editar artículos' diff --git a/config/routes.rb b/config/routes.rb index c02ed680..ec7561ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,8 @@ Rails.application.routes.draw do get 'login/new', to: 'login#new' post 'login', to: 'login#create' + delete 'login/logout', to: 'login#delete' + get 'markdown', to: 'application#markdown' resources :sites, only: [ :index, :show ] do