Last active
August 29, 2015 14:04
-
-
Save AhmedNadar/9d177a59a701a96d48a3 to your computer and use it in GitHub Desktop.
Create Admin Users with Active Admin using email only!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As admin you can create other Admin Users with thier email only where password link is sent via email | |
# 1- Gemfile | |
gem 'devise' | |
gem 'activeadmin', github: 'gregbell/active_admin' | |
# 2- Install Devise then Active Admin | |
rails g devise:install | |
rails g active_admin:install | |
# You might see other instructions inthe terminal, just follow them | |
# Type Yes for override user modle | |
# 3- migrate | |
rake db:migrate | |
# 4- Update Admin User form: 'app/admin/admin_user.rb' | |
# Basicly comment password and confirm_password inputs | |
form do |f| | |
f.inputs "Admin Details" do | |
f.input :email | |
end | |
f.actions | |
end | |
# 5- Admin can created by email only without a password | |
# creat_after sends email to the Admin's email with a link to create a password | |
after_create { |admin| admin.send_reset_password_instructions } | |
def password_required? | |
new_record? ? false : super | |
end | |
# 6- Then we need to update our mailr default URL in development here, 'config/environments/development.rb' | |
config.action_mailer.default_url_options = { :host => 'localhost:3000' } | |
# For sure send email will fail, because we need to setup a Mailer for the email to be sent, | |
# check Action Mailer (http://guides.rubyonrails.org/action_mailer_basics.html) | |
# But we can view the email content on the terminal. | |
# Example below: | |
# Rendered devise/mailer/reset_password_instructions.html.erb (2.7ms) | |
# Devise::Mailer#reset_password_instructions: processed outbound mail in 53.7ms | |
# Sent mail to [email protected] (56.9ms) | |
# Date: Thu, 17 Jul 2014 10:42:36 +0000 | |
# From: [email protected] | |
# Reply-To: [email protected] | |
# To: [email protected] | |
# Message-ID: <[email protected]> | |
# Subject: Reset password instructions | |
# Mime-Version: 1.0 | |
# Content-Type: text/html; | |
# charset=UTF-8 | |
# Content-Transfer-Encoding: 7bit | |
# <p>Hello [email protected]!</p> | |
# <p>Someone has requested a link to change your password. You can do this through the link below.</p> | |
# <p><a href="http://localhost:3000/admin/password/edit?reset_password_token=yzJaaaefefsofskjsddfdfdkNss">Change my password</a></p> | |
# <p>If you didn't request this, please ignore this email.</p> | |
# <p>Your password won't change until you access the link above and create a new one.</p> | |
# It works :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment