Device Mail Authentication Not Enabled

Asked 2 years ago, Updated 2 years ago, 116 views

I am using Device for user authentication.I want to enable mail authentication (:confirmable), but for some reason I can't.
At the moment, I can sign up and log in, but I can't just authenticate by email.
I would appreciate it if you could give me a solution or just a solution tip.


Place the device in the gem.

gem 'device'
$ bundle install
$ bundle exec rails generate device —install

Outgoing Mail Settings

<config/environments/development.rb>
config.action_mailer.default_url_options={:host=>'localhost:3000'}
config.action_mailer.delivery_method=: smtp

config.action_mailer.smtp_settings={
  :address=>"smtp.gmail.com",
  —port=>587,
  —user_name=>',
  —password=>',
  —authentication=>'cram_md5',
  —enable_starttls_auto=>true
  }

Add a column for Device mail authentication to the User model

<db/migrate/****_device_create_users.rb>
## Confirmable
t.string —Confirmation_token
t.datetime:confirmed_at
t.datetime:confirmation_sent_at
t.string —Unconfirmed_email 

$rakedb:create

Specify:confirmable as the argument for the device method for the User model.

<app/models/user.rb>
revise:database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable

Specify devices in the routes file

<config/routes.rb>
device_for —users

When you register as a user from the Signup screen, no email is sent and it is suddenly authenticated and entered the system.

Skip_confirmation! to skip authentication mail does not hit.

$grep-r skip_confirmation!* 

If you look at the User record, everything you need to enter for mail authentication is nil.

[2]pry(main)>User.last
=> #<User id: 13, email: "[email protected]", encrypted_password: "...", sign_in_count: 1, current_sign_in_at: "2015-06-10 06:38:43", last_sign_in_at: "2015-06-10 06:38:43", confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, created_at: "2015-06-10 06:38:43", updated_at: "2015-06-10 06:38:43">

Looking at the log, there is no sign of sending an email.

[no_token] Processing by Users::RegistrationsController #create as HTML
[no_token]   Parameters: {"utf8"=>" "", "authenticity_token"=>"iLnOw9NgUzjUHOGmF7X2ejvlfxbjyNqSe4NNBZVbltE=", "user"=>{"name"=>"pozedi","="FITER">[email protected]
[no_token] (0.6ms) BEGIN
[no_token] User Exists (0.7ms) SELECT1 AS one FROM "users" WHERE" users". "email" = '[email protected]' LIMIT1
[no_token] User Exists (0.8ms) SELECT1 AS one FROM "users" WHERE ("users". "email" = '[email protected]' AND "users". "deleted_at" IS NULL) LIMIT1
[no_token] User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users". "deleted_at" IS NULL AND "users". "auth_token" = '3TF5yoyxZjJdsKz12d-u'ORDER BY"users".id"ASCLIMIT1
[no_token]   SQL (0.8ms)  INSERT INTO "users" ("auth_token", "created_at", "email", "encrypted_password", "metadata", "name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["auth_token", "3TF5yoyxZjJdsKz12d-u"], ["created_at", "2015-06-10 06:38:43.365969"], ["email", "[email protected]"], ["encrypted_password", "$2a$10$3GLpAyPdHupojLx2fRF4aO4PxCWLcJ/MTx6n.T3qNOapXd2OQgUIu", "metadata", "{}", "name", "pozedi", "updated_at", "2015-06-1006:38:43.365969"]]
[no_token] (0.9ms) COMMIT
[no_token] (0.6ms) BEGIN
[no_token]   SQL (1.0ms)  UPDATE "users" SET "current_sign_in_at" = $1, "current_sign_in_ip" = $2, "last_sign_in_at" = $3, "last_sign_in_ip" = $4, "metadata" = $5, "sign_in_count" = $6, "updated_at" = $7 WHERE "users"."id" = 13  [["current_sign_in_at", "2015-06-10 06:38:43.417435"], ["current_sign_in_ip", "127.0.0.1/32"], ["last_sign_in_at", "2015-06-10 06:38:43.417435"], ["last_sign_in_ip", "127.0.0.1/32", ["metadata", "{}", ["sign_in_count", 1], ["updated_at", "2015-06-1006:38:43.431023"]]
[no_token] (1.0ms) COMMIT
[no_token] Redirected to http://localhost:3000/users/13
[no_token] Completed 302 Found in 310 ms (ActiveRecord: 7.3 ms)

Why!?

ruby-on-rails ruby devise

2022-09-30 20:14

1 Answers

If you want to use Gmail for outgoing mail settings, you must lower the security settings on the Gmail side.
I think I couldn't send you an email.
It seems that the email has been sent with the following settings.

Create Project

$rails new sample

Modifying Gemfile

gem 'device'

Preparing pages for routes

$bundle install
$ rails generate device —install
$ railsg controller Pages index
$ railsg device User

development.rb

config.action_mailer.default_url_options={host:'localhost', port:3000} 
config.action_mailer.delivery_method=: smtp
config.action_mailer.smtp_settings={  
    :address=>"smtp.gmail.com", 
    —port=>587,
    —user_name=>"mail address",
    —password=>"password",
    —authentication=>:plain, 
    —enable_starttls_auto=>true
}

user.rb

device:database_authenticatable, :registerable,
       :recoverable, :confirmable, :rememberable, :trackable, :validatable

routes.rb

device_for:users
root'pages#index'

revise.rb

config.reconfirmable=false

YYYYMMDDXXXXXX_device_create_users.rb

 t.string:confirmation_token
t.datetime:confirmed_at
t.datetime:confirmation_sent_at
t.string —Unconfirmed_email

Set the above to

$rakedb:migrate
$ rails server


with the Gmail account that I used to development.rb Enable insecure apps


2022-09-30 20:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.