From fed01476afa0932662de8ca7c39748992029b9ac Mon Sep 17 00:00:00 2001 From: shemoreira Date: Wed, 19 Oct 2016 14:47:15 -0200 Subject: [PATCH] #2 <@lrsousa, @lucasgaspari> - validar login --- app/controllers/sessions_controller.rb | 13 +++++++++---- app/views/devise/sessions/_new.html.erb | 12 +++++++++++- app/views/layouts/application.html.erb | 1 - 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index df33923..a4aa661 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -14,12 +14,17 @@ def create @user = UserBloodBank.find_for_authentication(cnpj: params[:documento]) end - if @user.valid_password?(senha) - sign_in(@user) - redirect_to dashboard_path, alert: "#{@user.name} tá na área!" + if (@user == nil) + redirect_to root_path , alert:"Documento inválido", flash: { manifesto_modal: true } else - redirect_to new_user_blood_donator_session_path, alert: "Dados invalidos!" + if @user.valid_password?(senha) + sign_in(@user) + redirect_to dashboard_path, alert: "#{@user.name} tá na área!" + else + redirect_to root_path , alert:"Senha inválida", flash: { manifesto_modal: true } + end end + end private diff --git a/app/views/devise/sessions/_new.html.erb b/app/views/devise/sessions/_new.html.erb index 094eb96..a3852b0 100644 --- a/app/views/devise/sessions/_new.html.erb +++ b/app/views/devise/sessions/_new.html.erb @@ -1,5 +1,11 @@ +<% if flash[:manifesto_modal] %> +