コード例 #1
0
ファイル: views.py プロジェクト: WilliamRen/django-rest-auth
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #2
0
ファイル: views.py プロジェクト: ppak9/bongtoo_restapi
    def perform_create(self, serializer):
        validated_data = self.request.data
        user = serializer.save(self.request)
        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            create_token(self.token_model, user, serializer)

        complete_signup(self.request._request, user,
                        allauth_settings.EMAIL_VERIFICATION, None)

        subject_data = validated_data.pop('subject')
        activity_data = validated_data.pop('activity')
        regions_data = validated_data.pop('region')

        for data in regions_data:
            region = Region.objects.get(city=data['city'], town=data['town'])
            user.region.add(region)

        for data in activity_data:
            activity = Activity.objects.get(id=data['id'])
            user.activity.add(activity)

        for data in subject_data:
            subject = Subject.objects.get(id=data['id'])
            user.subject.add(subject)
        return user
コード例 #3
0
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #4
0
    def send_activation_email(self, user, serializer):

        create_token(self.token_model, user, serializer)

        token = account_activation_token.make_token(user)

        params = {
            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
            'token': token
        }

        confirmation_link = settings.FRONTEND_URL + "/#/confirm?" + urllib.parse.urlencode(
            params)

        context = {
            'username': user.username,
            'confirmation_link': confirmation_link,
            'service_name': "DummyService"
        }

        message = Mail(from_email='*****@*****.**',
                       to_emails=user.email,
                       subject='Thank you for registration',
                       html_content=render_to_string(
                           "account/email/confirmation_mail.html", context))
        try:
            sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
            response = sg.send(message)
            print(response.status_code)
            print(response.body)
            print(response.headers)
        except Exception as e:
            print(e)
コード例 #5
0
    def perform_create(self, serializer):
        user = serializer.save(self.request)
        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            create_token(self.token_model, user, serializer)

        return user
コード例 #6
0
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     if getattr(settings, 'REST_USE_JWT', False):
         self.token = jwt_encode(user)
     else:
         create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION, None)
     return user
コード例 #7
0
ファイル: views.py プロジェクト: bss3/django-rest-auth
 def perform_create(self, serializer):
     user = serializer.save()
     if getattr(settings, 'REST_USE_JWT', False):
         self.token = jwt_encode(user)
     else:
         create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #8
0
    def perform_create(self, serializer):
        user = serializer.save(self.request)
        print("user:"******"khurm" + str(user).split('@')[0] +
              "name bucket will be created!")
        create_bucket("khurm" + str(user).split('@')[0])
        if getattr(settings, 'REST_USE_JWT', False):
            print("REST_USE_JWT가 false로 되어있어?")
            self.token = jwt_encode(user)
        else:
            print("REST_USE_JWT가 true지?")
            create_token(self.token_model, user, serializer)

        return user
コード例 #9
0
ファイル: views.py プロジェクト: ITOO-UrFU/NOTV
    def perform_create(self, serializer):
        print("perform_create")
        user = serializer.save(self.request)
        print("user saved")
        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            print("creating token")
            create_token(self.token_model, user, serializer)

        print("sending блядский email...")
        complete_signup(self.request._request, user, False, None)
        print("остался только ретерн")
        return user
コード例 #10
0
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save(request)

        create_token(self.token_model, user, serializer)

        request.data["user"] = user.pk

        complete_signup(self.request._request, user, allauth_settings.EMAIL_VERIFICATION, None)

        headers = self.get_success_headers(serializer.data)
        return Response(self.get_response_data(user),
                        status=status.HTTP_201_CREATED,
                        headers=headers)
コード例 #11
0
ファイル: auth.py プロジェクト: Chaoslecion123/Diver
    def perform_create(self, serializer):
        user = serializer.save(self.request)

        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            create_token(self.token_model, user, serializer)

        send_account_create_confirmation_email.delay(
            {
                'user_name': user.get_full_name()
            },
            user.email
        )

        return user
コード例 #12
0
    def login(self):
        self.user = self.serializer.validated_data['user']

        if self.user.get_has_two_factor():
            # Check if we have a backup code in request.data
            if 'backup_code' in self.serializer.validated_data and self.serializer.validated_data['backup_code'] != '' and not self.serializer.validated_data['backup_code'] is None:
                match_code = None
                codes = TwoFactorBackupCode.objects.filter(user=self.user)
                for code in codes:
                    if self.serializer.validated_data['backup_code'] == code.code:
                        match_code = code
                if not match_code:
                    raise InvalidBackupCode()
                else:
                    match_code.delete()
            # Verify 2FA code
            elif self.serializer.validated_data['two_factor_token'] != '' and not self.serializer.validated_data['two_factor_token'] is None:
                totp = TOTP(TwoFactorConfiguration.objects.get(user=self.user).totp_key)
                print(self.serializer.validated_data['two_factor_token'])
                print(totp.now())
                if not totp.verify(self.serializer.validated_data['two_factor_token']):
                    raise TwoFactorInvalid()
            # Raise Exception if code is not valid
            else:
                raise TwoFactorRequired()

        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(self.user)
        else:
            self.token = create_token(self.token_model, self.user,
                                      self.serializer)

        if getattr(settings, 'REST_SESSION_LOGIN', True):
            self.process_login()
コード例 #13
0
ファイル: views.py プロジェクト: mohandoz/happy
    def get_response(self):
        token = create_token(self.token_model, self.user, self.serializer)
        serializer_class = TokenSerializer

        serializer = serializer_class(instance=token,
                                          context={'request': self.request})

        return Response(serializer.data, status=status.HTTP_200_OK)
コード例 #14
0
ファイル: views.py プロジェクト: Tazman75/medtech
    def login(self):
        self.user = self.serializer.validated_data['user']

        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(self.user)
        else:
            self.token = create_token(self.token_model, self.user, self.serializer)

        if getattr(settings, 'REST_SESSION_LOGIN', True):
            login(self.request, self.user)
コード例 #15
0
ファイル: block.py プロジェクト: Qabel/qabel-accounting
def get_block_quota_of_user(user):
    logger = module_logger.getChild('get_block_quota_of_user')
    logger.info('Retrieving quota of user %r on %r', user.username, settings.BLOCK_URL)
    response = Session().get(BASE_URL + 'quota/', headers={
        'Authorization': 'Token %s' % create_token(TokenModel, user, None),
    })
    check_response(response, logger)
    quota = response.json()
    logger.info('Received quota: %r', quota)
    return quota['quota'], quota['size']
コード例 #16
0
    def login(self):
        self.user = self.serializer.validated_data['user']

        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(self.user)
        else:
            self.token = create_token(self.token_model, self.user,
                                      self.serializer)

        if getattr(settings, 'REST_SESSION_LOGIN', True):
            self.process_login()
コード例 #17
0
    def login(self):
        self.user = self.serializer.validated_data['user']

        if getattr(settings, 'REST_USE_JWT', False):
            self.token = get_login_token_with_auth_info(self.user, AuthAction.LOGIN, AuthProvider.BASIC)
        else:
            from rest_auth.app_settings import create_token
            self.token = create_token(self.token_model, self.user, self.serializer)

        if getattr(settings, 'REST_SESSION_LOGIN', True):
            self.process_login()
コード例 #18
0
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     if getattr(settings, 'REST_USE_JWT', False):
         self.token = jwt_encode(user)
     else:
         create_token(self.token_model, user, serializer)
     current_site = get_current_site(self.request)
     d = ({
         'email': user.email,
         'username': user.username,
         'WEB_SITE_URL': WEB_SITE_URL
     })
     plaintext = get_template('email-template/email.txt')
     htmly = get_template('email-template/welcome.html')
     subject, from_email, to = "Welcome To Tajinder's English Classes", settings.DEFAULT_FROM_EMAIL, user.email
     text_content = plaintext.render(d)
     html_content = htmly.render(d)
     # msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
     # msg.attach_alternative(html_content, "text/html")
     # msg.send()
     return user
コード例 #19
0
ファイル: block.py プロジェクト: AndanGagar/qabel-accounting
def get_block_quota_of_user(user):
    logger = module_logger.getChild('get_block_quota_of_user')
    logger.info('Retrieving quota of user %r on %r', user.username,
                settings.BLOCK_URL)
    response = Session().get(BASE_URL + 'quota/',
                             headers={
                                 'Authorization':
                                 'Token %s' %
                                 create_token(TokenModel, user, None),
                             })
    check_response(response, logger)
    quota = response.json()
    logger.info('Received quota: %r', quota)
    return quota['quota'], quota['size']
コード例 #20
0
    def perform_create(self, serializer):
        user = serializer.save(self.request)
        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            create_token(self.token_model, user, serializer)

        complete_signup(self.request._request, user,
                        allauth_settings.EMAIL_VERIFICATION, None)

        # Actualizo el usuario en UserCompany ahora el usuario está vinculado a
        # una empresa y un perfil
        try:
            my_user = UserCompany.objects.get(email=user.email)
            print('my_user', my_user)
            my_user.user = AuthUser.objects.get(email=user.email)
            #print ('my_user.user', my_user.user)
            my_user.save()
            my_user = AuthUser.objects.filter(
                email=user.email).values_list('id')
            print(my_user)
        except:
            pass
        return user
コード例 #21
0
    def login(self):
        """handle login request

        Only called if the user is active
        """

        self.user = self.serializer.validated_data['user']
        delete_token(self.user, log=False)
        if getattr(settings, "REST_USE_JWT", False):
            self.token = jwt_encode(self.user)
        else:
            self.token = create_token(self.token_model, self.user,
                                      self.serializer)

        if getattr(settings, "REST_SESSION_LOGIN", False):
            self.process_login()
        else:
            update_last_login(self.user)
コード例 #22
0
def login_view(request):
    #serializer = AuthTokenSerializer(data=request.data)
    if request.user.is_authenticated == True:
        error = {"detail": "You must have to log out first"}
        return Response(custom_api_response(errors=error),
                        status=status.HTTP_400_BAD_REQUEST)

    serializer = LoginSerializer(data=request.data)
    if serializer.is_valid():
        user = serializer.validated_data['user']
        token = create_token(TokenModel, user, serializer)
        #token = Token.objects.get(user=user)
        django_login(request, user)
        content = {'token': token.key, 'email': user.email, 'id': user.id}
        return Response(custom_api_response(serializer, content),
                        status=status.HTTP_200_OK)
        #return Response({'token': token.key, 'username': user.username, 'id': user.id})
    else:
        return Response(custom_api_response(serializer),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #23
0
 def login(self):
     self.user = self.serializer.validated_data['user']
     self.token = create_token(self.token_model, self.user,
                                   self.serializer)
     if getattr(settings, 'REST_SESSION_LOGIN', True):
         self.process_login()
コード例 #24
0
def token(user):
    return create_token(TokenModel, user, TokenSerializer)
コード例 #25
0
 def _login(self, user, serializer):
     create_token(self.token_model, user, serializer)
     if getattr(settings, 'REST_SESSION_LOGIN', True):
         login(self.request, user)
コード例 #26
0
 def create_login_token(user):
     serializer = LoginSerializer()
     token = create_token(TokenModel, user, serializer)
     return token
コード例 #27
0
 def perform_create(self, serializer):
     user_object = serializer.save()
     token = create_token(TokenModel, user_object, UserViewSetSerializer)
     return user_object, token
コード例 #28
0
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     create_token(self.token_model, user, serializer)
     return user
コード例 #29
0
 def get_response_data(self, user):
     token = create_token(user)
     data = jwt_response_payload_handler(token, user)
     return data
コード例 #30
0
    def login(self):
        self.user = self.serializer.validated_data['user']

        self.token = create_token(self.token_model, self.user, self.serializer)
コード例 #31
0
 def create_new_token(self,user):
     try:
         Token.objects.get(user=user).delete()
     except:
         pass
     create_token(self.token_model, user , None)