# Path: sitegate/signin_flows/modern.py
# class ModernSignin(SigninFlow):
#     """Modernized login flow based on classic from Django built-in
#     with username e-mail authentication support."""
# 
#     form = ModernSigninForm
# 
# Path: sitegate/signup_flows/modern.py
# class ModernSignup(SimpleClassicWithEmailSignup):
#     """Modernized registration flow based on classic from Django built-in
#     with unique e-mail field, without username and second password fields.
# 
#     """
#     form = ModernSignupForm
# 
#     def sign_in(self, request: HttpRequest, form: ModelForm, signup_result: 'User') -> bool:
#         form_data = form.cleaned_data
#         return self.login_generic(request, form_data['email'], form_data['password1'])
# 
#     def add_user(self, request: HttpRequest, form: ModelForm) -> 'User':
# 
#         user = super(form.__class__, form).save(commit=False)
# 
#         if not hasattr(user, 'USERNAME_FIELD') or user.USERNAME_FIELD == 'username':
#             user.username = form.cleaned_data['email']
# 
#         user.email = form.cleaned_data['email']
#         user.set_password(form.cleaned_data['password1'])
#         user.save()
# 
#         self.send_email(request, user)
# 
#         return user
# 
# Path: sitegate/utils.py
# class DecoratorBuilder:
#     """Decorators builder. Facilitates decorators creation.
#     Inherit from this and implement `handle` method.
# 
#     """
# 
#     def __init__(self, args, kwargs):
#         """Accepts decoration function arguments."""
#         self._args_dec = list(args)
#         self._kwargs_dec = dict(kwargs)
# 
#     def handle(self, func, args_func, kwargs_func, args_dec, kwargs_dec):
#         raise NotImplementedError  # pragma: nocover
# 
#     def __call__(self, *args_call, **kwargs_call):
#         def decorated(view_function):
#             @wraps(view_function, assigned=available_attrs(view_function))
#             def catcher(*args_func, **kwargs_func):
#                 return self.handle(view_function, args_func, kwargs_func, self._args_dec, self._kwargs_dec)
#             return catcher
# 
#         # Case one: @dec('a', b='b')
#         if len(args_call) and hasattr(args_call[0], '__call__'):
#             return decorated(args_call[0])
# 
#         # Case two: @dec
#         if len(self._args_dec) and hasattr(self._args_dec[0], '__call__'):
#             return decorated(self._args_dec[0])(*args_call, **kwargs_call)
# 
#         return decorated


from typing import Type, Callable
from django.shortcuts import redirect
from .signin_flows.modern import ModernSignin
from .signup_flows.modern import ModernSignup
from .utils import DecoratorBuilder
    from .flows_base import FlowsBase  # noqa
"""This file contains decorators used by sitegate."""



if False:  # pragma: nocover


class FlowBuilder(DecoratorBuilder):

    def __init__(self, flow_cls: Type['FlowsBase'], args: tuple, kwargs: dict):
        self.flow_cls = flow_cls
        super(FlowBuilder, self).__init__(args, kwargs)

    def handle(self, func: Callable, args_func: tuple, kwargs_func: dict, args_dec: tuple, kwargs_dec: dict):
        kwargs_dec_ = dict(kwargs_dec)
        flow_class = kwargs_dec_.pop('flow', None)

        if flow_class is None:
            flow_class = self.flow_cls

        flow_obj = flow_class(**kwargs_dec_)

        return flow_obj.respond_for(func, args_func, kwargs_func)



# Path: sitegate/signin_flows/modern.py
# class ModernSignin(SigninFlow):
#     """Modernized login flow based on classic from Django built-in
#     with username e-mail authentication support."""
# 
#     form = ModernSigninForm
# 
# Path: sitegate/signup_flows/modern.py
# class ModernSignup(SimpleClassicWithEmailSignup):
#     """Modernized registration flow based on classic from Django built-in
#     with unique e-mail field, without username and second password fields.
# 
#     """
#     form = ModernSignupForm
# 
#     def sign_in(self, request: HttpRequest, form: ModelForm, signup_result: 'User') -> bool:
#         form_data = form.cleaned_data
#         return self.login_generic(request, form_data['email'], form_data['password1'])
# 
#     def add_user(self, request: HttpRequest, form: ModelForm) -> 'User':
# 
#         user = super(form.__class__, form).save(commit=False)
# 
#         if not hasattr(user, 'USERNAME_FIELD') or user.USERNAME_FIELD == 'username':
#             user.username = form.cleaned_data['email']
# 
#         user.email = form.cleaned_data['email']
#         user.set_password(form.cleaned_data['password1'])
#         user.save()
# 
#         self.send_email(request, user)
# 
#         return user
# 
# Path: sitegate/utils.py
# class DecoratorBuilder:
#     """Decorators builder. Facilitates decorators creation.
#     Inherit from this and implement `handle` method.
# 
#     """
# 
#     def __init__(self, args, kwargs):
#         """Accepts decoration function arguments."""
#         self._args_dec = list(args)
#         self._kwargs_dec = dict(kwargs)
# 
#     def handle(self, func, args_func, kwargs_func, args_dec, kwargs_dec):
#         raise NotImplementedError  # pragma: nocover
# 
#     def __call__(self, *args_call, **kwargs_call):
#         def decorated(view_function):
#             @wraps(view_function, assigned=available_attrs(view_function))
#             def catcher(*args_func, **kwargs_func):
#                 return self.handle(view_function, args_func, kwargs_func, self._args_dec, self._kwargs_dec)
#             return catcher
# 
#         # Case one: @dec('a', b='b')
#         if len(args_call) and hasattr(args_call[0], '__call__'):
#             return decorated(args_call[0])
# 
#         # Case two: @dec
#         if len(self._args_dec) and hasattr(self._args_dec[0], '__call__'):
#             return decorated(self._args_dec[0])(*args_call, **kwargs_call)
# 
#         return decorated


# Path: sitegate/decorators.py
from typing import Type, Callable
from django.shortcuts import redirect
from .signin_flows.modern import ModernSignin
from .signup_flows.modern import ModernSignup
from .utils import DecoratorBuilder
    from .flows_base import FlowsBase  # noqa

"""This file contains decorators used by sitegate."""



if False:  # pragma: nocover


class FlowBuilder(DecoratorBuilder):

    def __init__(self, flow_cls: Type['FlowsBase'], args: tuple, kwargs: dict):
        self.flow_cls = flow_cls
        super(FlowBuilder, self).__init__(args, kwargs)

    def handle(self, func: Callable, args_func: tuple, kwargs_func: dict, args_dec: tuple, kwargs_dec: dict):
        kwargs_dec_ = dict(kwargs_dec)
        flow_class = kwargs_dec_.pop('flow', None)

        if flow_class is None:
            flow_class = self.flow_cls

        flow_obj = flow_class(**kwargs_dec_)

        return flow_obj.respond_for(func, args_func, kwargs_func)



class RedirectBuilder(DecoratorBuilder):