예제 #1
0
파일: views.py 프로젝트: Hamdy/minilab
def resend_activation(request):
    if request.user.is_authenticated():
        return HttpResponseForbidden()
    
    if request.method == "GET":
        form = ResendActTokenForm()
    elif request.method == "POST":
        form = ResendActTokenForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            User = get_user_model()
            user = User.objects.filter(email=email)[0]
            user.reset_activation_token()
            user.save()
            actvation_token_reset.send(sender=get_user_model(), token=user.activation_token)
            return render(request, 'message.html', {'message':ACT_TOKEN_RESENT})
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET'])

    return render(request, 'registration/resend_act_token.html', {'form':form})
예제 #2
0
파일: views.py 프로젝트: Hamdy/minilab
def message(request):
    if not request.method == 'GET':
        return HttpResponseNotAllowed(permitted_methods=['GET'])
    
    message = request.GET.get('message')
    
    if message not in ['reg_successful']:
        return HttpResponseForbidden()
    
    data = {}
    if message == REG_SUCCESSFUL:
        data['message'] = REG_SUCCESSFUL_MESSAGE
            
    return render(request, 'message.html', data)
예제 #3
0
def resend_activation(request):
    if request.user.is_authenticated():
        return HttpResponseForbidden()

    if request.method == "GET":
        form = ResendActTokenForm()
    elif request.method == "POST":
        form = ResendActTokenForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            User = get_user_model()
            user = User.objects.filter(email=email)[0]
            user.reset_activation_token()
            user.save()
            actvation_token_reset.send(sender=get_user_model(),
                                       token=user.activation_token)
            return render(request, 'message.html',
                          {'message': ACT_TOKEN_RESENT})
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET'])

    return render(request, 'registration/resend_act_token.html',
                  {'form': form})
예제 #4
0
def message(request):
    if not request.method == 'GET':
        return HttpResponseNotAllowed(permitted_methods=['GET'])

    message = request.GET.get('message')

    if message not in ['reg_successful']:
        return HttpResponseForbidden()

    data = {}
    if message == REG_SUCCESSFUL:
        data['message'] = REG_SUCCESSFUL_MESSAGE

    return render(request, 'message.html', data)
예제 #5
0
파일: views.py 프로젝트: Hamdy/minilab
def register(request):
    if request.method == 'GET':
        form = RegistrationForm()
    elif request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = get_user_model()
            user = user()
            user.username = form.cleaned_data.get('username')
            user.email = form.cleaned_data.get('email')
            user.password = make_password(form.cleaned_data.get('password'))
            user.is_active = False
            user.reset_activation_token()
            user.generate_verification_token()
            user.save()
            
            return redirect("%s?message=%s" %
                (reverse('message'), REG_SUCCESSFUL))
    else:
        return HttpResponseNotAllowed(permitted_methods=['POST', 'GET'])
    return render(request, 'registration/register.html', {'form':form})
예제 #6
0
def register(request):
    if request.method == 'GET':
        form = RegistrationForm()
    elif request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = get_user_model()
            user = user()
            user.username = form.cleaned_data.get('username')
            user.email = form.cleaned_data.get('email')
            user.password = make_password(form.cleaned_data.get('password'))
            user.is_active = False
            user.reset_activation_token()
            user.generate_verification_token()
            user.save()

            return redirect("%s?message=%s" %
                            (reverse('message'), REG_SUCCESSFUL))
    else:
        return HttpResponseNotAllowed(permitted_methods=['POST', 'GET'])
    return render(request, 'registration/register.html', {'form': form})
예제 #7
0
파일: views.py 프로젝트: Hamdy/minilab
def activate(request, token=''):
    if request.method != "GET":
        return HttpResponseNotAllowed(permitted_methods=['GET'])
    
    if request.user.is_authenticated():
        return HttpResponseForbidden()

    User = get_user_model()
    users = User.objects.filter(activation_token=token)
    
    if not users:
        return HttpResponseNotFound()
    
    user = users[0]
    if user.is_active:
        return HttpResponseNotFound()
    data = {}
    
    if user.token_expired:
        data['message'] = ACT_TOKEN_EXPIRED
    else:
        user.activate()
        data['message'] = ACT_SUCCESSFUL
    return render(request, 'message.html', data)
예제 #8
0
def activate(request, token=''):
    if request.method != "GET":
        return HttpResponseNotAllowed(permitted_methods=['GET'])

    if request.user.is_authenticated():
        return HttpResponseForbidden()

    User = get_user_model()
    users = User.objects.filter(activation_token=token)

    if not users:
        return HttpResponseNotFound()

    user = users[0]
    if user.is_active:
        return HttpResponseNotFound()
    data = {}

    if user.token_expired:
        data['message'] = ACT_TOKEN_EXPIRED
    else:
        user.activate()
        data['message'] = ACT_SUCCESSFUL
    return render(request, 'message.html', data)