Esempio n. 1
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
        # request.session['user'] = user
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None:
        # if user already activated account
        if user.is_active:
            messages.error(request, 'Your account is already activated!')
            return redirect('members:account_home')
        #  if activation token is valid
        elif account_activation_token.check_token(user, token):
            print("activating...")
            user.is_active = True
            user.save()
            login(request, user)
            messages.success(request,
                             "Congratulations, you are our members now !")
            return redirect('members:account_home')
        # if token expires but user's inactive profile remains
        elif not account_activation_token.check_token(user, token):
            return HttpResponseNotFound(
                "Sorry, your validation email has expired.")
            #  if user's inactive profile has been removed
    else:
        messages.error(
            request,
            'Sorry, your registration has expired. Please sign up again')
        return redirect(reverse_lazy('members:signup'))
Esempio n. 2
0
    def test_check_user_email_token_equal(self):
        """
        user 회원가입 후 발송되는 인증 확인 이메일 token값과 DB에 저장되는 이메일 token 값이 같은지 확인
        :return:
        """
        user = get_dummy_user()

        # user email token 값과 DB상의 토큰 값 비교
        token = account_activation_token.make_token(user)
        self.assertTrue(account_activation_token.check_token(user, token))
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        return render(request, 'members/user_active_complete.html')
    else:
        return HttpResponse('Activation link is invalid!')
Esempio n. 4
0
    def get(self, request, uidb64, token):
        try:
            # uid = force_text(urlsafe_base64_decode(uidb64.encode('utf-8')))
            uid = force_text(urlsafe_base64_decode(uidb64))
            user = User.objects.get(pk=uid)

        except (TypeError.ValueError, OverflowError, User.DoesNotExist):
            user = None

        try:
            if user is not None and account_activation_token.check_token(
                    user, token):
                user.is_active = True
                user.save()
                return Response(user.email + '계정이 활성화 되었습니다.',
                                status=status.HTTP_200_OK)
            else:
                return Response('만료된 링크입니다.',
                                status=status.HTTP_400_BAD_REQUEST)

        except Exception as e:
            print(traceback.format_exc())
Esempio n. 5
0
def user_activate(request, uidb64, token):

    try:
        # uid = force_text(urlsafe_base64_decode(uidb64.encode('utf-8')))
        uid = force_text(urlsafe_base64_decode(uidb64))
        print(
            f'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ {uid}'
        )
        user = User.objects.get(pk=uid)

    except (TypeError.ValueError, OverflowError, User.DoesNotExist):
        user = None

    try:
        if user is not None and account_activation_token.check_token(
                user, token):
            user.is_active = True
            user.save()
            return HttpResponse(user.email + '계정이 활성화 되었습니다.')
        else:
            return HttpResponse('만료된 링크입니다.')

    except Exception as e:
        print(traceback.format_exc())