Invalid email or password with Devise and Strong Parameters on Admin model

221 views
Skip to first unread message

hyperrjas

unread,
Mar 21, 2013, 10:33:19 AM3/21/13
to plataforma...@googlegroups.com
I have the problem with devise `admin` model. However with `user` model my app is working fine:

This is my admin model:

    class Admin
      include Mongoid::Document
      devise :database_authenticatable, :trackable, :timeoutable
    
      field :email,              :type => String, :default => ""
      field :encrypted_password, :type => String, :default => ""
    
      validates_presence_of :email, :role, :password, :password_confirmation
      validates_presence_of :encrypted_password
      validates_uniqueness_of :email, :case_sensitive => false
    
      ## Trackable
      field :sign_in_count,      :type => Integer, :default => 0
      field :current_sign_in_at, :type => Time
      field :last_sign_in_at,    :type => Time
      field :current_sign_in_ip, :type => String
      field :last_sign_in_ip,    :type => String
    
      #ROLES = %w[admin superadmin]
      field :role, :type => String
    end

I create a first admin with:

    Admin.create! created_at: Time.now, email: "em...@email.com", password: "11111111", password_confirmation: "11111111"

This is my devise controller `admins/sessions_controller.rb`

    class Admins::SessionsController < Devise::SessionsController
     #
     #
     #
    end

This is my `route.rb`

    MyApp::Application.routes.draw do
      devise_for :admins, :controllers => { :sessions => "admins/sessions" }
      namespace :admin do
       get '', to: 'dashboard#index', as: '/'
      end
    end

This is my view `admins/sessions/new.html.erb`

    <h2>Sign in</h2>
    <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
      <div class="form-inputs">
        <%= f.input :email, :required => true %>
        <%= f.input :password, :required => true } %>
        <%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
      </div>
      <%= f.button :submit, "Sign in" %>
    <% end %>

This is my `config/initalizers/strongs_parameters.rb`

    Mongoid::Document.send(:include, ActiveModel::ForbiddenAttributesProtection)

When I enter my username and password I can not login on admin panel and I get the error `Invalid email or password`. I get in my log:

**Completed 401 Unauthorized in 1ms**

**Where have I the problem? What am I doing wrong?**

Lucas Mazza

unread,
Mar 21, 2013, 10:57:55 AM3/21/13
to plataforma...@googlegroups.com
Hard to tell from here. Can you push an application to GitHub that replicates this problem?


--
 
---
You received this message because you are subscribed to the Google Groups "Devise" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

hyperrjas

unread,
Mar 21, 2013, 12:19:00 PM3/21/13
to plataforma...@googlegroups.com
I don't know that I was doing wrong, but I have removed all admin objects, and I have restarted, console and server and now is working fine :O

Thank you very much
Reply all
Reply to author
Forward
0 new messages