Adding registration and activation.
This commit is contained in:
commit
00256870f8
@ -5,3 +5,5 @@ scribeengine.sqlite
|
|||||||
posts.sql
|
posts.sql
|
||||||
*.egg-info
|
*.egg-info
|
||||||
ScrivbeEngine.e4p
|
ScrivbeEngine.e4p
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
@ -43,6 +43,7 @@ security.salt = secretsalt
|
|||||||
|
|
||||||
mail.on = false
|
mail.on = false
|
||||||
mail.manager = immediate
|
mail.manager = immediate
|
||||||
|
mail.transport = smtp
|
||||||
mail.smtp.server = mail.mydomain.com
|
mail.smtp.server = mail.mydomain.com
|
||||||
mail.smtp.username = mymailusername
|
mail.smtp.username = mymailusername
|
||||||
mail.smtp.password = mymailpassword
|
mail.smtp.password = mymailpassword
|
||||||
|
@ -1 +0,0 @@
|
|||||||
/home/raoul/VirtualEnv/ScribeEngine/feeds/bin/paster serve development.ini --reload
|
|
@ -23,6 +23,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from scribeengine.lib.base import *
|
from scribeengine.lib.base import *
|
||||||
from scribeengine.lib.validation.client import JSString, JSEmail
|
from scribeengine.lib.validation.client import JSString, JSEmail
|
||||||
@ -47,7 +48,7 @@ class AdminController(BaseController):
|
|||||||
return {
|
return {
|
||||||
u'email': JSEmail(required=True, message=u'You haven\'t typed in an e-mail address.'),
|
u'email': JSEmail(required=True, message=u'You haven\'t typed in an e-mail address.'),
|
||||||
u'password': JSString(required=True, message=u'You haven\'t typed in a password.'),
|
u'password': JSString(required=True, message=u'You haven\'t typed in a password.'),
|
||||||
u'confirm-password': JSString(required=True, equalTo=u'password', message=u'Your passwords don\'t match.')
|
u'confirm-password': JSString(required=True, equalTo=u'#password', message=u'Your passwords don\'t match.')
|
||||||
}
|
}
|
||||||
|
|
||||||
def register_schema(self):
|
def register_schema(self):
|
||||||
@ -67,8 +68,55 @@ class AdminController(BaseController):
|
|||||||
)
|
)
|
||||||
Session.add(user)
|
Session.add(user)
|
||||||
Session.commit()
|
Session.commit()
|
||||||
|
blog_mail = Session.query(Variable).get(u'blog mail')
|
||||||
|
blog_title = Session.query(Variable).get(u'blog title')
|
||||||
|
blog_host = Session.query(Variable).get(u'blog host')
|
||||||
|
if not blog_host:
|
||||||
|
url = u'%s://%s' % (request.environ[u'wsgi.url_scheme'],
|
||||||
|
request.environ[u'HTTP_HOST'])
|
||||||
|
blog_host = Variable(key=u'blog host', value=url)
|
||||||
|
Session.add(blog_host)
|
||||||
|
Session.commit()
|
||||||
|
utils.send_mail(u'/email/activate.mako', u'%s <%s>' % (user.nick, user.email),
|
||||||
|
u'%s <%s>' % (blog_mail.value, blog_title.value),
|
||||||
|
u'[%s] Activate your account!' % blog_title.value,
|
||||||
|
{
|
||||||
|
'user': user,
|
||||||
|
'blog_title': blog_title.value,
|
||||||
|
'blog_host': blog_host.value
|
||||||
|
})
|
||||||
|
h.flash.set_message(u'An e-mail has been sent to your e-mail address. '
|
||||||
|
u'Please activate your account by clicking on the link in your '
|
||||||
|
u'e-mail.', u'success')
|
||||||
h.redirect_to('/')
|
h.redirect_to('/')
|
||||||
|
|
||||||
|
def activate(self, id=None):
|
||||||
|
activation_code = request.GET.get('code')
|
||||||
|
if not activation_code:
|
||||||
|
h.flash.set_message(u'Your activation code was missing or '
|
||||||
|
u'incorrect. Please check your activation e-mail.', u'error')
|
||||||
|
h.redirect_to(h.url_for(action=u'register'))
|
||||||
|
if not id:
|
||||||
|
h.flash.set_message(u'Your username was missing or incorrect. '
|
||||||
|
u'Please check your activation e-mail.', u'error')
|
||||||
|
h.redirect_to(h.url_for(action=u'register'))
|
||||||
|
user = Session.query(User)\
|
||||||
|
.filter_by(id=id)\
|
||||||
|
.filter_by(activation_key=activation_code)\
|
||||||
|
.first()
|
||||||
|
if not user:
|
||||||
|
h.flash.set_message(u'Your username or activation code is '
|
||||||
|
u'incorrect. Please check your activation e-mail.', u'error')
|
||||||
|
h.redirect_to(h.url_for(action=u'register'))
|
||||||
|
user.activation_key = None
|
||||||
|
user.modified = datetime.now()
|
||||||
|
Session.add(user)
|
||||||
|
Session.commit()
|
||||||
|
h.flash.set_message(u'Your account has been activated! Please log in '
|
||||||
|
u'with your e-mail address and the password you typed in during '
|
||||||
|
u'registration.', u'success')
|
||||||
|
h.redirect_to(h.url_for(action=u'login'))
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
c.page_title = u'Login'
|
c.page_title = u'Login'
|
||||||
return render(u'/admin/login.mako')
|
return render(u'/admin/login.mako')
|
||||||
@ -90,11 +138,14 @@ class AdminController(BaseController):
|
|||||||
log.debug('Logging in as "%s" with password "%s"', c.form_values[u'email'], c.form_values[u'password'])
|
log.debug('Logging in as "%s" with password "%s"', c.form_values[u'email'], c.form_values[u'password'])
|
||||||
user = Session.query(User).filter_by(email=c.form_values[u'email']).first()
|
user = Session.query(User).filter_by(email=c.form_values[u'email']).first()
|
||||||
password = utils.hash_password(c.form_values[u'password'])
|
password = utils.hash_password(c.form_values[u'password'])
|
||||||
log.debug(user)
|
|
||||||
if not user or user.password != password:
|
if not user or user.password != password:
|
||||||
log.debug('Username or password are incorrect.')
|
log.debug('Username or password are incorrect.')
|
||||||
h.flash.set_message(u'Your username or password are incorrect.', u'error')
|
h.flash.set_message(u'Your username or password are incorrect.', u'error')
|
||||||
h.redirect_to('/admin/login')
|
h.redirect_to(h.url_for(action=u'login'))
|
||||||
|
elif user and user.activation_key is not None:
|
||||||
|
log.debug('Unactivated account.')
|
||||||
|
h.flash.set_message(u'Your account has not yet been activated. Please check your e-mail for a link to activate your account.', u'error')
|
||||||
|
h.redirect_to(h.url_for(action=u'login'))
|
||||||
elif user and user.password == password:
|
elif user and user.password == password:
|
||||||
log.debug('Logged in successfully.')
|
log.debug('Logged in successfully.')
|
||||||
redirect_url = str(session.get(u'redirect_url', u'/'))
|
redirect_url = str(session.get(u'redirect_url', u'/'))
|
||||||
@ -109,10 +160,11 @@ class AdminController(BaseController):
|
|||||||
del session[u'REMOTE_USER']
|
del session[u'REMOTE_USER']
|
||||||
session.save()
|
session.save()
|
||||||
h.flash.set_message(u'There was a problem logging you in.', u'error')
|
h.flash.set_message(u'There was a problem logging you in.', u'error')
|
||||||
h.redirect_to('/admin/login')
|
h.redirect_to(h.url_for(action=u'login'))
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
del session[u'REMOTE_USER']
|
del session[u'REMOTE_USER']
|
||||||
session.save()
|
session.save()
|
||||||
|
h.flash.set_message(u'You have logged out successfully.', u'success')
|
||||||
h.redirect_to('/')
|
h.redirect_to('/')
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ import string
|
|||||||
from random import choice
|
from random import choice
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from pylons import config
|
from pylons import config, c
|
||||||
from turbomail import Message
|
from turbomail import Message
|
||||||
|
|
||||||
from scribeengine.lib.base import render, c
|
from scribeengine.lib.base import render
|
||||||
|
|
||||||
def send_mail(template, mail_to, mail_from, subject, variables={}, attachments=[]):
|
def send_mail(template, mail_to, mail_from, subject, variables={}, attachments=[]):
|
||||||
"""
|
"""
|
||||||
|
@ -100,10 +100,10 @@ users_table = Table(u'users', metadata,
|
|||||||
Column(u'email', Unicode(200), nullable=False, index=True),
|
Column(u'email', Unicode(200), nullable=False, index=True),
|
||||||
Column(u'password', Unicode(64), nullable=False),
|
Column(u'password', Unicode(64), nullable=False),
|
||||||
Column(u'nick', Unicode(50), nullable=False, index=True),
|
Column(u'nick', Unicode(50), nullable=False, index=True),
|
||||||
Column(u'first_name', Unicode(100)),
|
Column(u'first_name', Unicode(100), default=u''),
|
||||||
Column(u'last_name', Unicode(100)),
|
Column(u'last_name', Unicode(100), default=u''),
|
||||||
Column(u'homepage', Unicode(200)),
|
Column(u'homepage', Unicode(200), default=u''),
|
||||||
Column(u'activation_key', Unicode(40))
|
Column(u'activation_key', Unicode(40), default=None)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Definition of the "variables" table
|
# Definition of the "variables" table
|
||||||
|
@ -404,6 +404,10 @@ fieldset {
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#register-now {
|
||||||
|
margin-left: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
/* Message areas */
|
/* Message areas */
|
||||||
|
|
||||||
#form-errors {
|
#form-errors {
|
||||||
@ -414,8 +418,7 @@ fieldset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#message {
|
#message {
|
||||||
margin-top: 1.8em;
|
margin-bottom: 1.8em;
|
||||||
/*padding: 0.3em 0.5em;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#message p {
|
#message p {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<%inherit file="/base.mako"/>
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">Log in</h2>
|
<h2 class="title">Log in</h2>
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<%include file="/errors.mako"/>
|
<%include file="/errors.mako"/>
|
||||||
<form id="post-new" action="${h.url_for(controller='admin', action='login')}" method="post">
|
<form id="post-new" action="${h.url_for(controller='admin', action='login')}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -15,6 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<input type="submit" name="action" value="Login" class="form-button"/>
|
<input type="submit" name="action" value="Login" class="form-button"/>
|
||||||
|
<span id="register-now">No account? <a href="${h.url_for(controller=u'admin', action=u'register')}" title="register now">Register now!</a></span>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<%inherit file="/base.mako"/>
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">Register</h2>
|
<h2 class="title">Register</h2>
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<%include file="/errors.mako"/>
|
<%include file="/errors.mako"/>
|
||||||
<form id="post-new" action="${h.url_for(controller='admin', action='register')}" method="post">
|
<form id="post-new" action="${h.url_for(controller='admin', action='register')}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<input type="password" name="confirm-password" id="register-confirm-password" class="form-text" />
|
<input type="password" name="confirm-password" id="register-confirm-password" class="form-text" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<input type="submit" name="action" value="Register"/>
|
<input type="submit" name="action" value="Register" class="form-button" />
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<div class="post">
|
<div class="post">
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2>
|
<h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2>
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
${h.literal(post.body)}
|
${h.literal(post.body)}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<%inherit file="/base.mako"/>
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">${c.post.title}</h2>
|
<h2 class="title">${c.post.title}</h2>
|
||||||
<div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div>
|
<div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div>
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
${h.literal(c.post.body)}
|
${h.literal(c.post.body)}
|
||||||
</div>
|
</div>
|
||||||
|
21
scribeengine/templates/email/activate.mako
Normal file
21
scribeengine/templates/email/activate.mako
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
Dear ${c.user.nick},
|
||||||
|
|
||||||
|
You have just registered on ${c.blog_title}, but before you continue, you will
|
||||||
|
need to activate your account. You can do this by simply clicking on the link
|
||||||
|
below, or copying and pasting it into your browser.
|
||||||
|
|
||||||
|
${c.blog_host}${h.url_for(controller=u'admin', action=u'activate', id=c.user.id, code=c.user.activation_key)}
|
||||||
|
|
||||||
|
If this is not you, simply leave this e-mail, and the account will expire after
|
||||||
|
72 hours. If you left this e-mail for too long and want to continue with the
|
||||||
|
registration process, click on the link below, type in your e-mail addres, and
|
||||||
|
another e-mail will be sent to you to activate your account.
|
||||||
|
|
||||||
|
${c.blog_host}${h.url_for(controller=u'admin', action=u'reset', id=c.user.id)}
|
||||||
|
|
||||||
|
Once you have completed the registration process you will be able to comment on
|
||||||
|
the posts on the site.
|
||||||
|
|
||||||
|
Kind regards,
|
||||||
|
|
||||||
|
${c.blog_title} Team
|
@ -1,7 +1,7 @@
|
|||||||
<%inherit file="/base.mako"/>
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">Edit Post: ${c.post.title}</h2>
|
<h2 class="title">Edit Post: ${c.post.title}</h2>
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<%include file="/errors.mako"/>
|
<%include file="/errors.mako"/>
|
||||||
<form id="post-new" action="${h.url_for(controller='post',action='edit', id=c.post.id)}" method="post">
|
<form id="post-new" action="${h.url_for(controller='post',action='edit', id=c.post.id)}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<%inherit file="/base.mako"/>
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">New Post</h2>
|
<h2 class="title">New Post</h2>
|
||||||
<%include file="/flash.mako"/>
|
|
||||||
<%include file="/errors.mako"/>
|
<%include file="/errors.mako"/>
|
||||||
<form id="post-new" action="${h.url_for('/post/edit')}" method="post">
|
<form id="post-new" action="${h.url_for('/post/edit')}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
Reference in New Issue
Block a user