mirror of
https://github.com/krislamo/DJ-BaseSite
synced 2025-02-22 22:45:52 +00:00
Added custom title pages.
Added variable: "basetitle" to the config file which sets the title on index, login and registration pages as well as the admin pages. I then moved the code that connects to the SMTP server to above where the user is created in registration. I did this because if the connection fails then it wont continue and create a user that wont be able get an activation link. I also adjusted some indentions to make it easier to read on github.com
This commit is contained in:
parent
b8d3c338f8
commit
782a6e15d2
21
config.txt
21
config.txt
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
// CUSTOM VARIABLES
|
// CUSTOM VARIABLES
|
||||||
v baseurl http://127.0.0.1:8000
|
v baseurl http://127.0.0.1:8000
|
||||||
|
v basetitle DJ-BaseSite
|
||||||
|
|
||||||
v admin_name Kris619
|
v admin_name Kris619
|
||||||
v admin_email KrisPublicEmail@gmail.com
|
v admin_email KrisPublicEmail@gmail.com
|
||||||
@ -38,7 +39,9 @@ v HOSTpass HereItIs_HaveMyAccount
|
|||||||
|
|
||||||
// !!!!!!HEY, PAY ATTENTION FOR A SECOND!!!!!!
|
// !!!!!!HEY, PAY ATTENTION FOR A SECOND!!!!!!
|
||||||
// Don't mess with anything below unless you
|
// Don't mess with anything below unless you
|
||||||
// know what you are doing.
|
// know what you are doing. You can easily
|
||||||
|
// crash the Setup by putting things in the
|
||||||
|
// wrong order.
|
||||||
|
|
||||||
// DYNAMIC FILES
|
// DYNAMIC FILES
|
||||||
%here%/myproject/manage.py 1
|
%here%/myproject/manage.py 1
|
||||||
@ -47,6 +50,14 @@ v HOSTpass HereItIs_HaveMyAccount
|
|||||||
%here%/myproject/myproject/urls.py 1
|
%here%/myproject/myproject/urls.py 1
|
||||||
%here%/myproject/manage.py 1
|
%here%/myproject/manage.py 1
|
||||||
|
|
||||||
|
// Add these dir commands before actually adding
|
||||||
|
// the files from inside the folders.
|
||||||
|
|
||||||
|
// Admin
|
||||||
|
dir templates
|
||||||
|
dir templates/admin
|
||||||
|
%here%/myproject/myproject/templates/admin/base_site.html 1
|
||||||
|
|
||||||
// STATIC FILES
|
// STATIC FILES
|
||||||
%here%/myproject/myproject/__init__.py 2
|
%here%/myproject/myproject/__init__.py 2
|
||||||
%here%/myproject/myproject/views.py 2
|
%here%/myproject/myproject/views.py 2
|
||||||
@ -58,13 +69,9 @@ v HOSTpass HereItIs_HaveMyAccount
|
|||||||
// Activation Email
|
// Activation Email
|
||||||
%here%/myproject/myproject/activation_email.html 2
|
%here%/myproject/myproject/activation_email.html 2
|
||||||
|
|
||||||
// Add these dir commands before actually adding
|
|
||||||
// the files from inside the folders.
|
|
||||||
|
|
||||||
// HTML/CSS
|
// HTML/CSS
|
||||||
dir static
|
dir static
|
||||||
dir static/css
|
dir static/css
|
||||||
dir templates
|
|
||||||
%here%/myproject/myproject/static/css/default.css 2
|
%here%/myproject/myproject/static/css/default.css 2
|
||||||
%here%/myproject/myproject/templates/base.html 2
|
%here%/myproject/myproject/templates/base.html 2
|
||||||
%here%/myproject/myproject/templates/index.html 2
|
%here%/myproject/myproject/templates/index.html 2
|
||||||
@ -80,10 +87,6 @@ dir templates/auth
|
|||||||
%here%/myproject/myproject/templates/auth/newaccount.html 2
|
%here%/myproject/myproject/templates/auth/newaccount.html 2
|
||||||
%here%/myproject/myproject/templates/auth/registration.html 2
|
%here%/myproject/myproject/templates/auth/registration.html 2
|
||||||
|
|
||||||
// Admin
|
|
||||||
dir templates/admin
|
|
||||||
%here%/myproject/myproject/templates/admin/base_site.html 2
|
|
||||||
|
|
||||||
// Backend Django app
|
// Backend Django app
|
||||||
dir backends root
|
dir backends root
|
||||||
%here%/myproject/backends/__init__.py 2
|
%here%/myproject/backends/__init__.py 2
|
||||||
|
@ -16,6 +16,7 @@ DEBUG = True
|
|||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
|
||||||
baseurl = "<%baseurl%>" # "example.com"
|
baseurl = "<%baseurl%>" # "example.com"
|
||||||
|
base_title = "<%basetitle%>"
|
||||||
|
|
||||||
'''
|
'''
|
||||||
You need to sign up at http://recaptcha.net/ for a public/private key to use their CAPTCHA service.
|
You need to sign up at http://recaptcha.net/ for a public/private key to use their CAPTCHA service.
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "admin/base.html" %}
|
{% extends "admin/base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block title %}{{ title }} | {% trans 'Admin Site' %}{% endblock %}
|
{% block title %}{{ title }} | {% trans '<%basetitle%> Admin Site' %}{% endblock %}
|
||||||
|
|
||||||
{% block branding %}
|
{% block branding %}
|
||||||
<h1 id="site-name">{% trans 'Administration' %}</h1>
|
<h1 id="site-name">{% trans '<%basetitle%> Administration' %}</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block nav-global %}{% endblock %}
|
{% block nav-global %}{% endblock %}
|
||||||
|
@ -31,7 +31,8 @@ from django.core.mail import EmailMessage
|
|||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
|
||||||
# Variables from Settings.py
|
# Variables from Settings.py
|
||||||
from settings import EMAIL_HOST_USER, baseurl, EMAIL_MESSAGE
|
from settings import EMAIL_HOST_USER, EMAIL_MESSAGE
|
||||||
|
from settings import baseurl, base_title
|
||||||
|
|
||||||
# User Profile model
|
# User Profile model
|
||||||
from accountprofile.models import UserProfile
|
from accountprofile.models import UserProfile
|
||||||
@ -149,27 +150,25 @@ def login_user(request):
|
|||||||
# No object so the username and password are invalid.
|
# No object so the username and password are invalid.
|
||||||
login_errors = True
|
login_errors = True
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/login.html',
|
'auth/login.html',
|
||||||
locals(),
|
locals(),
|
||||||
context_instance=RequestContext(request)
|
context_instance=RequestContext(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# User isn't online and hasn't sent any POST data, give them a login form.
|
# User isn't online and hasn't sent any POST data, give them a login form.
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/login.html',
|
'auth/login.html',
|
||||||
locals(),
|
locals(),
|
||||||
context_instance=RequestContext(request)
|
context_instance=RequestContext(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# User is logged on, don't let them login until he's logged out.
|
# User is logged on, don't let them login until he's logged out.
|
||||||
user_navigation = user_nav(request.user.username)
|
user_navigation = user_nav(request.user.username)
|
||||||
error = "You're already logged on."
|
error = "You're already logged on."
|
||||||
responce = render_to_response(
|
responce = render_to_response('error.html',locals())
|
||||||
'error.html',
|
|
||||||
locals()
|
|
||||||
)
|
|
||||||
return responce
|
return responce
|
||||||
|
|
||||||
def register_user(request):
|
def register_user(request):
|
||||||
@ -198,11 +197,11 @@ def register_user(request):
|
|||||||
|
|
||||||
# Is human?
|
# Is human?
|
||||||
HumanTestResult = captcha.submit(
|
HumanTestResult = captcha.submit(
|
||||||
request.POST["recaptcha_challenge_field"],
|
request.POST["recaptcha_challenge_field"],
|
||||||
request.POST["recaptcha_response_field"],
|
request.POST["recaptcha_response_field"],
|
||||||
captcha_privatekey,
|
captcha_privatekey,
|
||||||
get_ip(request)
|
get_ip(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
# If not human: display errors
|
# If not human: display errors
|
||||||
if HumanTestResult.is_valid:
|
if HumanTestResult.is_valid:
|
||||||
@ -241,34 +240,43 @@ def register_user(request):
|
|||||||
else:
|
else:
|
||||||
registration_errors.append("Invalid human verification code.")
|
registration_errors.append("Invalid human verification code.")
|
||||||
captcha_test = captcha.displayhtml(
|
captcha_test = captcha.displayhtml(
|
||||||
captcha_publickey,
|
captcha_publickey,
|
||||||
False,
|
False,
|
||||||
HumanTestResult.error_code)
|
HumanTestResult.error_code
|
||||||
|
)
|
||||||
|
|
||||||
|
# Connect to SMTP server
|
||||||
|
connection = mail.get_connection()
|
||||||
|
connection.open()
|
||||||
|
|
||||||
# If no errors: create user.
|
# If no errors: create user.
|
||||||
if len(registration_errors) == 0:
|
if len(registration_errors) == 0:
|
||||||
new_user = User.objects.create_user(
|
new_user = User.objects.create_user(
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
request.POST["repassw"]
|
request.POST["repassw"]
|
||||||
)
|
)
|
||||||
|
|
||||||
new_user.is_active = True
|
new_user.is_active = True
|
||||||
new_user.save()
|
new_user.save()
|
||||||
|
|
||||||
# Create activation key and user profile
|
# Create activation key and user profile
|
||||||
activation_key = UserActivationKey()
|
activation_key = UserActivationKey()
|
||||||
profile = UserProfile(
|
profile = UserProfile(
|
||||||
activatekey=activation_key,
|
activatekey=activation_key,
|
||||||
activated=False,
|
activated=False,
|
||||||
user=new_user)
|
user=new_user)
|
||||||
profile.save()
|
profile.save()
|
||||||
|
|
||||||
# User is created and saved. Send an activation link via email
|
# User is created and saved. Send an activation link via email
|
||||||
connection = mail.get_connection()
|
|
||||||
connection.open()
|
|
||||||
|
|
||||||
message_activateurl = baseurl+"/activate/?key="+str(activation_key)+"&user="+str(new_user.username)
|
# Activation link
|
||||||
message_deactivateurl = baseurl+"/deactivate/?key="+str(activation_key)+"&user="+str(new_user.username)
|
message_activateurl = baseurl+"/activate/?key="+str(activation_key)
|
||||||
|
message_activateurl = message_activateurl+"&user="+str(new_user.username)
|
||||||
|
|
||||||
|
# Deactivation link
|
||||||
|
message_deactivateurl = baseurl+"/deactivate/?key="+str(activation_key)
|
||||||
|
message_deactivateurl = message_deactivateurl+"&user="+str(new_user.username)
|
||||||
|
|
||||||
f = open(EMAIL_MESSAGE, 'r')
|
f = open(EMAIL_MESSAGE, 'r')
|
||||||
message = f.read()
|
message = f.read()
|
||||||
@ -278,35 +286,39 @@ def register_user(request):
|
|||||||
message = message.replace("<$disablelink>", message_deactivateurl)
|
message = message.replace("<$disablelink>", message_deactivateurl)
|
||||||
|
|
||||||
email = EmailMessage(
|
email = EmailMessage(
|
||||||
"Account Activation",
|
"Account Activation",
|
||||||
message,
|
message,
|
||||||
EMAIL_HOST_USER,
|
EMAIL_HOST_USER,
|
||||||
[new_user.email])
|
[new_user.email]
|
||||||
|
)
|
||||||
|
|
||||||
email.send()
|
email.send()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
# Return new account page
|
# Return new account page
|
||||||
accountname = new_user.username
|
accountname = new_user.username
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/newaccount.html',
|
'auth/newaccount.html',
|
||||||
locals(),
|
locals(),
|
||||||
context_instance=RequestContext(request)
|
context_instance=RequestContext(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Return registration form with errors in registration_errors
|
# Return registration form with errors in registration_errors
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/registration.html',
|
'auth/registration.html',
|
||||||
locals(),
|
locals(),
|
||||||
context_instance=RequestContext(request)
|
context_instance=RequestContext(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
# If user hasn't sent POST data (not logged on)
|
# If user hasn't sent POST data (not logged on)
|
||||||
else:
|
else:
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/registration.html',
|
'auth/registration.html',
|
||||||
locals(),
|
locals(),
|
||||||
context_instance=RequestContext(request)
|
context_instance=RequestContext(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
# User is logged on
|
# User is logged on
|
||||||
else:
|
else:
|
||||||
user_navigation = user_nav(request.user.username)
|
user_navigation = user_nav(request.user.username)
|
||||||
@ -346,14 +358,14 @@ def activate_user(request):
|
|||||||
if key_correct:
|
if key_correct:
|
||||||
user_name = user.username
|
user_name = user.username
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'auth/activated.html',
|
'auth/activated.html',
|
||||||
locals()
|
locals()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
error = "Activation failed."
|
error = "Activation failed."
|
||||||
responce = render_to_response(
|
responce = render_to_response(
|
||||||
'error.html',
|
'error.html',
|
||||||
locals()
|
locals()
|
||||||
)
|
)
|
||||||
|
|
||||||
return responce
|
return responce
|
||||||
|
Loading…
x
Reference in New Issue
Block a user