|
7 | 7 | # See https://aboutcode.org for more information about nexB OSS projects. |
8 | 8 | # |
9 | 9 |
|
| 10 | +from django.core.mail import send_mail |
10 | 11 | from django.db.models import Count |
11 | 12 | from django.db.models import Q |
| 13 | +from django.http import HttpResponse |
12 | 14 | from django.http.response import Http404 |
13 | 15 | from django.shortcuts import render |
14 | 16 | from django.urls import reverse_lazy |
|
22 | 24 | from vulnerabilities.forms import ApiUserCreationForm |
23 | 25 | from vulnerabilities.forms import PackageSearchForm |
24 | 26 | from vulnerabilities.forms import VulnerabilitySearchForm |
| 27 | +from vulnerablecode.settings import env |
25 | 28 |
|
26 | 29 | PAGE_SIZE = 20 |
27 | 30 |
|
@@ -232,9 +235,18 @@ class ApiUserCreateView(generic.CreateView): |
232 | 235 | template_name = "api_user_creation_form.html" |
233 | 236 |
|
234 | 237 | def form_valid(self, form): |
235 | | - # TODO: send an email with the API key |
236 | | - response = super().form_valid(form) |
237 | | - # TODO: return http response with a simple success message that |
| 238 | + super().form_valid(form) |
| 239 | + |
| 240 | + send_mail( |
| 241 | + subject="VCIO API Key", |
| 242 | + message=f"Here is your token for the VCIO API: {self.object.auth_token}", |
| 243 | + from_email=env.str("FROM_EMAIL", default=""), |
| 244 | + recipient_list=[self.object.email], |
| 245 | + ) |
| 246 | + |
| 247 | + return HttpResponse( |
| 248 | + f"We have mailed you the token for VCIO API on this email {self.object.email}" |
| 249 | + ) |
238 | 250 |
|
239 | 251 | def get_success_url(self): |
240 | | - return reverse_lazy("api_user_creation_success", kwargs={"uuid": self.object.pk}) |
| 252 | + return reverse_lazy("home") |
0 commit comments