podigee/device_detector

When using Chrome on a MacBook - returned info is incorrect

Closed this issue · 2 comments

So when running in development, (have not tried it in prod as of yet), When I capture the client data in my password reset controller, info is returning as incorrect? this is how I have implemented the call (it will be refactored later).

  def create
    user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36'
    client = DeviceDetector.new(user_agent)
    @user = User.find_by(email: params[:password_reset][:email].downcase)
    if @user
      @user.create_reset_digest
      PasswordResetDetail.create(
        user_id: @user.id,
        client_name: client.name,
        client_full_version: client.full_version,
        client_os_name: client.os_name,
        client_os_full_version: client.os_full_version,
        client_device_name: client.device_name,
        client_device_type: client.device_type,
        client_is_known: client.known?
      )
      UserMailer.password_reset(@user).deliver_now
      flash[:info] = 'Email sent with password reset instructions'
      redirect_to community_root_url(subdomain: 'community')
    else
      flash.now[:error] = 'Email address not found'
      render 'new'
    end
  end

This is the server output (no errors and aside from the wrong info it works very well!)

Started POST "/password_resets" for 127.0.0.1 at 2020-09-08 16:58:22 -0600
Processing by PasswordResetsController#create as HTML
  Parameters: {"authenticity_token"=>"JAJSpUbqzRKIS/nJ3QO+TFhh8stBF0BzRHdiaDHHpKizKLoAVEY8BhfIRfFlj4o4l6GDbJn4fFVmjOc+/bXWTw==", "password_reset"=>"[FILTERED]"}
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "xxx@xxx-xxx-xxx.com"], ["LIMIT", 1]]
  ↳ app/controllers/password_resets_controller.rb:11:in `create'
   (0.2ms)  BEGIN
  ↳ app/models/user.rb:53:in `create_reset_digest'
  User Update (0.4ms)  UPDATE "users" SET "reset_digest" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["reset_digest", "$2a$12$z9FXWm6sgdYkwCUfhq5ntunOg5yEBFuCdQ8Cd1mUZ44xD5yHI1R9C"], ["updated_at", "2020-09-08 22:58:22.658982"], ["id", 1]]
  ↳ app/models/user.rb:53:in `create_reset_digest'
   (0.8ms)  COMMIT
  ↳ app/models/user.rb:53:in `create_reset_digest'
   (0.1ms)  BEGIN
  ↳ app/models/user.rb:54:in `create_reset_digest'
  User Update (0.5ms)  UPDATE "users" SET "updated_at" = $1, "reset_sent_at" = $2 WHERE "users"."id" = $3  [["updated_at", "2020-09-08 22:58:22.663686"], ["reset_sent_at", "2020-09-08 22:58:22.663494"], ["id", 1]]
  ↳ app/models/user.rb:54:in `create_reset_digest'
   (0.4ms)  COMMIT
  ↳ app/models/user.rb:54:in `create_reset_digest'
   (0.2ms)  BEGIN
  ↳ app/controllers/password_resets_controller.rb:14:in `create'
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/password_resets_controller.rb:14:in `create'
  PasswordResetDetail Create (0.4ms)  INSERT INTO "password_reset_details" ("user_id", "client_name", "client_full_version", "client_os_name", "client_os_full_version", "client_device_type", "client_is_known", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["user_id", 1], ["client_name", "Chrome"], ["client_full_version", "30.0.1599.17"], ["client_os_name", "Windows"], ["client_os_full_version", "8"], ["client_device_type", "desktop"], ["client_is_known", true], ["created_at", "2020-09-08 22:58:22.671077"], ["updated_at", "2020-09-08 22:58:22.671077"]]
  ↳ app/controllers/password_resets_controller.rb:14:in `create'
   (0.4ms)  COMMIT
  ↳ app/controllers/password_resets_controller.rb:14:in `create'
  PasswordResetDetail Load (0.5ms)  SELECT "password_reset_details".* FROM "password_reset_details" WHERE "password_reset_details"."user_id" = $1 ORDER BY "password_reset_details"."id" DESC LIMIT $2  [["user_id", 1], ["LIMIT", 1]]
  ↳ app/mailers/user_mailer.rb:31:in `password_reset'
  CACHE PasswordResetDetail Load (0.1ms)  SELECT "password_reset_details".* FROM "password_reset_details" WHERE "password_reset_details"."user_id" = $1 ORDER BY "password_reset_details"."id" DESC LIMIT $2  [["user_id", 1], ["LIMIT", 1]]
  ↳ app/mailers/user_mailer.rb:32:in `password_reset'
UserMailer#password_reset: processed outbound mail in 4.8ms
Breadcrumb ActionMail delivered meta_data from:Mail::AddressContainer has been dropped for having an invalid data type
Breadcrumb ActionMail delivered meta_data date:DateTime has been dropped for having an invalid data type
Delivered mail 5f580c8ea6023_dc905c6c37049@MacBook-Pro.local.mail (381.5ms)
Date: Tue, 08 Sep 2020 16:58:22 -0600
From: xxx-xxx@xxx-xxx-xxx.com
Reply-To: xxx@xxx-xxx-xxx.com
To: xxxx@xxx-xxx-xxx.com
Message-ID: <5f580c8ea6023_dc905c6c37049@MacBook-Pro.local.mail>
Subject: Postmark Template: "user-password-reset"
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
postmark-template-alias: user-password-reset

This message is using a Postmark template.

Alias: "user-password-reset"
Model:
{
  "name": "xxxx",
  "action_url": "http://community.lvh.me:3000/password_resets/0sScCHal3P7Zu_1xHfJWdA/edit?email=xxx%xxx-xxx-xxx.com",
  "device_name": "Desktop",
  "operating_system": "Windows",
  "support_url": "xxx@xxx-xxx-xxx.com"
}

Use the #prerender method on this object to contact the Postmark API to pre-render the template.

Cheers,
Your friends at Postmark
Redirected to http://community.lvh.me:3000/
Completed 302 Found in 684ms (ActiveRecord: 4.8ms | Allocations: 15911)

]

I am currently running a macbook pro, with macOS Catalina (v10.15.6)

Is my implementation buggered up or am I doing something wrong?

Hey! I'm not involved with this gem other than using it. What exactly seems to be incorrect? The user agent you are parsing seems to be detected correctly by DeviceDetector: Chrome 30 on Windows 8.

Hi TheMindlessDevCanada,

I had a look at the user agent you provided and everything is working well in the device_detector gem:

user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36'
client = DeviceDetector.new(user_agent)
client.name
=> "Chrome"
client.full_version
=> "30.0.1599.17"
client.os_name
=> "Windows"
client.os_full_version
=> "8"
client.device_name
=> nil
client.device_type
=> "desktop"
client.known?
=> true

So you are probably encountering an issue at another place in your code.