def invite_with_mail(request, template="invite_with_mail.html"): if request.method == "POST": form = InvitationWithMailForm(request.POST) if form.is_valid(): inviter = request.user # TODO: Erhan we need a mail template to send users to invite subject = "%s Has Invited You to Heroject" % inviter.username message = render_to_string( "mail_templates/invitation_mail.html", {"username": inviter.username, "full_name": inviter.get_full_name()}, ) sender = EMAIL_HOST_USER recipients = [form.cleaned_data["email"]] mail_sender(subject=subject, message=message, sender=sender, recipients=recipients) messages.add_message(request, messages.SUCCESS, "Your invitation has successfully sended to recepient.") form = InvitationWithMailForm() redirect("invite_with_mail") else: form = InvitationWithMailForm() return render(request, template, {"form": form})
def register_user(request, register_success_url="/", template="register.html"): """ Registration view """ if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password1'] user = Profile.objects.create_user( username=username, email=email, password=password) user.save() #TODO: Erhan we need a mail template to send users to say hello subject = "Welcome to Heroject" message = render_to_string('mail_templates/welcome_mail.html', {'username': username, 'password': password, 'email': email}) sender = EMAIL_HOST_USER recipients = [email] mail_sender(subject=subject, message=message, sender=sender, recipients=recipients) auth_usr = authenticate(username=username, password=password) if auth_usr: login(request, auth_usr) return redirect(register_success_url) else: form = RegistrationForm() return render(request, template, {'form': form})