-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathviews.py
More file actions
43 lines (31 loc) · 1.19 KB
/
views.py
File metadata and controls
43 lines (31 loc) · 1.19 KB
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
from django.shortcuts import render
from django.conf import settings
import requests
# Create your views here.
def home(request):
return render(request, "home.html")
def adda(request):
return render(request, "adda.html")
def slack(request):
view_data = {}
subdomain = settings.SLACK_SUB_DOMAIN
view_data['subdomain'] = subdomain
if request.method == "POST":
email = request.POST.get('email')
if email:
token = settings.SLACK_TOKEN
api_url = "https://{}.slack.com/api/users.admin.invite".format(subdomain)
res = requests.post(api_url, {
'email': email,
'token': token,
'set_active': 'true'
})
data = res.json()
if not data['ok']:
if data['error'] == 'already_invited':
view_data['message'] = "You are already invited to this team! Please recheck your email!"
else:
view_data['message'] = "Error: " + data['error']
else:
view_data['message'] = "You have been invited. Please check your email!"
return render(request, "slack.html", view_data)