diff --git a/.bzrignore b/.bzrignore index dc00706..bc560e7 100644 --- a/.bzrignore +++ b/.bzrignore @@ -5,3 +5,5 @@ scribeengine.sqlite posts.sql *.egg-info ScrivbeEngine.e4p +build +dist diff --git a/development.ini b/development.ini index db85be5..0e738fe 100644 --- a/development.ini +++ b/development.ini @@ -43,6 +43,7 @@ security.salt = secretsalt mail.on = false mail.manager = immediate +mail.transport = smtp mail.smtp.server = mail.mydomain.com mail.smtp.username = mymailusername mail.smtp.password = mymailpassword diff --git a/run-server b/run-server deleted file mode 100755 index 3cc02c7..0000000 --- a/run-server +++ /dev/null @@ -1 +0,0 @@ -/home/raoul/VirtualEnv/ScribeEngine/feeds/bin/paster serve development.ini --reload diff --git a/scribeengine/controllers/admin.py b/scribeengine/controllers/admin.py index 8d1148f..975e545 100644 --- a/scribeengine/controllers/admin.py +++ b/scribeengine/controllers/admin.py @@ -23,6 +23,7 @@ import logging import string import random +from datetime import datetime from scribeengine.lib.base import * from scribeengine.lib.validation.client import JSString, JSEmail @@ -47,7 +48,7 @@ class AdminController(BaseController): return { 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'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): @@ -67,8 +68,55 @@ class AdminController(BaseController): ) Session.add(user) 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('/') + 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): c.page_title = u'Login' 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']) user = Session.query(User).filter_by(email=c.form_values[u'email']).first() password = utils.hash_password(c.form_values[u'password']) - log.debug(user) if not user or user.password != password: log.debug('Username or password are incorrect.') 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: log.debug('Logged in successfully.') redirect_url = str(session.get(u'redirect_url', u'/')) @@ -109,10 +160,11 @@ class AdminController(BaseController): del session[u'REMOTE_USER'] session.save() 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): del session[u'REMOTE_USER'] session.save() + h.flash.set_message(u'You have logged out successfully.', u'success') h.redirect_to('/') diff --git a/scribeengine/lib/utils.py b/scribeengine/lib/utils.py index a2c0d9e..434b252 100644 --- a/scribeengine/lib/utils.py +++ b/scribeengine/lib/utils.py @@ -27,10 +27,10 @@ import string from random import choice from datetime import datetime -from pylons import config +from pylons import config, c 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=[]): """ diff --git a/scribeengine/model/tables.py b/scribeengine/model/tables.py index af15ec9..9ef1c4b 100644 --- a/scribeengine/model/tables.py +++ b/scribeengine/model/tables.py @@ -100,10 +100,10 @@ users_table = Table(u'users', metadata, Column(u'email', Unicode(200), nullable=False, index=True), Column(u'password', Unicode(64), nullable=False), Column(u'nick', Unicode(50), nullable=False, index=True), - Column(u'first_name', Unicode(100)), - Column(u'last_name', Unicode(100)), - Column(u'homepage', Unicode(200)), - Column(u'activation_key', Unicode(40)) + Column(u'first_name', Unicode(100), default=u''), + Column(u'last_name', Unicode(100), default=u''), + Column(u'homepage', Unicode(200), default=u''), + Column(u'activation_key', Unicode(40), default=None) ) # Definition of the "variables" table diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index 827903a..d6fbe3d 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -404,6 +404,10 @@ fieldset { margin-bottom: 1em; } +#register-now { + margin-left: 1em; +} + /* Message areas */ #form-errors { @@ -414,8 +418,7 @@ fieldset { } #message { - margin-top: 1.8em; - /*padding: 0.3em 0.5em;*/ + margin-bottom: 1.8em; } #message p { diff --git a/scribeengine/templates/admin/login.mako b/scribeengine/templates/admin/login.mako index ba5841d..6ef1e70 100644 --- a/scribeengine/templates/admin/login.mako +++ b/scribeengine/templates/admin/login.mako @@ -1,7 +1,7 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/>

Log in

- <%include file="/flash.mako"/> <%include file="/errors.mako"/>
@@ -15,6 +15,7 @@
+ No account? Register now!
diff --git a/scribeengine/templates/admin/register.mako b/scribeengine/templates/admin/register.mako index d3edd7d..b54f0bc 100644 --- a/scribeengine/templates/admin/register.mako +++ b/scribeengine/templates/admin/register.mako @@ -1,7 +1,7 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/>

Register

- <%include file="/flash.mako"/> <%include file="/errors.mako"/>
@@ -22,7 +22,7 @@
- +
diff --git a/scribeengine/templates/blog/teaser.mako b/scribeengine/templates/blog/teaser.mako index 13e84c6..3b347e4 100644 --- a/scribeengine/templates/blog/teaser.mako +++ b/scribeengine/templates/blog/teaser.mako @@ -1,5 +1,4 @@
- <%include file="/flash.mako"/>

${post.title}

${h.literal(post.body)} diff --git a/scribeengine/templates/blog/view.mako b/scribeengine/templates/blog/view.mako index b88ef62..ae83e33 100644 --- a/scribeengine/templates/blog/view.mako +++ b/scribeengine/templates/blog/view.mako @@ -1,8 +1,8 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/>

${c.post.title}

Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}
- <%include file="/flash.mako"/>
${h.literal(c.post.body)}
diff --git a/scribeengine/templates/email/activate.mako b/scribeengine/templates/email/activate.mako new file mode 100644 index 0000000..30e7d57 --- /dev/null +++ b/scribeengine/templates/email/activate.mako @@ -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 diff --git a/scribeengine/templates/post/edit.mako b/scribeengine/templates/post/edit.mako index 1477181..44006f1 100644 --- a/scribeengine/templates/post/edit.mako +++ b/scribeengine/templates/post/edit.mako @@ -1,7 +1,7 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/>

Edit Post: ${c.post.title}

- <%include file="/flash.mako"/> <%include file="/errors.mako"/>
diff --git a/scribeengine/templates/post/new.mako b/scribeengine/templates/post/new.mako index 521a125..cca1e4e 100644 --- a/scribeengine/templates/post/new.mako +++ b/scribeengine/templates/post/new.mako @@ -1,7 +1,7 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/>

New Post

- <%include file="/flash.mako"/> <%include file="/errors.mako"/>