Merged in controller rename and URL bug fixes.

This commit is contained in:
Raoul Snyman 2010-02-07 00:08:38 +02:00
commit 804cfea9c7
7 changed files with 74 additions and 23 deletions

View File

@ -34,14 +34,14 @@ from scribeengine.model.meta import Session
log = logging.getLogger(__name__)
class AdminController(BaseController):
class AccountController(BaseController):
def index(self):
h.redirect_to('/admin/login')
h.redirect_to(h.url_for(controller=u'account', action=u'login'))
def register(self):
c.page_title = u'Register'
return render(u'/admin/register.mako')
return render(u'/account/register.mako')
@jsvalidate(u'register-form')
def register_jsschema(self):
@ -95,11 +95,11 @@ class AdminController(BaseController):
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'))
h.redirect_to(h.url_for(controller=u'account', 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'))
h.redirect_to(h.url_for(controller=u'account', action=u'register'))
user = Session.query(User)\
.filter_by(id=id)\
.filter_by(activation_key=activation_code)\
@ -115,11 +115,11 @@ class AdminController(BaseController):
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'))
h.redirect_to(h.url_for(controller=u'account', action=u'login'))
def login(self):
c.page_title = u'Login'
return render(u'/admin/login.mako')
return render(u'/account/login.mako')
@jsvalidate(u'login-form')
def login_jsschema(self):
@ -141,11 +141,11 @@ class AdminController(BaseController):
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(h.url_for(action=u'login'))
h.redirect_to(h.url_for(controller=u'account', 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'))
h.redirect_to(h.url_for(controller=u'account', action=u'login'))
elif user and user.password == password:
log.debug('Logged in successfully.')
redirect_url = str(session.get(u'redirect_url', u'/'))
@ -160,7 +160,7 @@ 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(h.url_for(action=u'login'))
h.redirect_to(h.url_for(controller=u'account', action=u'login'))
def logout(self):
del session[u'REMOTE_USER']

View File

@ -43,19 +43,19 @@ class PostController(BaseController):
@authenticate(u'Add Posts')
def new(self):
c.page_title = 'New Post'
c.page_title = u'New Post'
return render(u'/post/new.mako')
@authenticate(u'Edit My Posts')
def edit(self, id=None):
if id is None:
h.redirect_to('/post/new')
h.redirect_to(h.url_for(controller=u'post', action=u'new'))
c.post = Session.query(Post).get(id)
if len(c.post.tags):
c.post.tags_list = u', '.join([tag.name for tag in c.post.tags])
else:
c.post.tags_list = u''
c.page_title = 'Edit Post: %s' % c.post.title
c.page_title = u'Edit Post: %s' % c.post.title
return render(u'/post/edit.mako')
@authenticate(u'Edit My Posts')
@ -87,9 +87,9 @@ class PostController(BaseController):
Session.add(post)
Session.commit()
if c.form_values[u'action'] == u'Save Draft':
h.redirect_to(h.url_for(action=u'draft'))
h.redirect_to(h.url_for(controller=u'post', action=u'draft'))
else:
h.redirect_to(str('/archive/%s/%s' % (post.created.strftime('%Y/%m/%d'), post.url)))
h.redirect_to(h.url_for_post(post))
def draft(self):
posts = Session.query(Post)\

View File

@ -80,12 +80,12 @@ def teaser(text):
def url_for_post(post):
#TODO: this is hard coded.
return url_for(
controller='blog',
action='view',
controller=u'blog',
action=u'view',
year=post.created.strftime('%Y'),
month=post.created.strftime('%m'),
day=post.created.strftime('%d'),
url=post.url
)
)
flash = Flash()

View File

@ -0,0 +1,22 @@
<%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
<div class="post">
<h2 class="title">Log in</h2>
<%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for(controller=u'account', action=u'login')}" method="post">
<fieldset>
<div class="form-item">
<label for="login-email">E-mail:</label>
<input type="text" name="email" id="login-email" class="form-text" />
</div>
<div class="form-item">
<label for="login-password">Password:</label>
<input type="password" name="password" id="login-password" class="form-text" />
</div>
<div class="form-item">
<input type="submit" name="action" value="Login" class="form-button"/>
<span id="register-now">No account? <a href="${h.url_for(controller=u'account', action=u'register')}" title="register now">Register now!</a></span>
</div>
</fieldset>
</form>
</div>

View File

@ -0,0 +1,29 @@
<%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
<div class="post">
<h2 class="title">Register</h2>
<%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for(controller=u'account', action=u'register')}" method="post">
<fieldset>
<div class="form-item">
<label for="register-nick">Nick:</label>
<input type="text" name="nick" id="register-nick" class="form-text" />
</div>
<div class="form-item">
<label for="register-email">E-mail:</label>
<input type="text" name="email" id="register-email" class="form-text" />
</div>
<div class="form-item">
<label for="register-password">Password:</label>
<input type="password" name="password" id="register-password" class="form-text" />
</div>
<div class="form-item">
<label for="register-confirm-password">Confirm Password:</label>
<input type="password" name="confirm-password" id="register-confirm-password" class="form-text" />
</div>
<div class="form-item">
<input type="submit" name="action" value="Register" class="form-button" />
</div>
</fieldset>
</form>
</div>

View File

@ -32,13 +32,13 @@
% endfor
% if c.current_user:
% if c.current_user.has_permission('Add Posts'):
<li><a href="${h.url_for(controller='post', action='new')}">New Post</a></li>
<li><a href="${h.url_for(controller='post', action='draft')}">Draft Posts</a></li>
<li><a href="${h.url_for(controller=u'post', action=u'new')}">New Post</a></li>
<li><a href="${h.url_for(controller=u'post', action=u'draft')}">Draft Posts</a></li>
% endif
<li><a href="${h.url_for(controller='admin', action='logout')}">Logout</a></li>
<li><a href="${h.url_for(controller=u'account', action=u'logout')}">Logout</a></li>
<li>Logged in as <em>${c.current_user.nick}</em></li>
% else:
<li><a href="${h.url_for(controller='admin', action='login')}">Login</a></li>
<li><a href="${h.url_for(controller=u'account', action=u'login')}">Login</a></li>
% endif
</ul>
</div>

View File

@ -53,7 +53,7 @@
% if c.post.comment_status == u'open':
<h3 id="respond">Leave a Reply</h3>
% if not c.current_user:
<p>You must be <a href="${h.url_for(controller='admin', action='login')}">logged in</a> to post a comment.</p>
<p>You must be <a href="${h.url_for(controller=u'account', action=u'login')}">logged in</a> to post a comment.</p>
% else:
<form action="${h.url_for(controller='blog',action='comment', id= c.post.id)}" method="post" id="commentform">
<p class="user-details">Logged in as <em>${c.current_user.nick}</em>. <a href="${h.url_for(controller='admin',action='logout')}" title="Log out of this account">Logout &raquo;</a></p>