diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5e9554a..f71b8c7 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 5200e60..85e969c 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 b8978a9..a0ce18b 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 4773631..4862d69 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 0000000..c15d4cf --- /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 ef63cbe..c16b77b 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 2bccb5a..1ccd0be 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 df3d83e..93b5e18 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 c02ed68..ec7561c 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