# Path: authemail/wrapper.py
# class API(object):
# class Authemail(API):
#     BASE_PATH = ''
#     URLS = {}
#     BASE_PATH = 'accounts'
#     URLS = {
#         'signup': '/signup/',
#         'signup_verify': '/signup/verify/',
#         'login': '/login/',
#         'logout': '/logout/',
#         'password_reset': '/password/reset/',
#         'password_reset_verify': '/password/reset/verify/',
#         'password_reset_verified': '/password/reset/verified/',
#         'email_change': '/email/change/',
#         'email_change_verify': '/email/change/verify/',
#         'password_change': '/password/change/',
#         'users_me': '/users/me/',
#     }
#     def __init__(self):
#     def _get_path(self, key):
#     def _get_complete_url(self, path):
#     def _request(self, method, path, params=None, payload=None):
#     def _GET(self, path, params=None):
#     def _POST(self, path, params=None, payload=None):
#     def _set_attrs_to_values(self, response={}):
#     def signup(self, **kwargs):
#     def signup_verify(self, **kwargs):
#     def login(self, **kwargs):
#     def logout(self, **kwargs):
#     def password_reset(self, **kwargs):
#     def password_reset_verify(self, **kwargs):
#     def password_reset_verified(self, **kwargs):
#     def email_change(self, **kwargs):
#     def email_change_verify(self, **kwargs):
#     def password_change(self, **kwargs):
#     def users_me(self, **kwargs):
# 
# Path: example_project/example_project/forms.py
# class SignupForm(PasswordConfirmForm):
#     first_name = forms.CharField(max_length=30, required=False)
#     last_name = forms.CharField(max_length=30, required=False)
#     email = forms.EmailField(max_length=255)
# 
# class LoginForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
#     password = forms.CharField(max_length=128)
# 
# Path: example_project/example_project/forms.py
# class PasswordResetForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
# 
# class PasswordResetVerifiedForm(AddErrorMixin, forms.Form):
#     pass
# 
# Path: example_project/example_project/forms.py
# class EmailChangeForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
# 
# Path: example_project/example_project/forms.py
# class PasswordChangeForm(PasswordConfirmForm):
#     pass
# 
# class UsersMeChangeForm(AddErrorMixin, forms.Form):
#     first_name = forms.CharField(max_length=30, required=False)
#     last_name = forms.CharField(max_length=30, required=False)
#     date_of_birth = forms.DateField(required=False)


from django.urls import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView
from django.views.generic.base import View
from django.views.generic.edit import FormView
from authemail import wrapper
from .forms import SignupForm, LoginForm
from .forms import PasswordResetForm, PasswordResetVerifiedForm
from .forms import EmailChangeForm
from .forms import PasswordChangeForm, UsersMeChangeForm
from . import wrapperplus

    def form_valid(self, form):
        token = self.request.session['auth_token']
        password = form.cleaned_data['password']

        account = wrapper.Authemail()
        response = account.password_change(token=token, password=password)

        # Handle other error responses from API
        if 'detail' in response:
            form.add_error(None, response['detail'])
            return self.form_invalid(form)

        return super(PasswordChangeFrontEnd, self).form_valid(form)


class PasswordChangeSuccessFrontEnd(TemplateView):
    template_name = 'password_change_success.html'


class UsersMeChangeFrontEnd(FormView):
    template_name = 'users_me_change.html'
    form_class = UsersMeChangeForm
    success_url = reverse_lazy('users_me_change_success_page')

    def get_context_data(self, **kwargs):
        context = super(UsersMeChangeFrontEnd, self).get_context_data(**kwargs)

        token = self.request.session['auth_token']


# Path: authemail/wrapper.py
# class API(object):
# class Authemail(API):
#     BASE_PATH = ''
#     URLS = {}
#     BASE_PATH = 'accounts'
#     URLS = {
#         'signup': '/signup/',
#         'signup_verify': '/signup/verify/',
#         'login': '/login/',
#         'logout': '/logout/',
#         'password_reset': '/password/reset/',
#         'password_reset_verify': '/password/reset/verify/',
#         'password_reset_verified': '/password/reset/verified/',
#         'email_change': '/email/change/',
#         'email_change_verify': '/email/change/verify/',
#         'password_change': '/password/change/',
#         'users_me': '/users/me/',
#     }
#     def __init__(self):
#     def _get_path(self, key):
#     def _get_complete_url(self, path):
#     def _request(self, method, path, params=None, payload=None):
#     def _GET(self, path, params=None):
#     def _POST(self, path, params=None, payload=None):
#     def _set_attrs_to_values(self, response={}):
#     def signup(self, **kwargs):
#     def signup_verify(self, **kwargs):
#     def login(self, **kwargs):
#     def logout(self, **kwargs):
#     def password_reset(self, **kwargs):
#     def password_reset_verify(self, **kwargs):
#     def password_reset_verified(self, **kwargs):
#     def email_change(self, **kwargs):
#     def email_change_verify(self, **kwargs):
#     def password_change(self, **kwargs):
#     def users_me(self, **kwargs):
# 
# Path: example_project/example_project/forms.py
# class SignupForm(PasswordConfirmForm):
#     first_name = forms.CharField(max_length=30, required=False)
#     last_name = forms.CharField(max_length=30, required=False)
#     email = forms.EmailField(max_length=255)
# 
# class LoginForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
#     password = forms.CharField(max_length=128)
# 
# Path: example_project/example_project/forms.py
# class PasswordResetForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
# 
# class PasswordResetVerifiedForm(AddErrorMixin, forms.Form):
#     pass
# 
# Path: example_project/example_project/forms.py
# class EmailChangeForm(AddErrorMixin, forms.Form):
#     email = forms.EmailField(max_length=255)
# 
# Path: example_project/example_project/forms.py
# class PasswordChangeForm(PasswordConfirmForm):
#     pass
# 
# class UsersMeChangeForm(AddErrorMixin, forms.Form):
#     first_name = forms.CharField(max_length=30, required=False)
#     last_name = forms.CharField(max_length=30, required=False)
#     date_of_birth = forms.DateField(required=False)


# Path: example_project/example_project/views.py
from django.urls import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView
from django.views.generic.base import View
from django.views.generic.edit import FormView
from authemail import wrapper
from .forms import SignupForm, LoginForm
from .forms import PasswordResetForm, PasswordResetVerifiedForm
from .forms import EmailChangeForm
from .forms import PasswordChangeForm, UsersMeChangeForm
from . import wrapperplus


    def form_valid(self, form):
        token = self.request.session['auth_token']
        password = form.cleaned_data['password']

        account = wrapper.Authemail()
        response = account.password_change(token=token, password=password)

        # Handle other error responses from API
        if 'detail' in response:
            form.add_error(None, response['detail'])
            return self.form_invalid(form)

        return super(PasswordChangeFrontEnd, self).form_valid(form)


class PasswordChangeSuccessFrontEnd(TemplateView):
    template_name = 'password_change_success.html'


class UsersMeChangeFrontEnd(FormView):
    template_name = 'users_me_change.html'
    form_class = UsersMeChangeForm
    success_url = reverse_lazy('users_me_change_success_page')

    def get_context_data(self, **kwargs):
        context = super(UsersMeChangeFrontEnd, self).get_context_data(**kwargs)

        token = self.request.session['auth_token']


        account = wrapper.Authemail()