Esempio n. 1
0
def reset_password(request):
    if request.method == 'POST':

        json_data = json.loads(request.body)
        check_recaptcha(json_data['recaptchaToken'])

        try:

            json_data = json.loads(request.body)
            email = json_data['email']
            murren = Murren.objects.get(email=email)

        except (TypeError, ValueError, OverflowError,
                Murren.DoesNotExist) as error_text:

            error = error_text
            murren = None

        if murren is not None:

            message = base_url + '/set_new_password/?activation_code=' \
                      + urlsafe_base64_encode(force_bytes(murren.email))
            subject = '[murrengan] Восстановление пароля Муррена'
            html_data = render_to_string('reset_email.html', {
                'uri': message,
                'murren_name': murren.username
            })
            send_mail(subject,
                      None,
                      'Murrengan <*****@*****.**>', [murren.email],
                      html_message=html_data)

            return JsonResponse({'email_sent_successfully': True})

        else:

            return JsonResponse({
                'error_on_backend': True,
                'error_text': error.args[0]
            })
Esempio n. 2
0
def murren_register(request):
    if request.method == 'POST':

        json_data = json.loads(request.body)

        check_recaptcha(json_data['recaptchaToken'])

        murren_data = {
            'username': json_data['username'],
            'email': json_data['email'],
            'password': json_data['password'],
        }

        form = MurrenSignupForm(murren_data)

        if form.is_valid():

            user = form.save(commit=False)
            user.is_active = False
            user.set_password(murren_data.get('password'))
            user.save()

            message = base_url + '/murren_email_activate/?activation_code=' \
                      + urlsafe_base64_encode(force_bytes(user.pk))
            subject = '[murrengan] Активация аккаунта Муррена'
            html_data = render_to_string('activation_email.html', {
                'uri': message,
                'murren_name': user.username
            })
            send_mail(subject,
                      None,
                      'Murrengan <*****@*****.**>',
                      [murren_data.get('email')],
                      html_message=html_data)

            return JsonResponse({'is_murren_created': 'true'})

        else:

            return JsonResponse(form.errors)
Esempio n. 3
0
def confirm_new_password(request):
    if request.method == 'POST':

        json_data = json.loads(request.body)
        check_recaptcha(json_data['recaptchaToken'])

        murren_email = force_text(
            urlsafe_base64_decode(json_data['murren_email']))
        murren_password_1 = json_data['murren_password_1']
        murren_password_2 = json_data['murren_password_2']

        if murren_password_1 != murren_password_2:

            return JsonResponse({'password_not_equal': 'true'})

        try:

            murren = Murren.objects.get(email=murren_email)

        except (TypeError, ValueError, OverflowError,
                Murren.DoesNotExist) as error_text:

            error = error_text
            murren = None

        if murren is not None:

            murren.set_password(murren_password_2)
            murren.is_active = True
            murren.save()

            return JsonResponse({'password_successfully_changed': True})

        else:

            return JsonResponse({
                'error_on_backend': True,
                'error_text': error.args[0]
            })