Added user invitation email support.
This commit is contained in:
parent
a0f3235e94
commit
a9b1e4c8a5
|
@ -160,9 +160,47 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type
|
||||||
# send inviteation if needed
|
# send inviteation if needed
|
||||||
if params[:invite]
|
if params[:invite]
|
||||||
|
|
||||||
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
|
# generate token
|
||||||
# exit '123'
|
token = Token.create( :action => 'PasswordReset', :user_id => user.id )
|
||||||
|
|
||||||
|
# send mail
|
||||||
|
data = {}
|
||||||
|
data[:subject] = 'Invitation to #{config.product_name} at #{config.fqdn}'
|
||||||
|
data[:body] = 'Hi {user.firstname},
|
||||||
|
|
||||||
|
I (#{current_user.firstname} #{current_user.lastname}) invite you to #{config.product_name}.
|
||||||
|
|
||||||
|
Click on the following link and set your password:
|
||||||
|
|
||||||
|
#{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name}
|
||||||
|
|
||||||
|
Enjoy,
|
||||||
|
|
||||||
|
#{current_user.firstname} #{current_user.lastname}
|
||||||
|
|
||||||
|
Your #{config.product_name} Team
|
||||||
|
'
|
||||||
|
|
||||||
|
# prepare subject & body
|
||||||
|
[:subject, :body].each { |key|
|
||||||
|
data[key.to_sym] = NotificationFactory.build(
|
||||||
|
:string => data[key.to_sym],
|
||||||
|
:objects => {
|
||||||
|
:token => token,
|
||||||
|
:user => user,
|
||||||
|
:current_user => current_user,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# send notification
|
||||||
|
NotificationFactory.send(
|
||||||
|
:recipient => user,
|
||||||
|
:subject => data[:subject],
|
||||||
|
:body => data[:body]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
user_new = User.user_data_full( user.id )
|
user_new = User.user_data_full( user.id )
|
||||||
render :json => user_new, :status => :created
|
render :json => user_new, :status => :created
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -59,6 +59,7 @@ module NotificationFactory
|
||||||
def self.send(data)
|
def self.send(data)
|
||||||
sender = Setting.get('notification_sender')
|
sender = Setting.get('notification_sender')
|
||||||
a = Channel::IMAP.new
|
a = Channel::IMAP.new
|
||||||
|
puts "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}"
|
||||||
message = a.send(
|
message = a.send(
|
||||||
{
|
{
|
||||||
# :in_reply_to => self.in_reply_to,
|
# :in_reply_to => self.in_reply_to,
|
||||||
|
|
Loading…
Reference in a new issue