forked from ABlogiX/django-bigbluebutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
160 lines (115 loc) · 5.69 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from django.shortcuts import render, redirect
from django.views.generic import View
from django.conf import settings
from django.utils.translation import ugettext as _
from django.core.mail import send_mail
from django_bigbluebutton.python_bigbluebutton.bbb_api import getMeetings
from django_bigbluebutton.python_bigbluebutton.bbb_api import joinMeetingURL
from django_bigbluebutton.python_bigbluebutton.bbb_api import endMeeting
from django_bigbluebutton.forms import JoinMeetingForm, RegisteredUserForm
from django_bigbluebutton.models import RegisteredUser, Meeting
class MeetingsView(View):
template_name = 'django_bigbluebutton/meetings.html'
def get(self, request):
if request.user.is_authenticated():
join_meeting_form = JoinMeetingForm()
registered_user_form = RegisteredUserForm()
return_code = 'ERROR'
is_meetings = False
meetings = []
list_meetings = getMeetings(settings.BBB_URL, settings.BBB_SECRET)
if list_meetings is not None:
return_code = list_meetings['returncode']
if list_meetings['meetings'] is not None:
meetings = list(list_meetings['meetings'].values())
is_meetings = True
return render(request, self.template_name, locals())
else:
return redirect('/')
def post(self, request):
if request.user.is_authenticated():
if 'delete' in request.POST:
meeting_id = request.POST.get('meeting_id')
moderator_pw = request.POST.get('moderator_pw')
try:
meeting = Meeting.objects.get(unique_id=int(meeting_id))
meeting.delete()
except Meeting.DoesNotExist:
endMeeting(meeting_id, moderator_pw,
settings.BBB_URL, settings.BBB_SECRET)
return_code = 'ERROR'
is_meetings = False
meetings = []
list_meetings = getMeetings(settings.BBB_URL, settings.BBB_SECRET)
if list_meetings is not None:
return_code = list_meetings['returncode']
if list_meetings['meetings'] is not None:
meetings = list(list_meetings['meetings'].values())
is_meetings = True
return render(request, self.template_name, locals())
else:
return redirect('/')
class MeetingSubscriptionView(View):
template_name = 'django_bigbluebutton/subscription.html'
def get(self, request, *args):
# Get the meeting ID in the URL
meeting_id = args[0]
registered_user_form = RegisteredUserForm()
return render(request, self.template_name, locals())
def post(self, request, *args):
# Get the meeting ID in the URL
meeting_id = args[0]
subscription_success = False
registered_user_form = RegisteredUserForm(request.POST)
if registered_user_form.is_valid():
mail = registered_user_form.cleaned_data['mail']
last_name = registered_user_form.cleaned_data['last_name']
first_name = registered_user_form.cleaned_data['first_name']
company = registered_user_form.cleaned_data['company']
phone_number = registered_user_form.cleaned_data['phone_number']
try:
user = RegisteredUser.objects.get(mail=mail)
user.meetings.add(
Meeting.objects.get(unique_id=int(meeting_id))
)
except RegisteredUser.DoesNotExist:
user = RegisteredUser(mail=mail, last_name=last_name,
first_name=first_name,
company=company,
phone_number=phone_number)
user.save()
user.meetings.add(
Meeting.objects.get(unique_id=int(meeting_id))
)
subject = _("Subscription to the meeting : {}"
.format(Meeting.objects.get(unique_id=int(meeting_id)).name))
content = _("Thank you to subscribed to this meetings.\n"
"You will receive a mail one day before the meeting begins.\n")
send_mail(subject, content, settings.EMAIL_HOST_USER,
[user.mail, ], fail_silently=False)
subscription_success = True
registered_user_form = RegisteredUserForm()
return render(request, self.template_name, locals())
class MeetingConnectionView(View):
template_name = 'django_bigbluebutton/connection.html'
def get(self, request, *args):
# Get the meeting ID in the URL
meeting_id = args[0]
join_meeting_form = JoinMeetingForm()
return render(request, self.template_name, locals())
def post(self, request, *args):
# Get the meeting ID in the URL
meeting_id = args[0]
join_meeting_form = JoinMeetingForm(request.POST)
if join_meeting_form.is_valid():
username = join_meeting_form.cleaned_data['username']
password = join_meeting_form.cleaned_data['password']
meeting = Meeting.objects.get(unique_id=meeting_id)
if meeting.attendee_pw == password or meeting.moderator_pw == password:
meeting_url = joinMeetingURL(meeting_id, username,
password, settings.BBB_URL,
settings.BBB_SECRET)
return redirect(meeting_url)
else:
wrong_password = True
return render(request, self.template_name, locals())