In one project, the client wants to share same user credentials between rails app to wordpress site, I’ve worked in the same problem 5 years ago creating a plugin for this, so wordpress change many features and I need this feature fast, googling i find this solution:
rails login this plugin only need a small API for enable login i created this code in model user:
def wp_json
{
user: {
email: self.email,
first_name: self.firstname,
last_name: self.lastname,
description: '',
username: self.usernames,
login: self.email,
nickname: self.firstname,
display_name: "#{self.firstname} #{self.lastname}",
url: 'http://my-wp-installation.com'
}
}
end
and in the rails controller I created this:
def current
session = Session.where(session_id: params[:id]).first
respond_to do |format|
format.json do
if session && session.user
render json: session.user.wp_json
else
render json: { user: '' }.to_json
end
end
end
end
to work this integration the project must need to use database session store.