There is a way for create users without email with Devise?
I'm creating a single sign-on with Tumblr, Omniauth and Devise When accept on Tumblr dialog, it returns:
NoMethodError in Users::OmniauthCallbacksController#tumblr
undefined method `email' for #<User:0x00007f8835e4e110>
Tumblr don't provide email from their users on the whole hash.
Solved!
I used this devise: not requiring email
Then, removing from user model :validatable and this two methods:
def email_required?
false
end
def email_changed?
false
end
Related
I’m using Rails 4.2.1 and Devise and rails_admin and I’m quite new to Rails.
I have a user model in the project and a login module for the users. But I need to add Rails Admin authentication. I added a new model Admin for the purpose. I have already set up basic authentication for the Rails Admin login. But now I need to remove basic authentication and add a login page for Rails Admin. What changes do I have to do?
As for my code, I am currently using this for basic authentication:
RailsAdmin.config do |config|
config.authenticate_with do
authenticate_or_request_with_http_basic('Site Message') do |username, password|
authenticate_admin username, password
end
end
end
I have added a method authenticate_admin in application_controller that I want to use for authentication instead.
As you are using devise with rails admin, you can use devise for the authentication.
In your rails_admin.rb add the following code:
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
I currently have an app that allows users to invite other users to their organization. How can I make it so that devise will send a reset password link to the users that have been invited?
Add recoverable and use the send_reset_password_instructions method.
class User < ActiveRecord::Base
devise :recoverable
...
end
User.find(1).send_reset_password_instructions
I want to configure devise to send a confirmation email when the user has changed their password as a security measure. I'd prefer to re-use my devise mailers if possible. Any ideas how to do this?
Untested, but I'd try to do this within your User model with a simple after_update callback:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable # whatever
after_update :send_password_changed_notification
# attr_accessible, validations, ...
private
def send_password_changed_notification
# Send email with the mailer of your choice,
# e. g. your existing custom Devise mailer:
YourDeviseMailer.password_changed_notification(self).deliver if password_changed?
end
end
I would configure the update user action, you can read on how to do that in their documentation. Check how devise handles confirmations of new registered users in registration action and re-use that code in your new reset password action.
Recently I added the confirmable module to my User class. I already have a quite nice mailing system (Sidekiq, Sendgrid...) in my app, so I created my own "confirm account" mail. The problem now is to disable Devise from sending its default email. Is there any way to completely disable the Devise mailing system?
Added:
I want to maintain the confirmable module, as I am using its attributes and routes.
I can't use skip_confirmation! because I want the users to confirm their account.
I just want to disable Devise mails.
Use the source, Luke:
# lib/devise/models/confirmable.rb
# A callback method used to deliver confirmation
# instructions on creation. This can be overriden
# in models to map to a nice sign up e-mail.
def send_on_create_confirmation_instructions
send_devise_notification(:confirmation_instructions)
end
So override this method in your model to do nothing.
Try overriding the following devise method in your model:
def confirmation_required?
!confirmed?
end
or use skip_confirmation!:
user = User.new(params)
user.skip_confirmation!
user.save!
Use skip_confirmation! method before saving any object.
def create
#user = User.new(params[:user])
#user.skip_confirmation!
#user.save!
end
I think just removing
:confirmable
from the user model should do it
or have you tried disabling
config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
I recommend you
User.skip_reconfirmation!
That is skip confirm mail and update email not to use "confirm!"
remove (:confirmable) from devise model
ex:- here my devise model is User
here I used like this.
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,:omniauthable
end
I followed Ryan Bates'/RailsCasts tutorial for cookies login and remind me functionality in an application I am building.
[reference: http://railscasts.com/episodes/274-remember-me-reset-password?view=comments]
I wanted to introduce his OmniAuth functionality for the same application.
[reference: http://railscasts.com/episodes/235-omniauth-part-1]
I'm not using devise. I am correctly loading the Twitter app page, the error occurs when redirecting back to my application. I have the callback URL correctly set within Twitter.
I am getting an undefined method "authentications" for nil:NilClass error with OmniAuth and my authentications_controller. Specifically my console reads:
NoMethodError (undefined method authentications for nil:NilClass):app/controllers/authentications_controller.rb:9:in create'.
Here is the Authentications Controller code:
class AuthenticationsController < ApplicationController
def index
authentications = Authentication.all
end
def create
auth = request.env["omniauth.auth"]
current_user.authentications.create(:provider => auth['provider'], :uid => auth['uid'])
flash[:notice] = "Authentication was successful."
redirect_to authentications_url
end
Here is the current_user helper method in my Applications Controller.
private
def current_user
#current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
end
helper_method :current_user
User has many authentications.
Authentications belong to user.
I'd like to enable OmniAuth to work with Twitter so users can login with their Twitter account by avoiding the error I am receiving while maintaining my current_user code
Help is appreciated.
You're not taking into account the case where the user is not logged in.
What you're doing in your create action is associating the user's account on your site to his account on Twitter.
You can't use current_user without making sure that the user is logged in. Otherwise it will return nil, and that's why it's saying undefined method authentications for nil:NilClass.
Take a look at the next railscast that goes into more details: http://railscasts.com/episodes/236-omniauth-part-2