2019-07-01 02:38:43 +00:00
|
|
|
import uuid
|
|
|
|
|
2017-09-02 10:26:17 +00:00
|
|
|
from django.conf import settings
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
from django.contrib import messages
|
2017-09-02 11:06:20 +00:00
|
|
|
from django.contrib.auth import authenticate, login
|
2019-07-01 02:38:43 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
from django.contrib.auth.tokens import default_token_generator
|
2019-07-01 02:38:43 +00:00
|
|
|
from django.core.files.base import ContentFile
|
2017-09-24 10:25:52 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2019-07-01 02:38:43 +00:00
|
|
|
from django.shortcuts import render
|
2017-09-02 11:06:20 +00:00
|
|
|
from django.utils.encoding import force_bytes
|
|
|
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
2017-09-02 10:26:17 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-12-27 07:31:19 +00:00
|
|
|
from django.views.decorators.cache import cache_control
|
2019-07-01 02:38:43 +00:00
|
|
|
from django.views.generic import FormView, CreateView
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
|
2019-07-01 02:38:43 +00:00
|
|
|
from datacenterlight.utils import get_cms_integration
|
|
|
|
from hosting.forms import UserHostingKeyForm
|
|
|
|
from hosting.models import UserHostingKey
|
2017-09-02 11:06:20 +00:00
|
|
|
from membership.models import CustomUser
|
2019-07-01 02:38:43 +00:00
|
|
|
from opennebula_api.models import OpenNebulaManager
|
|
|
|
from utils.hosting_utils import get_all_public_keys
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
from .forms import SetPasswordForm
|
2017-09-02 11:06:20 +00:00
|
|
|
from .mailer import BaseEmail
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
class SignupViewMixin(CreateView):
|
|
|
|
model = CustomUser
|
|
|
|
success_url = None
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2017-09-02 11:06:20 +00:00
|
|
|
next_url = self.request.POST.get('next') if self.request.POST.get(
|
|
|
|
'next') \
|
2016-10-14 05:11:05 +00:00
|
|
|
else self.success_url
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
return next_url
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
name = form.cleaned_data.get('name')
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
password = form.cleaned_data.get('password')
|
|
|
|
|
|
|
|
CustomUser.register(name, password, email)
|
|
|
|
auth_user = authenticate(email=email, password=password)
|
|
|
|
login(self.request, auth_user)
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
|
|
|
class LoginViewMixin(FormView):
|
|
|
|
success_url = None
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2017-05-23 17:18:51 +00:00
|
|
|
next_url = self.request.POST.get('next', self.success_url)
|
2017-05-28 20:01:18 +00:00
|
|
|
if not next_url:
|
|
|
|
return self.success_url
|
2016-08-20 05:57:35 +00:00
|
|
|
return next_url
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
password = form.cleaned_data.get('password')
|
|
|
|
auth_user = authenticate(email=email, password=password)
|
|
|
|
|
|
|
|
if auth_user:
|
|
|
|
login(self.request, auth_user)
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
2017-12-27 07:31:19 +00:00
|
|
|
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
2016-08-20 05:57:35 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
if self.request.user.is_authenticated():
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
return super(LoginViewMixin, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2017-09-24 10:25:52 +00:00
|
|
|
class ResendActivationLinkViewMixin(FormView):
|
|
|
|
success_message = _(
|
2017-09-29 19:45:30 +00:00
|
|
|
"An email with the activation link has been sent to you")
|
2017-09-24 10:25:52 +00:00
|
|
|
|
|
|
|
def generate_email_context(self, user):
|
|
|
|
context = {
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme,
|
|
|
|
self.request.get_host()),
|
|
|
|
'activation_link': reverse_lazy(
|
|
|
|
'hosting:validate',
|
|
|
|
kwargs={'validate_slug': user.validation_slug}
|
|
|
|
),
|
|
|
|
'dcl_text': settings.DCL_TEXT,
|
|
|
|
}
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
user = CustomUser.objects.get(email=email)
|
|
|
|
messages.add_message(self.request, messages.SUCCESS,
|
|
|
|
self.success_message)
|
|
|
|
context = self.generate_email_context(user)
|
|
|
|
email_data = {
|
|
|
|
'subject': '{dcl_text} {account_activation}'.format(
|
|
|
|
dcl_text=settings.DCL_TEXT,
|
|
|
|
account_activation=_('Account Activation')
|
|
|
|
),
|
|
|
|
'to': email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': self.email_template_name,
|
|
|
|
'template_path': self.email_template_path,
|
|
|
|
'from_address': settings.DCL_SUPPORT_FROM_ADDRESS
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
class PasswordResetViewMixin(FormView):
|
2017-09-02 11:06:20 +00:00
|
|
|
success_message = _(
|
2017-10-14 21:00:42 +00:00
|
|
|
"The link to reset your password has been sent to your email")
|
2017-06-12 15:12:17 +00:00
|
|
|
site = ''
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
|
|
|
|
def test_generate_email_context(self, user):
|
|
|
|
context = {
|
|
|
|
'user': user,
|
|
|
|
'token': default_token_generator.make_token(user),
|
|
|
|
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
|
2017-09-02 11:06:20 +00:00
|
|
|
'site_name': 'ungleich' if self.site != 'dcl' else settings.DCL_TEXT,
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme,
|
|
|
|
self.request.get_host())
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
}
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
user = CustomUser.objects.get(email=email)
|
2017-09-02 11:06:20 +00:00
|
|
|
messages.add_message(self.request, messages.SUCCESS,
|
|
|
|
self.success_message)
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
context = self.test_generate_email_context(user)
|
|
|
|
email_data = {
|
2017-09-02 10:54:25 +00:00
|
|
|
'subject': _('Password Reset'),
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
'to': email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'password_reset_email',
|
|
|
|
'template_path': self.template_email_path
|
|
|
|
}
|
2017-06-12 15:12:17 +00:00
|
|
|
if self.site == 'dcl':
|
2017-09-02 10:26:17 +00:00
|
|
|
email_data['from_address'] = settings.DCL_SUPPORT_FROM_ADDRESS
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetConfirmViewMixin(FormView):
|
|
|
|
form_class = SetPasswordForm
|
2017-09-02 11:06:20 +00:00
|
|
|
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
def post(self, request, uidb64=None, token=None, *arg, **kwargs):
|
|
|
|
try:
|
|
|
|
uid = urlsafe_base64_decode(uidb64)
|
|
|
|
user = CustomUser.objects.get(pk=uid)
|
|
|
|
except (TypeError, ValueError, OverflowError, CustomUser.DoesNotExist):
|
|
|
|
user = None
|
|
|
|
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
|
2017-09-02 11:06:20 +00:00
|
|
|
if user is not None and default_token_generator.check_token(user,
|
|
|
|
token):
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
if form.is_valid():
|
|
|
|
new_password = form.cleaned_data['new_password2']
|
|
|
|
user.set_password(new_password)
|
|
|
|
user.save()
|
2017-09-02 11:20:09 +00:00
|
|
|
messages.success(request, _('Password has been reset.'))
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
return self.form_valid(form)
|
|
|
|
else:
|
2017-09-02 11:06:20 +00:00
|
|
|
messages.error(request,
|
2017-09-02 11:20:09 +00:00
|
|
|
_('Password reset has not been successful.'))
|
|
|
|
form.add_error(None,
|
|
|
|
_('Password reset has not been successful.'))
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
return self.form_invalid(form)
|
|
|
|
|
|
|
|
else:
|
2017-09-02 11:06:20 +00:00
|
|
|
messages.error(request,
|
2017-09-02 11:20:09 +00:00
|
|
|
_('The reset password link is no longer valid.'))
|
|
|
|
form.add_error(None,
|
|
|
|
_('The reset password link is no longer valid.'))
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
return self.form_invalid(form)
|
2019-07-01 02:38:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SSHKeyCreateView(LoginRequiredMixin, FormView):
|
|
|
|
form_class = UserHostingKeyForm
|
|
|
|
model = UserHostingKey
|
|
|
|
template_name = 'hosting/user_key.html'
|
|
|
|
login_url = reverse_lazy('hosting:login')
|
|
|
|
context_object_name = "virtual_machine"
|
|
|
|
success_url = reverse_lazy('hosting:ssh_keys')
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(SSHKeyCreateView, self).get_form_kwargs()
|
|
|
|
kwargs.update({'request': self.request})
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.save()
|
|
|
|
if settings.DCL_SSH_KEY_NAME_PREFIX in form.instance.name:
|
|
|
|
content = ContentFile(form.cleaned_data.get('private_key'))
|
|
|
|
filename = form.cleaned_data.get(
|
|
|
|
'name') + '_' + str(uuid.uuid4())[:8] + '_private.pem'
|
|
|
|
form.instance.private_key.save(filename, content)
|
|
|
|
context = self.get_context_data()
|
|
|
|
|
|
|
|
next_url = self.request.session.get(
|
|
|
|
'next',
|
|
|
|
reverse_lazy('hosting:create_virtual_machine')
|
|
|
|
)
|
|
|
|
|
|
|
|
if 'next' in self.request.session:
|
|
|
|
context.update({
|
|
|
|
'next_url': next_url
|
|
|
|
})
|
|
|
|
del (self.request.session['next'])
|
|
|
|
|
|
|
|
if form.cleaned_data.get('private_key'):
|
|
|
|
context.update({
|
|
|
|
'private_key': form.cleaned_data.get('private_key'),
|
|
|
|
'key_name': form.cleaned_data.get('name'),
|
|
|
|
'form': UserHostingKeyForm(request=self.request),
|
|
|
|
})
|
|
|
|
|
|
|
|
owner = self.request.user
|
|
|
|
manager = OpenNebulaManager(
|
|
|
|
email=owner.email,
|
|
|
|
password=owner.password
|
|
|
|
)
|
|
|
|
keys_to_save = get_all_public_keys(self.request.user)
|
|
|
|
manager.save_key_in_opennebula_user('\n'.join(keys_to_save))
|
|
|
|
return HttpResponseRedirect(self.success_url)
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
form = self.get_form()
|
|
|
|
required = 'add_ssh' in self.request.POST
|
|
|
|
form.fields['name'].required = required
|
|
|
|
form.fields['public_key'].required = required
|
|
|
|
if form.is_valid():
|
|
|
|
return self.form_valid(form)
|
|
|
|
else:
|
|
|
|
return self.form_invalid(form)
|
|
|
|
|
|
|
|
|
|
|
|
class AskSSHKeyView(SSHKeyCreateView):
|
|
|
|
form_class = UserHostingKeyForm
|
|
|
|
template_name = "datacenterlight/add_ssh_key.html"
|
|
|
|
success_url = reverse_lazy('datacenterlight:order_confirmation')
|
|
|
|
context_object_name = "dcl_vm_buy_add_ssh_key"
|
|
|
|
|
|
|
|
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
'site_url': reverse_lazy('datacenterlight:index'),
|
|
|
|
'cms_integration': get_cms_integration('default'),
|
|
|
|
'form': UserHostingKeyForm(request=self.request),
|
|
|
|
'keys': get_all_public_keys(self.request.user)
|
|
|
|
}
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|