Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
countable committed Jun 28, 2016
2 parents 1d37867 + cbe09a1 commit cf036fd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
36 changes: 12 additions & 24 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def retrieve_password

if @user
Notifications.reset_password(@user).deliver
render :password_sent, layout: 'application'
render :password_sent, layout: 'basic'
else
flash.now[:notice] = t('emails.reset_password.retrieval_failed')
render :forgot_password, layout: 'application'
render :forgot_password, layout: 'basic'
end
end

Expand Down Expand Up @@ -112,36 +112,24 @@ def reset_password
end
end

# ---------------------------------------------------------------------- login
def login
if authenticated?
redirect_to :locations
redirect_to '/admin'
else
render :login, layout: get_layout
render :login, layout: 'basic'
end
end

def login_post
authenticate(:user)

if authenticated?
respond_to do |format|
format.html do
redirect_to(params[:return_url] || :locations) # , :notice => t('auth.signed_in')
end
format.json do
render json: { success: 1, user: current_user }
end
end
params[:email] = User.first.email
u = User.find_by( email: params[:email] )
if u && u.valid_password?( params[:password] )
session[:admin_user_id] = u.id
redirect_to '/admin'
else
respond_to do |format|
format.html do
flash[:notice] = t('auth.invalid')
render :login, status: 401, layout: 'application'
end
format.json do
render json: { success: 0, user: nil, error: I18n.t('accounts.unauthenticated'), warden: warden.message }
end
end
flash[:error] = "Your email or password was incorrect."
render 'login', layout: 'basic'
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def authenticate!
raise UnauthenticatedError unless current_user
end

def authenticated?
session[:admin_user_id] && User.find_by( session[:admin_user_id] )
end


# Authorizes the user to access resource
#
# @return [nil]
Expand Down
4 changes: 2 additions & 2 deletions app/views/accounts/_login.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% return_url = nil if local_assigns[:return_url].nil? %>

<%= User.pluck( :email ).inspect -%>
<%= form_tag :login_post, :class => 'form-horizontal' do %>
<fieldset>
<div class="control-group">
Expand All @@ -15,7 +15,7 @@
<div class="input-prepend">
<%= password_field_tag :password %>
<p class="help-block">
<%= link_to 'Forgot Password', :forgot_password %>
<%= link_to 'Forgot Password', admin_forgot_password_path %>
</p>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions app/views/accounts/forgot_password.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<div class="container-fluid">
<div class="container">
<%= error_messages_for @user %>

<div class="page-header">
<h1><%= t('passwords.forgot') %></h1>
</div>

<p><%= t('passwords.reset_message') %></p>

<%= form_for User.new, :url => :retrieve_password do |form| %>
<%= form_for User.new, :url => :admin_retrieve_password do |form| %>
<div class="fieldset.form-horizontal">
<div class="control-group">
<%= label_tag :email, nil, :class => 'control-label' %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/accounts/login.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

<div class='detail-page standalone'>
<div class="container-fluid" id="locations-admin-list">
<div class="container">
<div class="page-header">
Expand All @@ -11,3 +13,4 @@
<% end %>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

devise_for :users

get '/admin/login' => 'accounts#login'
get '/admin/forgot_password' => 'accounts#forgot_password', as: 'admin_forgot_password'
post '/admin/forgot_password' => 'accounts#forgot_password'
get '/admin/forgot_password' => 'accounts#forgot_password', as: 'admin_retrieve_password'
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
mount RailsAdminImport::Engine => '/rails_admin_import', as: 'rails_admin_import'

Expand Down

0 comments on commit cf036fd

Please sign in to comment.