Example #1
0
def new_user(request):
    categorias = Categorias.objects.all()
    if request.method == 'POST':
        formuser = UserCreationForm(request.POST)
        formemail = EmailForm(request.POST)
        if formemail.is_valid() and formuser.is_valid() :
            code = code_activation_create()
            email = formemail.cleaned_data['email']
            u = formuser.save()
            u.email = email
            u.is_active = False
            u.save()
            p = Perfil.objects.create(
                code_activation = code,
                usuario = u,
            )
            subject = 'Confirmacion De Correo Electronico'
            text_content = 'Mensaje...nLinea 2nLinea3'
            html_content = '<h2>Confirmacion de Correo</h2><p>Haga click en el siguiente Enlace</p><p><a href="http://ahiteveo1.herokuapp.com/user/confirmar/?code='+code+'">Confirmar Cuenta</a></p>'
            from_email = '"AhiTeVeo" <*****@*****.**>'
            to = email
            msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            msm = "Su Cuenta fue creada Correctamente<br>Un Mensaje fue enviado a su correo para activar su cuenta"
            messages.add_message(request, messages.INFO, msm)
            return HttpResponseRedirect('/')
    else:
        formuser = UserCreationForm()
        formemail = EmailForm()
    return render(request, 'users/new_user.html', {
        'formuser':formuser,
        'formemail':formemail,
        'categorias':categorias,
    })
Example #2
0
    def post(self, request, *args, **kwargs):
        print request.data
        data = request.data.get('value')
        form = EmailForm(data={"email": data})
        valid = form.is_valid()

        return create_validation_response(data, valid, form.errors.get('email'))
Example #3
0
def pre_register(request):

    if request.method == "POST":
        form = EmailForm(request.POST)
        if form.is_valid():
            email_address = form.cleaned_data.get("email_address")
            register_link = f'{settings.DEFAULT_DOMAIN}{reverse("register")}'
            send_mail(
                "Join LocalLibrary!",
                "Click the link below.",
                os.environ.get("EMAIL_USER1"),
                [
                    email_address,
                ],
                fail_silently=False,
                html_message=
                f'Click the link below to register: <br/> <a href="{register_link}">{register_link}</a>',
            )
            messages.success(
                request,
                f'An email has been sent to <a class="alert-link">{email_address}</a> !',
                extra_tags="safe",
            )
            return redirect(reverse("index"))

    else:
        form = EmailForm()

    context = {"form": form}

    return render(request, "users/email_form.html", context)
Example #4
0
    def post(self, request, *args, **kwargs):
        print request.data
        data = request.data.get('value')
        form = EmailForm(data={"email": data})
        valid = form.is_valid()

        return create_validation_response(data, valid,
                                          form.errors.get('email'))
Example #5
0
def ask_email(request):
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            request.session['saved_email'] = form.cleaned_data['email']
            backend = request.session['partial_pipeline']['backend']
            return redirect('socialauth_complete', backend=backend)
    else:
        form = EmailForm()

    return render_to_response('social_auth/ask_email.html', {'form': form},
                              RequestContext(request))
Example #6
0
def newEmail(request):
	user = request.user
	profile = user.get_profile()
	if request.POST:
		form = EmailForm(request.POST)
		if form.is_valid():
			set_mail(user, form.cleaned_data["email"])
			return render_to_response('users/newmail.html', {'set': True}, RequestContext(request))
	else:
		form = EmailForm()
		if not profile.mail_confirmed and user.email != "":
			return render_to_response('users/newmail.html', {'unfinished': True}, RequestContext(request))
	return render_to_response('users/newmail.html', {'form': form}, RequestContext(request))
Example #7
0
def email_change(request):
    """ The email change page
    
    If you pass it an EmailForm, it will save it, and display a message. If it fails, it renders the users home page.
    """
    if request.method == "POST":
        form = EmailForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return home(request, "Email Changed Successfully")
    
    else:
        form = EmailForm(instance=request.user)
    
    ctx = _make_context(request, "email_form", form)
    
    return TemplateResponse(request, "users/index.html", ctx)
Example #8
0
def newEmail(request):
    user = request.user
    profile = user.get_profile()
    if request.POST:
        form = EmailForm(request.POST)
        form.user = request.user
        if form.is_valid():
            set_mail(user, form.cleaned_data["email"])
            return render_to_response('users/newmail.html', {'set': True},
                                      RequestContext(request))
    else:
        form = EmailForm()
        if not profile.mail_confirmed and user.email != "":
            return render_to_response('users/newmail.html',
                                      {'unfinished': True},
                                      RequestContext(request))
    return render_to_response('users/newmail.html', {'form': form},
                              RequestContext(request))
Example #9
0
def thanks(request, user_id):
    user = get_object_or_404(Users, id=user_id)
    registration_form = EmailForm(user_id=user_id)
    context = RequestContext(request)
    l = []
    if request.method == 'POST':
        form = EmailForm(request.POST, user_id=user_id)
        if form.is_valid():
            datas = {}
            datas['first_name'] = user.first_name
            datas['last_name'] = user.last_name
            datas['username'] = user.username
            datas['password'] = user.password
            datas['email'] = form.cleaned_data['email']
            datas['timezone'] = settings.TIME_ZONE
            datas[
                'preferred_languages'] = "[\"" + settings.LANGUAGE_CODE + "\"]"
            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
            usernamesalt = datas['username']
            if isinstance(usernamesalt, unicode):
                usernamesalt = usernamesalt.encode('utf8')
            datas['activation_key'] = hashlib.sha1(salt +
                                                   usernamesalt).hexdigest()

            datas['email_path'] = "/ActivationEmail.txt"
            datas['email_subject'] = _("Activate your user account for CMS")
            if not user.is_active:
                form.sendEmail(datas)
                form.save(datas)  #Save the user and his profile
            el = get_object_or_404(Users, username=user.username)
            request.session['registered'] = True  #For display purposes
            return redirect(settings.URL + settings.THANKS + "/" +
                            str(user.id) + "/")
        else:
            registration_form = form  #Display form with error messages (incorrect fields, etc)

    return render(
        request, 'thanks.html', {
            'user': user,
            'formset': registration_form,
            'u': settings.CMS_URL,
            'lpl': lpl
        }, locals())
Example #10
0
 def test_email_form_is_invalid(self):
     form = EmailForm(data={'email': 'abc123'})
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 1)
Example #11
0
 def test_email_form_is_valid(self):
     form = EmailForm(data={'email': '*****@*****.**'})
     self.assertTrue(form.is_valid())