1. Bruno Rocha
  2. pyforum

Commits

Julio Flores-Schwarzbeck  committed 28e51a5

v1.1 update project - 90% completion, finally the end is near :)

  • Participants
  • Parent commits e36f9fe
  • Branches default

Comments (0)

Files changed (9)

File controllers/default.py

View file
                         #    zft.modifying_date desc
                         #limit 1
                         #offset 0
-                        where_statement = (db.zf_topic.forum_id==forum_id) & \
-                        (db.zf_topic.disabled_flag==0)
+                        where_statement = (
+                            db.zf_topic.forum_id == forum_id) & (
+                            db.zf_topic.disabled_flag == 0)
                         last_update_info = db(
                             where_statement).select(
                             db.zf_topic.modifying_user_id,
     req = request.vars
     view_info = {}
     view_info['errors'] = []
+    captcha = forumhelper.gen_pwd()
+    view_info['anon_captcha'] = captcha
+    view_info['anon_captcha_base64'] = base64.standard_b64encode(captcha)
     allow_registration = forumhelper.get_system_property(
         'zfsp_allow_registration', '') != ''
     view_info.update({'allow_registration': allow_registration})
         if req.register_b:
 
             # Verify required fields
-            if len(req.auth_alias) > 0 and len(req.auth_email) > 0 and len(
-                req.auth_passwd) > 0:
+            if len(req.auth_email) > 0 and len(req.auth_passwd) > 0:
                 auth_email = req.auth_email.strip()
                 auth_passwd = req.auth_passwd
                 auth_passwd_c = req.auth_passwd_c
                 # See if this name has been taken
                 if db(db.auth_users.auth_email.lower() == \
                       auth_email.lower()).select(db.auth_users.id):
-                    view_info['errors'].append('The selected email is'
+                    view_info['errors'].append('The selected email is '
                                                'unavailable, please choose '
                                                'another one')
+                if base64.standard_b64encode(req.captcha_response) != req.c:
+                    view_info['errors'].append('Invalid humanity challenge '
+                                               'response, please try again')
 
                 if not view_info['errors']:
                     # Authenticate user
     if rss_type == 'system':
         title = str(XML(T('pyForum Latest System Topics')))
         descr = str(XML(T('pyForum Latest System Topics')))
-        rss_topics = forumhelper.get_system_announcements(include_content=True)
+        rss_topics = forumhelper.get_system_announcements(include_content=True,
+                                                          rss=True)
     else:
         title = str(XML(T('pyForum Latest Topics')))
         descr = str(XML(T('pyForum Latest Topics')))
-        rss_topics = forumhelper.get_latest_topics(include_content=True)
+        rss_topics = forumhelper.get_latest_topics(include_content=True,
+                                                   rss=True)
 
-    rss_feed = rss2.RSS2(title = title,
-                    link = URL(r=request, c='default', f='index'),
-                    description = descr,
-                    lastBuildDate = request.now,
-                    items = [
-                        rss2.RSSItem(
-                            title = topic.title,
-                            link = URL(r=request, c='default', f='view_topic',
-                                       args=[topic.id]),
-                            description = parse_content(topic.content,
-                                                        'forumfull'),
-                            pubDate = topic.modifying_date) \
-                        for topic in rss_topics]
-                    )
-    response.headers['Content-Type'] = 'application/rss+xml'
-    return rss2.dumps(rss_feed)
+    if rss_topics:
+        rss_feed = rss2.RSS2(title = title,
+                        link = URL(r=request, c='default', f='index'),
+                        description = descr,
+                        lastBuildDate = request.now,
+                        items = [
+                            rss2.RSSItem(
+                                title = topic.title,
+                                link = URL(r=request, c='default', f='view_topic',
+                                           args=[topic.id]),
+                                description = parse_content(topic.content,
+                                                            'forumfull'),
+                                pubDate = topic.modifying_date) \
+                            for topic in rss_topics]
+                        )
+        response.headers['Content-Type'] = 'application/rss+xml'
+        return rss2.dumps(rss_feed)
+    else:
+        redirect(URL(r=request, c='default', f='index', vars=dict(rss_msg='No '
+                                                                  'RSS Feed '
+                                                                  'Found')))
 
 def contact_admin():
     """ Contact Admin - This can allow anonymous users to post spam, so

File modules/forumhelper.py

View file
             rank = rank_info[0].rank_name
         return rank
 
-    def get_system_announcements(self, include_content=False):
+    def get_system_announcements(self, include_content=False, rss=False):
         max_sys_announcements = int(
             self.get_system_property('zfsp_system_announcement_max', 0))
+        sys_topics = None
         if max_sys_announcements:
             if include_content:
                 sys_topics = self.db(
                     self.db.zf_topic.modifying_date,
                     orderby=~self.db.zf_topic.modifying_date,
                     limitby=(0, max_sys_announcements))
-            if not len(sys_topics):
+            if not len(sys_topics) and not rss:
                 sys_topics = [{'error':'No Topics'}]
         else:
-            sys_topics = [{'error':'No Topics'}]
+            if not rss:
+                sys_topics = [{'error':'No Topics'}]
         return sys_topics
 
-    def get_latest_topics(self, include_content=False):
+    def get_latest_topics(self, include_content=False, rss=False):
         max_topics = int(
             self.get_system_property('zfsp_latest_postings_max', 0))
+        latest_topics = None
         if max_topics:
             if include_content:
                 latest_topics = self.db(\
                         self.db.zf_topic.modifying_date,
                         orderby=~self.db.zf_topic.modifying_date,
                         limitby=(0, max_topics))
-            if not len(latest_topics):
+            if not len(latest_topics) and not rss:
                 latest_topics = [{'error':'No Topics'}]
         else:
-            latest_topics = [{'error':'No Topics'}]
+            if not rss:
+                latest_topics = [{'error':'No Topics'}]
         return latest_topics
 
     def setup_notifications(self, subscription_id, subscription_type, now):

File views/default/contact_admin.html

View file
         <tbody>
             <tr>
                 <td>{{=XML(T('From'))}}:</td>
-                <td>{{=auth_user.get_user_name()}}
+                <td>{{=forumhelper.get_display_name()}}
                     {{if not auth_user.is_auth():}}<span class="warning">({{=XML(T('Please make sure you leave your contact information in case you need a response'))}}.)</span>{{pass}}
                 </td>
             <tr>

File views/default/index.html

View file
                                             {{if auth_user.is_auth():}}
                                                 <a href="{{=URL(r=request, c='pm', f='message_new', args=[forum['last_updated_by']])}}"
                                                    class="{{if forum['update_flag']:}}smallb-new{{else:}}smallb{{pass}}"
-                                                   title="{{=forum['last_updated_by']}}">{{=forum['last_updated_by']}}</a>
+                                                   title="">{{=forumhelper.get_display_name(forum['last_updated_by'])}}</a>
                                             {{else:}}
                                                 <b class="small">{{=forum['last_updated_by']}}</b>
                                             {{pass}}

File views/default/login.html

View file
         <table cellspacing="2" cellpadding="1">
         <tbody>
             <tr>
-                <td>{{=XML(T('Username'))}}:</td>
+                <td>{{=XML(T('Email'))}}:</td>
                 <td>
                     <input class="formelem" type="text" id="auth_alias" name="auth_alias" value="{{=request.vars.get('auth_alias', request.post_vars.get('auth_alias', ''))}}" style="width:200px;" />
                 </td>

File views/default/signup.html

View file
     <form id="login" method="post" action="">
         <fieldset id="login_form_fields">
             <input type="hidden" id="form_submitted" name="form_submitted" value="1" />
+            <input type="hidden" id="c" name="c" value="{{=view_info['anon_captcha_base64']}}" />
             <table cellspacing="2" cellpadding="1">
             <tbody>
                 <tr>
-                    <td><span class="required">*</span> {{=XML(T('Username'))}}:</td>
-                    <td><input type="text" id="auth_alias" name="auth_alias" value="{{=request.vars.get('auth_alias', '')}}" style="width:200px;" /></td>
-                <tr>
                     <td><span class="required">*</span> {{=XML(T('Email'))}}:</td>
                     <td><input class="formelem" type="text" id="auth_email" name="auth_email" value="{{=request.vars.get('auth_email', '')}}" style="width:200px;" /></td>
                 </tr>
                 <tr>
                     <td><span class="required">*</span> {{=XML(T('Confirm Password'))}}:</td>
                     <td><input class="formelem" type="password" id="auth_passwd_c" name="auth_passwd_c" value="" style="width:200px;" /></td>
-                </tr>  
+                </tr>
+                <tr>
+                    <td><span class="required">*</span>
+                        {{=XML(T('Verify your humanity'))}}:
+                    </td>
+                    <td>
+                        <input type="text" id="captcha_response" name="captcha_response" value="" style="width:100px;" />
+                        <b>{{=view_info['anon_captcha']}}</b>
+                        <span class="warning">({{=XML(T('Please Enter the acces code shown in order to subscribe'))}}.)</span>
+                    </td>
+                </tr>
             </tbody>
             </table>
 

File views/default/view_forum.html

View file
                                         {{if auth_user.is_auth():}}
                                             <a href="{{=URL(r=request, c='pm', f='message_new', args=[this_topic.modifying_user_id])}}"
                                                title=""
-                                               class="{{if (request.now - this_topic.modifying_date).days == 0:}}"smallb-new"{{else:}}"smallb"{{pass}}">{{=forumhelper.get_member_property('zfmp_display_name', this_topic.modifying_user_id, 'user_%s' % (this_topic.modifying_user_id))}}</a>
+                                               class="{{if (request.now - this_topic.modifying_date).days == 0:}}smallb-new{{else:}}smallb{{pass}}">{{=forumhelper.get_member_property('zfmp_display_name', this_topic.modifying_user_id, 'user_%s' % (this_topic.modifying_user_id))}}</a>
                                         {{else:}}
                                             <b class="small">{{=forumhelper.get_member_property('zfmp_display_name', this_topic.modifying_user_id, 'user_%s' % (this_topic.modifying_user_id))}}</b>
                                         {{pass}}

File views/default/view_topic.html

View file
                     <td class="cell3d" style="width:15%;">
                         <div class="topic-information">
                             {{=XML(T('By'))}}:
-                            {{if topic.creation_user == 'Anonymous User':}}
+                            {{if not topic.creation_user_id:}}
                                 <b class="small">Anonymous User</b>
                             {{else:}}
                                 {{if auth_user.is_auth():}}
-                                    <a href="{{=URL(r=request, c='pm', f='message_new', args=[topic.creation_user])}}"
+                                    <a href="{{=URL(r=request, c='pm', f='message_new', args=[topic.creation_user_id])}}"
                                        title=""
-                                       class="smallb">{{=topic.creation_user}}</a>
+                                       class="smallb">{{=forumhelper.get_display_name(topic.creation_user_id)}}</a>
                                 {{else:}}
-                                    <b>{{=topic.creation_user}}</b>
+                                    <b>{{=forumhelper.get_display_name(topic.creation_user_id)}}</b>
                                 {{pass}}
                                 {{if forumhelper.get_system_property('zfsp_use_ranking_system', '') != '':}}
-                                    <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(topic.creation_user)}}
+                                    <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(topic.creation_user_id)}}
                                 {{pass}}
-                                <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', topic.creation_user, '0')}}
-                                <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', topic.creation_user, XML(T('<i>Unknown</i>')))}}
-                                {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(topic.creation_user):}}
-                                    <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[topic.creation_user])}}" alt="" />
+                                <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', topic.creation_user_id, '0')}}
+                                <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', topic.creation_user_id, XML(T('<i>Unknown</i>')))}}
+                                {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(topic.creation_user_id):}}
+                                    <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[topic.creation_user_id])}}" alt="" />
                                 {{pass}}
                             {{pass}}
                         </div>
                             {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}
                                 <a href="#add_comment"
                                    title=""
-                                   onclick="reply_quote('{{=topic.creation_user}}', 'topic_id_{{=topic.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
+                                   onclick="reply_quote('{{=forumhelper.get_display_name(topic.creation_user_id)}}', 'topic_id_{{=topic.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
                             {{pass}}
                             <a href="{{=URL(r=request, c='default', f='report_inappropriate', args=[topic.id, topic.id])}}"
                                onclick="return confirm(document.getElementById('confirm_inapp').value);"
                             <td class="cell3d" style="width:15%;">
                                 <div class="topic-information">
                                     {{=XML(T('By'))}}:
-                                    {{if this_child.creation_user == 'Anonymous User':}}
+                                    {{if not this_child.creation_user_id:}}
                                         <b class="small">Anonymous User</b>
                                     {{else:}}
                                         {{if auth_user.is_auth():}}
-                                            <a href="{{=URL(r=request, c='pm', f='message_new', args=[this_child.creation_user])}}"
-                                               title="">{{=this_child.creation_user}}</a>
+                                            <a href="{{=URL(r=request, c='pm', f='message_new', args=[this_child.creation_user_id])}}"
+                                               title="">{{=forumhelper.get_display_name(this_child.creation_user_id)}}</a>
                                         {{else:}}
-                                            <b>{{=this_child.creation_user}}</b>
+                                            <b>{{=forumhelper.get_display_name(this_child.creation_user_id)}}</b>
                                         {{pass}}
                                         {{if forumhelper.get_system_property('zfsp_use_ranking_system', '') != '':}}
-                                            <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(this_child.creation_user)}}
+                                            <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(this_child.creation_user_id)}}
                                         {{pass}}
-                                        <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', this_child.creation_user, '0')}}
-                                        <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', this_child.creation_user, XML(T('<i>Unknown</i>')))}}
-                                        {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(this_child.creation_user):}}
-                                            <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[this_child.creation_user])}}" alt="" />
+                                        <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', this_child.creation_user_id, '0')}}
+                                        <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', this_child.creation_user_id, XML(T('<i>Unknown</i>')))}}
+                                        {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(this_child.creation_user_id):}}
+                                            <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[this_child.creation_user_id])}}" alt="" />
                                         {{pass}}
                                     {{pass}}
                                 </div>
                                     {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}
                                         <a href="#add_comment"
                                            title=""
-                                           onclick="reply_quote('{{=this_child.creation_user}}', 'topic_id_{{=this_child.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
+                                           onclick="reply_quote('{{=forumhelper.get_display_name(this_child.creation_user_id)}}', 'topic_id_{{=this_child.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
                                     {{pass}}
                                     <a href="{{=URL(r=request, c='default', f='report_inappropriate', args=[this_child.id, topic.id])}}"
                                        onclick="return confirm(document.getElementById('confirm_inapp').value);"

File views/pyforum_sidenav.html

View file
                 <table cellspacing="0" cellpadding="0" class="block-centered">
                     <tbody>
                         <tr>
-                            <td>{{=XML(T('Quick Search'))}}:</td>
+                            <td>{{=XML(T('Search'))}}:</td>
                             <td><input type="text" id="search_str" name="search_str" value="" class="formelem" style="width:100px;" /></td>
                         </tr>
                         <tr>