def register_email(request): ''' Register new email. ''' user = request.user serializer = RegisterEmailSerializer(data=request.data) serializer.is_valid(raise_exception=True) email = serializer.validated_data['email'] template_config = ( registration_settings.REGISTER_EMAIL_VERIFICATION_EMAIL_TEMPLATES) if registration_settings.REGISTER_EMAIL_VERIFICATION_ENABLED: signer = RegisterEmailSigner({ 'user_id': user.pk, 'email': email, }, request=request) send_verification(user, signer, template_config, email=email) else: email_field = get_user_setting('EMAIL_FIELD') setattr(user, email_field, email) user.save() return get_ok_response('Register email link email sent')
def send_reset_password_link(request): ''' Send email with reset password link. ''' serializer = SendResetPasswordLinkSerializer(data=request.data) serializer.is_valid(raise_exception=True) login = serializer.data['login'] user = None for login_field in get_login_fields(): user = get_user_by_lookup_dict({login_field: login}, default=None) if user: break if not user: raise UserNotFound() signer = ResetPasswordSigner({ 'user_id': user.pk, }, request=request) template_config = ( registration_settings.RESET_PASSWORD_VERIFICATION_EMAIL_TEMPLATES) send_verification(user, signer, template_config) return get_ok_response('Reset link sent')
def send_reset_password_link(request): ''' Send email with reset password link. --- serializer: SendResetPasswordLinkSerializer ''' serializer = SendResetPasswordLinkSerializer(data=request.data) serializer.is_valid(raise_exception=True) login = serializer.data['login'] user_class = get_user_model_class() user_queryset = user_class.objects.all() user = None for login_field in get_login_fields(): try: user = get_object_or_404(user_queryset, **{login_field: login}) break except Http404: pass if not user: raise BadRequest('User not found') signer = ResetPasswordSigner({ 'user_id': user.pk, }, request=request) template_config = ( registration_settings.RESET_PASSWORD_VERIFICATION_EMAIL_TEMPLATES) send_verification(user, signer, template_config) return get_ok_response('Reset link sent')
def register(request): ''' Register new user. ''' serializer_class = registration_settings.REGISTER_SERIALIZER_CLASS serializer = serializer_class(data=request.data) serializer.is_valid(raise_exception=True) kwargs = {} if registration_settings.REGISTER_VERIFICATION_ENABLED: verification_flag_field = get_user_setting('VERIFICATION_FLAG_FIELD') kwargs[verification_flag_field] = False user = serializer.save(**kwargs) profile_serializer_class = registration_settings.PROFILE_SERIALIZER_CLASS profile_serializer = profile_serializer_class(instance=user) user_data = profile_serializer.data if registration_settings.REGISTER_VERIFICATION_ENABLED: signer = RegisterSigner({ 'user_id': user.pk, }, request=request) template_config = ( registration_settings.REGISTER_VERIFICATION_EMAIL_TEMPLATES) send_verification(user, signer, template_config) return Response(user_data, status=status.HTTP_201_CREATED)
def register(request): ''' Register new user. ''' serializer_class = registration_settings.REGISTER_SERIALIZER_CLASS serializer = serializer_class(data=request.data) serializer.is_valid(raise_exception=True) kwargs = {} if registration_settings.REGISTER_VERIFICATION_ENABLED: verification_flag_field = get_user_setting('VERIFICATION_FLAG_FIELD') kwargs[verification_flag_field] = False email_field = get_user_setting('EMAIL_FIELD') if (email_field not in serializer.validated_data or not serializer.validated_data[email_field]): raise BadRequest("User without email cannot be verified") user = serializer.save(**kwargs) output_serializer_class = registration_settings.REGISTER_OUTPUT_SERIALIZER_CLASS # noqa: E501 output_serializer = output_serializer_class(instance=user) user_data = output_serializer.data if registration_settings.REGISTER_VERIFICATION_ENABLED: signer = RegisterSigner({ 'user_id': user.pk, }, request=request) template_config = ( registration_settings.REGISTER_VERIFICATION_EMAIL_TEMPLATES) send_verification(user, signer, template_config) return Response(user_data, status=status.HTTP_201_CREATED)