Sign in is not working after confirmable - ruby-on-rails-5.2

I am using devise gem,when i click the link from email Confirm my account after confirmable from email.
My sign in page is not working.

Put this:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
In development.rb file?

Related

How to redirect Subdomain to domain with same url in Rails

I have installed a gem rails_admin in my application now i want to redirect this url eritheia-labs.localhost:3000/admin/dashboard to localhost:3000/admin/dashboard
i wanna access rails admin via localhost:3000/admin instead of eritheia-labs.localhost:3000/admin or if enter this url it will redirect me to localhost:3000/admin
You could add the following to your config/routes.rb
constraints(host: "eritheia-labs.localhost") do
match '/admin/(*path)' => redirect { |params, req|
"http://localhost:3000#{req.fullpath}"
}, via: [:get, :head]
end
and make sure it is before the mount RailsAdmin::Engine line.
This code should redirect any requests for 'http://eritheia-labs.localhost:3000/admin/*path' to 'http://localhost:3000/admin/*path'.
I found another solution that is....
in routes.rb file
authenticate :user, lambda { |u| u.role == "admin" } do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
end
Put this Code Under constraints DomainConstraint do
this will access the rails_admin with localhost:3000/admin only, not with example.localhost:3000/admin

Mailgun::CommunicationError via nginx '301 Moved Permanently' error

I have a Ruby web app that sends email via Mailgun.
My Mailgun account & gem are properly set up and I can send emails manually (via curl, for instance).
The API key and the API base URL (https sandbox domain) are stored in environment variables.
When I attempt to send emails from the app like this:
def initialize(mailer: nil)
#mailer = mailer || Mailgun::Client.new(ENV['MAILGUN_API_KEY'])
end
then:
def call(user)
mailer.send_message(ENV['MAILGUN_SANDBOX'], {from: '...',
to: user.email,
subject: '...',
text: "..."})
end
When I run the app with Sinatra via localhost:xxxx, I get a Mailgun::CommunicationError at /.../... 301 Moved Permanently: ... nginx pointing to this line:
mailer.send_message(ENV['MAILGUN_SANDBOX'], ...
Any idea why that happens? I've researched the issue for hours but couldn't find a clue on what to do next.
Thanks!
I ran into this same issue. If you have already fixed this then hopefully this can help someone else.
I switched over to message builder for ease of use and being able to render my html but I'm pretty sure it will still send with the format you have setup with :text
When I switched over to the proper domain in the .env file I believe it solved my issue. You'll need 2 different domains to use Mailgun. The first is the full domain for your sandbox. ENV['MAILGUN_DOMAIN'] it is the sandbox domain with the full https://api.mailgun.net/v3/sandboxXXXXxxxXXXXXX.mailgun.org to send most of the mail formats.
You'll also need the last half of the full domain to send messages. That's just the sandboxXXXXxxxXXXXXX.mailgun.org which is passed into the MessageBuilder or other message .send_message method. When I had them mixed up or both the same I kept on getting this error. When I switched over to separate the two in my development.rb and some_mailer.rb is when I could send the mail without a problem.
Below is my file setup, for reference. I'm pretty new to all of this but this is how I'm setup and it's working for me so hopefully it helps.
# .env
MAILGUN_DOMAIN='https://api.mailgun.net/v3/sandboxXXXXxxxXXXXXX.mailgun.org'
MAILGUN_SEND_DOMAIN='sandboxXXXXxxxXXXXXX.mailgun.org'
# development.rb
ActionMailer::Base.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "ENV['MAILGUN_DOMAIN']",
:user_name => "ENV['MAILGUN_USERNAME']",
:password => "ENV['MAILGUN_PASSWORD']"
}
# some_mailer.rb
def some_mail_notification(user)
#user = user
mg_client = Mailgun::Client.new ENV['MAILGUN_KEY']
mb_obj = Mailgun::MessageBuilder.new
mb_obj.from "email#testing.com", {'first' => 'Customer', 'last' => 'Support'}
mb_obj.add_recipient :to, #user.email, { 'first' => #user.first_name, 'last' => #user.last_name }
mb_obj.subject "Your Recent Purchase on Some Site"
mb_obj.body_html ("#{render 'some_mail_notification.html.erb'}")
mg_client.send_message("sandboxXXXXxxxXXXXXX.mailgun.org", mb_obj)
end
I left the send_message above to the sandbox domain but you can set that as an environment variable in the .env file.

Symfony confirmation email not send but gmail work

i have some probleme using swiftmailer for setting my confirmation email, normaly everything is set well, but the mail is not sent, and i have my user in my database (but enable is set to 0 of course).
Since i don't have errors show by symfony i suppose it's my gmail account that blocked them, but i already set it to allow other application to use it as a "server", and i have a page that use swiftmailer to send normal mail, and it work fine.
i'm lost, thanks for your future help
My config.yml :
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
encryption: ssl
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
service:
mailer: fos_user.mailer.default
registration:
confirmation:
enabled: true
from_email:
address: maxime.duvey#gmail.com
sender_name: Registration mail
My config.yml :
mailer_transport: gmail
mailer_host: 127.0.0.1
mailer_user: maxime.duvey#gmail.com
mailer_password: XXXXXXXXXXX
i'm really lost, i don't understand why it don't work
It might be because you have to turn on "Less Secure Apps" as gmail allows doesn't allow you to access logins unless it is a secure app that they provide. This can be found in you google admin console.
See the link here for more info
I had the same problem when using PHPMailer.
However if you do decide to turn it on, it is not recommended.
They mention this in the link provided.
now that i think of it, it's maybe my manner to add a new user to my database :
my controler :
$userregister = new User();
$formregister = $this->get('form.factory')->createBuilder(FormType::class, $userregister);
$formregister
->add('firstname', TextType::class)
->add('lastname', TextType::class)
->add('email', EmailType::class)
->add('phonehome', NumberType::class)
->add('phoneportable', NumberType::class)
->add('username', TextType::class)
//->add('Password', PasswordType::class)
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
->add('submit', SubmitType::class);
$form = $formregister->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($userregister);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');
return $this->redirect($this->generateUrl('Contact_Action', array('id' => $userregister->getId())));
}
return $this->render('register.html.twig', array('form'=>$form->createView()));
and my twig :
{{ form(form) }}
i'm not sure, maybe

Action Mailer - Rails 4

I am playing around with action mailer, and I don't understand a couple of things
class MYMailer < ActionMailer::Base
default from: "bar#gmail.com"
....
end
in my production.rb file:
#config.action_mailer.default_url_options = { :host => 'www.example.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 111,
domain: 'gmail.com',
user_name: 'foo#gmail.com',
password: 'foobar',
authentication: 'plain',
enable_starttls_auto: true }
1) First of all what is this default from: "bar#gmail.com" ?
The from value is read from my production file, and I receive emails from foo#gmail.com. So what is the point of default from: "bar#gmail.com"
2) Second what is the point of #config.action_mailer.default_url_options = { :host => 'www.example.com' } ? I read something on the official guides but I didn't get it. My app still sends email without it..
Thanks
1) Gmail Api Do not support sent email from different adress(protect from spam/spoof)
2) Rails can send email from self application and this options tell him what host use.

ActiveAdmin not sending password confirmation instructions

I recently installed ActiveAdmin and I am working on the User model. After I created the initial AdminUser I tried adding another AdminUser and its supposed to send an email to set up the password but it fails to send the email.
I have this code in my config/development folder
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
and this in my AdminUser model
after_create { |admin| admin.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
Not sure why its not sending the email for me to change my password.
You are getting problem because you didn't configure any server to go out an emails.
You are on right path. just add following things.
Please add following line to app/Gemfile and run bundle install.
gem "letter_opener"
and then add following line to config/enviornments/development.rb
config.action_mailer.delivery_method = :letter_opener
Above code will help you to see the result in the browser itself, doesn't actually sends the email.
To send an actual email you need to change following line and need to add smtp code.(smtp server)
config.action_mailer.delivery_method = :smtp
Then add following lines below above line:
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => 'gmail',
:user_name => 'gmail username',
:password => 'gmail password',
:authentication => 'plain',
:enable_starttls_auto => true
}

Resources