コード例 #1
0
ファイル: views.py プロジェクト: HerbertChu/gangurru
def register(request):
    if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']
            if password.__len__() == 0 or username.__len__() == 0:
                return render(request, 'index.html', {'message': 'INPUT_ERROR'})
            try:
                validators.validate_email(username)
            except forms.ValidationError:
                return render(request, 'index.html', {'message': 'MAIL_ERROR'})

            if username is not None and password is not None:
                user = User(username=username, password=make_password(password), is_active=False)
                user.save()
                profile = Profile(user=user, ipaddr=ipHelper.get_client_ip(request), last_date=timezone.now())
                profile.save()
                try:
                    subject, from_email, to = 'Hello ...', '*****@*****.**', username
                    text_content = 'This is an important message.'
                    html_content1 = '<img src=\"https://photos-4.dropbox.com/t/2/AADz6TCPLjDlC2J0BJdTZdqWsRYtDCm9EULtTsGIuXh0oQ/12/6639851/png/32x32/1/_/1/2/bb_logo.png/EOrw1oQCGIoPIAcoBw/g31AMVol6mHfY-0RAV-91MyAGGz4W9EP0EN-4iriUSM?size=1024x768&size_mode=2\">'
                    html_content2 = u'<p>歡迎加入<strong>BBStar</strong> 請點下面這個按鈕啟動帳戶</p><input type=\"button\" value=\"啟動\"/>'
                    msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
                    msg.attach_alternative(html_content1+html_content2, "text/html")
                    msg.send()
                except BadHeaderError:
                    return render(request, 'index.html', {'user': user, 'message': 'MAIL_ERROR'})
                return render(request, 'index.html', {'user': user, 'message': 'PLEASE_CHECK_EMAIL'})
    return redirect('/bbstar/')
コード例 #2
0
ファイル: views.py プロジェクト: HerbertChu/gangurru
def index(request):
    show = ['Hello BBStar ...']
    print ipHelper.get_client_ip(request), show, timezone.now()
    return render(request, 'index.html')