Пример #1
0
    def register(self):

        social_logins = aslist(self.settings.get("websauna.social_logins", ""))

        if self.request.method == 'GET':
            if self.request.user:
                return HTTPFound(location=self.after_register_url)

            return {'form': self.form.render(), 'social_logins': social_logins}

        elif self.request.method != 'POST':
            return

        # If the request is a POST:
        controls = self.request.POST.items()
        try:
            captured = self.form.validate(controls)
        except deform.ValidationFailure as e:
            return {
                'form': e.render(),
                'errors': e.error.children,
                'social_logins': social_logins
            }

        # With the form validated, we know email and username are unique.
        del captured['csrf_token']

        registration_service = get_registration_service(self.request)
        return registration_service.sign_up(user_data=captured)
Пример #2
0
    def register(self):

        social_logins = aslist(self.settings.get("websauna.social_logins", ""))

        if self.request.method == 'GET':
            if self.request.user:
                return HTTPFound(location=self.after_register_url)

            return {'form': self.form.render(), 'social_logins': social_logins}

        elif self.request.method != 'POST':
            return

        # If the request is a POST:
        controls = self.request.POST.items()
        try:
            captured = self.form.validate(controls)
        except deform.ValidationFailure as e:
            return {'form': e.render(), 'errors': e.error.children, 'social_logins': social_logins}

        # With the form validated, we know email and username are unique.
        del captured['csrf_token']

        registration_service = get_registration_service(self.request)
        return registration_service.sign_up(user_data=captured)
Пример #3
0
def register(request: Request) -> dict:
    """Sign up view.

    :param request: Pyramid request.
    :return: Context to be used by the renderer.
    """
    settings = request.registry.settings

    schema = request.registry.getUtility(IRegisterSchema)
    schema = schema().bind(request=request)

    form_class = request.registry.getUtility(IRegisterForm)
    form = form_class(schema)

    social_logins = aslist(settings.get("websauna.social_logins", ""))

    if request.method == "POST":
        # If the request is a POST:
        controls = request.POST.items()
        try:
            captured = form.validate(controls)
        except deform.ValidationFailure as e:
            return {
                'form': e.render(),
                'errors': e.error.children,
                'social_logins': social_logins
            }

        # With the form validated, we know email and username are unique.
        del captured['csrf_token']

        registration_service = get_registration_service(request)
        return registration_service.sign_up(user_data=captured)

    return {'form': form.render(), 'social_logins': social_logins}
Пример #4
0
def activate(request: Request) -> dict:
    """View to activate user after clicking email link.

    :param request: Pyramid request.
    :return: Context to be used by the renderer.
    """
    code = request.matchdict.get('code', None)
    registration_service = get_registration_service(request)
    return registration_service.activate_by_email(code)
Пример #5
0
 def activate(self):
     """View to activate user after clicking email link."""
     code = self.request.matchdict.get('code', None)
     registration_service = get_registration_service(self.request)
     return registration_service.activate_by_email(code)
Пример #6
0
 def activate(self):
     """View to activate user after clicking email link."""
     code = self.request.matchdict.get('code', None)
     registration_service = get_registration_service(self.request)
     return registration_service.activate_by_email(code)