Commit 38fa6509 authored by Noe Nieto's avatar Noe Nieto 💬

Merge branch 'master' of source.puri.sm:liberty/ldh_middleware

parents 87891003 0df7234f
Pipeline #6247 failed with stage
# Django
# 3rd party
from captcha.fields import CaptchaField
from django import forms
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django import forms
from django.contrib.auth import get_user_model
# 3rd party
from captcha.fields import CaptchaField
from ldapregister.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from registration.backends.simple.views import RegistrationView
from registration.forms import validators
# Others
from cart.models import ChosenReward
from ldapregister.forms import RegistrationForm
from purist.models import AccountType
User = get_user_model()
......@@ -35,10 +33,12 @@ class CartRegistrationForm(RegistrationForm):
email = forms.EmailField(
label=_('Recovery email address'),
help_text=_('Enter an email address were we can send you recovery information.'),
help_text=_('Optional. Enter an email address were we can send you '
'recovery information.'),
validators=[
validators.validate_confusables_email,
],
required=False,
)
class CartRegistrationFormWithCaptcha(CartRegistrationForm):
......@@ -120,7 +120,7 @@ class CartRegistrationView(RegistrationView):
else:
# go to WooCommerce cart URL
url = '{}/{}/{}?{}&reauth=1'.format(
url = '{}/{}/{}/{}&reauth=1'.format(
settings.WOO_URL,
'wp-login.php?redirect_to=',
settings.WOO_CART_BILLING_PATH,
......@@ -188,10 +188,11 @@ class CartRegistrationView(RegistrationView):
for limit in limits:
if limit.service in to_activate:
limit.renewal_date = next_month
limit.is_active = True
# Tunnel special case
# Tunnel special case. Requires user manual activation
if limit.service == settings.LM_SERVICES.TUNNEL:
user.generate_tunnel_account()
limit.is_active = False
else:
limit.is_active = True
limit.save()
user.save()
reward.save()
......
......@@ -89,13 +89,22 @@ class InvitationRegistrationView(RegistrationView):
u_limit.created_date = o_limit.created_date
u_limit.updated_date = o_limit.updated_date
# Generate tunnel creds for invited user if
# owner has tunnel service
# Tunnel activation requires manual
# action from user
if (
o_service == settings.LM_SERVICES.TUNNEL and
o_limit.remaining_use_time().total_seconds() > 0
):
user.generate_tunnel_account()
u_limit.is_active = True
u_limit.is_active = False
u_limit.save()
# Make new user member of same groups as owner
if o_limit.is_active:
if o_service == settings.LM_SERVICES.SOCIAL:
user.set_ldap_group('social')
elif o_service == settings.LM_SERVICES.CHAT:
user.set_ldap_group('chat')
elif o_service == settings.LM_SERVICES.MAIL:
user.set_ldap_group('mail')
elif o_service == settings.LM_SERVICES.XMPP:
user.set_ldap_group('xmpp')
return user
......@@ -118,22 +118,25 @@ def activate_single_limit(limit, credit_timedelta=None, renewal_date=None):
# otherwise, activate the limit before saving
if limit.service == settings.LM_SERVICES.TUNNEL:
if not limit.user.has_tunnel_account():
limit.user.generate_tunnel_account()
# TUNNEL special case requires user manual activation
limit.is_active = False
elif limit.service == settings.LM_SERVICES.CHAT:
limit.user.set_ldap_group("chat")
limit.is_active = True
elif limit.service == settings.LM_SERVICES.MAIL:
limit.user.set_ldap_group("mail")
limit.is_active = True
elif limit.service == settings.LM_SERVICES.SOCIAL:
limit.user.set_ldap_group("social")
limit.is_active = True
elif limit.service == settings.LM_SERVICES.XMPP:
limit.user.set_ldap_group("xmpp")
limit.is_active = True
elif limit.service == settings.LM_SERVICES.GROUP:
pass # Nothing to do for GROUP
limit.is_active = True
else:
raise Exception("Invalid activation attempt. Service not recognised.")
limit.is_active = True
limit.user.chosenreward.is_pending = False
limit.user.chosenreward.save()
limit.save()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment