Devise case insensitive email when login - ruby-on-rails-3

I'm using postgresql
Devise stores emails in db with downcase:
config.case_insensitive_keys = [ :email ]
But when i login with uppercased email - i got error that email is wrong.
I find solition for this, but this have 1 trouble:
def self.find_for_authentication(conditions = {})
# Allow to log in with case insensitive email
conditions[:email].downcase!
end
1) When I try to logged in with wrong uppercased email I got error and my email with downcase. (logged with AAA#bbb.CCC, got aaa#bbb.ccc, but i need to show AAA#bbb.CCC). How can I change this behaviour ?

I am not sure I get you but you should be able to access the original email
you supplied by
conditions[:email]
Or once logged in you could access the email of the logged in user via
self.email.
Let me know if this helps

Solution was really simple. What you need is just copy params hash and change email in this hash when login, but when user got exception - we just return original hash with entered params
def self.find_for_authentication(conditions = {})
# Allow to log in with case insensitive email
new_hash = conditions.dup
new_hash[:email] = conditions[:email].downcase
where(new_hash).first
end

Related

Create user in Readers Account Snowflake

I have created a share and added that share to a reader account.
Now I have executed a create user statement there in the reader account i.e.
CREATE or replace USER client_test
PASSWORD = 'Client4321'
LOGIN_NAME = 'client'
DISPLAY_NAME = 'client test'
FIRST_NAME = 'client'
LAST_NAME = 'test'
EMAIL = 'mukul.kumar#gmail.com'
DEFAULT_ROLE = sysadmin;
This statement gets executed without any error and also I can see the user details under the account tab in snowflake UI
but still, when I am trying to login into this newly created user, there is an error of incorrect username or password coming up.
Is creating a user in a reader account not allowed or anything like there in snowflake?
I haven't found documentation on this as such. It will be appreciated if anyone helps me out with this.
The issue here is that the login_name is the one which should be used for logging in to the SF application. Use "client" and "Client4321" to login and it will be successful.

Parameterisation for login feature in Karate

I want to parameterise the login feature file so that is can be used for multiple user credentials. Can anyone please help me here? Below is the code that I am using:
Given url baseUrl
And form field username = 'admin'
And form field password = 'admin'
When method GET
Then status 200
I want to parameterise the value for username and password so that it can be passed from another feature file and can be reused again.

Rails 3/Devise - Change Error Message for Password Reset

I am working with a Rails 3 App and am needing to adjust the error message on the password resent view. If a user types in an email address and submits it, currently, the app will display this error message:
Email not found
I am needing to change this error message to this:
We don't have an account with that e-mail address. Maybe you used another address?
I know that you can adjust this in the Devise YML file, but am not sure how to do this... any suggestions?
Working Code
class PasswordsController < Devise::PasswordsController
def create
user = User.find_by_email(params[:user][:email])
if user.nil?
flash.now[:notice] = "We don't have an account with that e-mail address. Maybe you used another address?"
end
super
end
end
You could try using a before_filter that checks if the email exists in the datbase and if not the it redirects you to the password reset form with a flash notice

how to process incoming mails using mailman and update them into the database

am developing ruby on rails3 application where i am sending an email to user and if user replies that email then that reply content, date should be updated to the database. For this i have ProductComment model. when admin sends comment to the user it will be stored in the database. if user replies to that then database should be updated accordingly. I am trying to use mailman. I have installed the gem. But am not getting how to get the comment id, what should i write in replyto address, where to write the mailman code and from which mail i should read.
Am sending email like this:
mail(:to => #user.email, :subject => "Edit Your Product", :reply_to=>"abc#syz.com)
I am handling it in products controller like this:
require 'mailman'
Mailman::Application.run do
to 'abc#xyz.com' do
ProductComment.create(message)
end
end
Please help me to come out from this problem
Please tell me how to use mailman gem in ruby on rails3 application
there is a recent pro-episode on receiving emails with mailman on railscasts: http://railscasts.com/episodes/313-receiving-email-with-mailman
chmod +x script/mailman_server
cat mailman_test.eml | script/mailman_server
script/mailman_server
-
# script/mailman_server
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.pop3 = {
server: 'pop.gmail.com', port: 995, ssl: true,
username: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
Mailman::Application.run do
default do
begin
Ticket.receive_mail(message)
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end
-
def self.receive_mail(message)
ticket_id = message.subject[/^Update (\d+)$/, 1]
if ticket_id.present? && Ticket.exists?(ticket_id)
Ticket.update(ticket_id, body: message.body.decoded)
else
Ticket.create subject: message.subject, body: message.body.decoded, from: message.from.first
end
end
Postmark Inbound is a good choice. Setup like so:
Sign up for Postmark, they will give you an email which Postmark will assign to your account.
Sign up for Google Apps branded Gmail for your domain. Set up forwarding from an account to the Postmark email address. People can now email reply#yourdamin.com, and it will be forwarded to Postmark.
Create a callback URL. When Postmark receives an email it will package it up and post it to your callback. You can then access the email attributes via the params hash.
To implement replying to messages, simply add a reply to field to your outgoing message which contains a unique hash for the message, e.g.
reply+uniquehash#yourdomain.com.
This is a legal email address, and will be sent to reply#yourdomain.com. You can then parse out the hash in your callback and use it to match the reply to the original message.
Simple :)

How to change email address of a user in devise "safely"?

By default, devise uses an email address for sign up and sign in.
But I want that the email address should be allowed to be changed by the user.
If I allow the user to edit the email address, and the user specifies an "incorrect" (i.e. a typo by mistake) email address and then user signs out, and the user also forgets what the typo'ed email was, now the user account is inaccessible by the user!
How to best work around this? (except for creating a separate, unchangeable username field that will always allow user to login)
You can force the user to confirm his account again if he changes his email.
Once, you updated the password of the concerned user, you need to un-confirm the user, and then re-send the confirmation email.
To unconfirm the user :
user = User.find(1)
if user.confirmed?
user.confirmed_at = nil
user.save(:validate => false)
end
To resend the email confirmation :
user = User.find(1)
user.send_confirmation_instructions
Hope this help !
Devise does this out of the box. Here is the info from the initializer:
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
In confirmable module you may see how it works.