Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
#2 <@lrsousa, @lucasgaspari> - validar login
Browse files Browse the repository at this point in the history
  • Loading branch information
lrsousa committed Oct 19, 2016
1 parent 0bea211 commit fed0147
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 9 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion app/views/devise/sessions/_new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<% if flash[:manifesto_modal] %>
<div class="Modal js-modal js-modalLogin" style="opacity: 1; visibility: visible;">
<div class="Modal-content js-modalContent" style="top: 50%;">
<% else %>
<div class="Modal js-modal js-modalLogin">
<div class="Modal-content js-modalContent">
<% end %>

<div class="Modal-header">
<div class="Grid">
<div class="Grid-cell u-sizeFull">
Expand All @@ -10,13 +16,15 @@
</div>
</div>

<%= alert %>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="Modal-body">
<div class="Form Form--fluid">
<div class="Grid">
<div class="Grid-cell u-desktop-size1of12 u-mobile-sizeFull"></div>
<div class="Grid-cell u-desktop-size9of12 u-mobile-sizeFull">
<p>
<%= alert %>
</p>
<div class="Form-group">
<span class="Form-inputLabel u-size2of12">CPF/CNPJ:</span>
<input type="text" class="Form-inputValue u-size10of12" name="documento" />
Expand Down Expand Up @@ -44,4 +52,6 @@
</div>
</div>
<% end %>


</div>
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
<%= render "devise/sessions/new" %>
<% end %>
</div>

</body>
</html>

0 comments on commit fed0147

Please sign in to comment.