1
|
|
|
# frozen_string_literal: true |
2
|
|
|
|
3
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
4
|
|
|
# |
5
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). |
6
|
|
|
# |
7
|
|
|
# This program is free software; you can redistribute it and/or modify it under the |
8
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software |
9
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later |
10
|
|
|
# version. |
11
|
|
|
# |
12
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
13
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
14
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU Lesser General Public License along |
17
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
module Emailer |
20
|
|
|
extend ActiveSupport::Concern |
21
|
|
|
|
22
|
|
|
# Sends account activation email. |
23
|
|
View Code Duplication |
def send_activation_email(user) |
|
|
|
|
24
|
|
|
begin |
25
|
|
|
return unless Rails.configuration.enable_email_verification |
26
|
|
|
|
27
|
|
|
UserMailer.verify_email(user, user_verification_link(user), @settings).deliver |
28
|
|
|
rescue => e |
29
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
30
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
31
|
|
|
else |
32
|
|
|
flash[:success] = I18n.t("email_sent", email_type: t("verify.verification")) |
33
|
|
|
end |
34
|
|
|
end |
35
|
|
|
|
36
|
|
|
# Sends password reset email. |
37
|
|
View Code Duplication |
def send_password_reset_email(user) |
|
|
|
|
38
|
|
|
begin |
39
|
|
|
return unless Rails.configuration.enable_email_verification |
40
|
|
|
|
41
|
|
|
UserMailer.password_reset(user, reset_link(user), @settings).deliver_now |
42
|
|
|
rescue => e |
43
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
44
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
45
|
|
|
else |
46
|
|
|
flash[:success] = I18n.t("email_sent", email_type: t("reset_password.subtitle")) |
47
|
|
|
end |
48
|
|
|
end |
49
|
|
|
|
50
|
|
View Code Duplication |
def send_user_promoted_email(user, role) |
|
|
|
|
51
|
|
|
begin |
52
|
|
|
return unless Rails.configuration.enable_email_verification |
53
|
|
|
|
54
|
|
|
UserMailer.user_promoted(user, role, root_url, @settings).deliver_now |
55
|
|
|
rescue => e |
56
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
57
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
58
|
|
|
end |
59
|
|
|
end |
60
|
|
|
|
61
|
|
View Code Duplication |
def send_user_demoted_email(user, role) |
|
|
|
|
62
|
|
|
begin |
63
|
|
|
return unless Rails.configuration.enable_email_verification |
64
|
|
|
|
65
|
|
|
UserMailer.user_demoted(user, role, root_url, @settings).deliver_now |
66
|
|
|
rescue => e |
67
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
68
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
69
|
|
|
end |
70
|
|
|
end |
71
|
|
|
|
72
|
|
|
# Sends inivitation to join |
73
|
|
|
def send_invitation_email(name, email, token) |
74
|
|
|
begin |
75
|
|
|
return unless Rails.configuration.enable_email_verification |
76
|
|
|
|
77
|
|
|
UserMailer.invite_email(name, email, invitation_link(token), @settings).deliver_now |
78
|
|
|
rescue => e |
79
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
80
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
81
|
|
|
else |
82
|
|
|
flash[:success] = I18n.t("administrator.flash.invite", email: email) |
83
|
|
|
end |
84
|
|
|
end |
85
|
|
|
|
86
|
|
View Code Duplication |
def send_user_approved_email(user) |
|
|
|
|
87
|
|
|
begin |
88
|
|
|
return unless Rails.configuration.enable_email_verification |
89
|
|
|
|
90
|
|
|
UserMailer.approve_user(user, root_url, @settings).deliver_now |
91
|
|
|
rescue => e |
92
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
93
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
94
|
|
|
else |
95
|
|
|
flash[:success] = I18n.t("email_sent", email_type: t("verify.verification")) |
96
|
|
|
end |
97
|
|
|
end |
98
|
|
|
|
99
|
|
View Code Duplication |
def send_approval_user_signup_email(user) |
|
|
|
|
100
|
|
|
begin |
101
|
|
|
return unless Rails.configuration.enable_email_verification |
102
|
|
|
|
103
|
|
|
admin_emails = admin_emails() |
104
|
|
|
UserMailer.approval_user_signup(user, admins_url, admin_emails, @settings).deliver_now unless admin_emails.empty? |
105
|
|
|
rescue => e |
106
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
107
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
108
|
|
|
end |
109
|
|
|
end |
110
|
|
|
|
111
|
|
View Code Duplication |
def send_invite_user_signup_email(user) |
|
|
|
|
112
|
|
|
begin |
113
|
|
|
return unless Rails.configuration.enable_email_verification |
114
|
|
|
|
115
|
|
|
admin_emails = admin_emails() |
116
|
|
|
UserMailer.invite_user_signup(user, admins_url, admin_emails, @settings).deliver_now unless admin_emails.empty? |
117
|
|
|
rescue => e |
118
|
|
|
logger.error "Support: Error in email delivery: #{e}" |
119
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
120
|
|
|
end |
121
|
|
|
end |
122
|
|
|
|
123
|
|
|
private |
124
|
|
|
|
125
|
|
|
# Returns the link the user needs to click to verify their account |
126
|
|
|
def user_verification_link(user) |
127
|
|
|
edit_account_activation_url(token: user.activation_token, email: user.email) |
128
|
|
|
end |
129
|
|
|
|
130
|
|
|
def admin_emails |
131
|
|
|
admins = User.all_users_with_roles.where(roles: { role_permissions: { name: "can_manage_users", value: "true" } }) |
132
|
|
|
|
133
|
|
|
if Rails.configuration.loadbalanced_configuration |
134
|
|
|
admins = admins.without_role(:super_admin) |
135
|
|
|
.where(provider: @user_domain) |
136
|
|
|
end |
137
|
|
|
|
138
|
|
|
admins.collect(&:email).join(",") |
139
|
|
|
end |
140
|
|
|
|
141
|
|
|
def reset_link(user) |
142
|
|
|
edit_password_reset_url(user.reset_token, email: user.email) |
143
|
|
|
end |
144
|
|
|
|
145
|
|
|
def invitation_link(token) |
146
|
|
|
if allow_greenlight_accounts? |
147
|
|
|
signup_url(invite_token: token) |
148
|
|
|
else |
149
|
|
|
root_url(invite_token: token) |
150
|
|
|
end |
151
|
|
|
end |
152
|
|
|
end |
153
|
|
|
|