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
Related
I have the gem working for gmail. I can see the list of contacts in
#contacts = request.env['omnicontacts.contacts']
However, when importing via hotmail, the list is empty. I made sure that I do have hotmail contacts. I double checked every settings in my live application (secret key, domain...)
Has anyone had a similar issue ? What can I try to diagnose further ?
My callback controller:
class Oauth::HotmailController < ApplicationController
def callback_token
#this is called.
#This is empty. When using gmail, contacts are retrieved. But not with hotmail
#contacts = request.env['omnicontacts.contacts']
end
end
In your response from hotmail you have encoded emails.
For example: "email_hashes":["243c01e30cfdbc8c46b8dddb68a685bb8f86016096fd3398919ed6845fde6b7b"]
This patch should help:
https://gist.github.com/clouw/5871254
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
I have a list of stories assigned to me in Cucumber, one of them being "Then the user should receive a confirmation email". I think testing that the user receives it is beyond the power of the application, but how can I test that an email had just been sent?
You can use this step definition :
Then "the user should receive a confirmation email" do
# this will get the first email, so we can check the email headers and body.
email = ActionMailer::Base.deliveries.first
email.from.should == "admin#example.com"
email.to.should == #user.email
email.body.should include("some key word or something....")
end
Tested with Rails 3.2
Source
email_spec + action_mailer_cache_delivery gems are your friends for doing this
I would suggest you to verify the last_response after some action ocurrs, like, a user click on a button, or something like that.
Or if you are updating a record after doing something, check for the updated_at attribute to see if it was changed or not.
Check dockyard/capybara-email gem:
feature 'Emailer' do
background do
# will clear the message queue
clear_emails
visit email_trigger_path
# Will find an email sent to test#example.com
# and set `current_email`
open_email('test#example.com')
end
scenario 'following a link' do
current_email.click_link 'your profile'
expect(page).to have_content 'Profile page'
end
scenario 'testing for content' do
expect(current_email).to have_content 'Hello Joe!'
end
scenario 'testing for a custom header' do
expect(current_email.headers).to include 'header-key'
end
scenario 'testing for a custom header value' do
expect(current_email.header('header-key')).to eq 'header_value'
end
scenario 'view the email body in your browser' do
# the `launchy` gem is required
current_email.save_and_open
end
end
Another option is PutsBox. You can send an email to whatever-you-want#putsbox.com, wait for a few seconds (SMTP stuff ins't instantaneous) then check your email via http://preview.putsbox.com/p/whatever-you-want/last.
This post tutorial has some examples.
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 :)
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.