FIX: better accept invite flow when user is invited via a link

This commit is contained in:
Arpit Jalan
2019-01-07 14:22:08 +05:30
parent 77d947701c
commit e0bc82657b
5 changed files with 18 additions and 14 deletions

View File

@@ -47,16 +47,19 @@ class InvitesController < ApplicationController
begin
user = invite.redeem(username: params[:username], name: params[:name], password: params[:password], user_custom_fields: params[:user_custom_fields])
if user.present?
log_on_user(user)
log_on_user(user) if user.active?
post_process_invite(user)
end
topic = user.present? ? invite.topics.first : nil
response = { success: true }
if user.present? && user.active?
topic = invite.topics.first
response[:redirect_to] = topic.present? ? path("#{topic.relative_url}") : path("/")
else
response[:message] = I18n.t('invite.confirm_email')
end
render json: {
success: true,
redirect_to: topic.present? ? path("#{topic.relative_url}") : path("/")
}
render json: response
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
render json: {
success: false,