You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/05/28 22:13:11 UTC

[09/26] allura git commit: [#7868] ticket:760 Code structure for phone verification for project registration

[#7868] ticket:760 Code structure for phone verification for project registration


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/bde6588e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/bde6588e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/bde6588e

Branch: refs/heads/master
Commit: bde6588eb12afd11bd0f02d093ffc0a9d0f84544
Parents: aeabf8c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 8 14:27:32 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu May 28 20:11:45 2015 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            | 10 ++++
 Allura/allura/lib/exceptions.py                 |  4 ++
 Allura/allura/lib/plugin.py                     | 21 +++++++
 Allura/allura/nf/allura/css/allura.css          |  6 +-
 .../templates/neighborhood_add_project.html     | 18 +++++-
 .../templates/phone_verification_fragment.html  | 60 ++++++++++++++++++++
 Allura/development.ini                          |  3 +
 7 files changed, 119 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 201ee54..d01fb38 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -184,12 +184,19 @@ class NeighborhoodController(object):
     @without_trailing_slash
     def add_project(self, **form_data):
         require_access(self.neighborhood, 'register')
+        provider = plugin.ProjectRegistrationProvider.get()
+        phone_verified = provider.phone_verified(c.user, self.neighborhood)
+        c.show_phone_verification_overlay = not phone_verified
         c.add_project = W.add_project
         form_data.setdefault(
             'tools', [u'Wiki', u'Git', u'Tickets', u'Discussion'])
         form_data['neighborhood'] = self.neighborhood.name
         return dict(neighborhood=self.neighborhood, form_data=form_data)
 
+    @expose('jinja:allura:templates/phone_verification_fragment.html')
+    def phone_verification_fragment(self, *args, **kw):
+        return {}
+
     @expose('json:')
     def suggest_name(self, project_name=''):
         provider = plugin.ProjectRegistrationProvider.get()
@@ -230,6 +237,9 @@ class NeighborhoodController(object):
             flash(
                 "Project creation rate limit exceeded.  Please try again later.", 'error')
             redirect('add_project')
+        except exceptions.ProjectPhoneVerificationError:
+            flash('You must pass phone verification', 'error')
+            redirect('add_project')
         except Exception as e:
             log.error('error registering project: %s',
                       project_unixname, exc_info=True)

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/lib/exceptions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/exceptions.py b/Allura/allura/lib/exceptions.py
index 8a33658..f796d99 100644
--- a/Allura/allura/lib/exceptions.py
+++ b/Allura/allura/lib/exceptions.py
@@ -43,6 +43,10 @@ class ProjectRatelimitError(ForgeError):
     pass
 
 
+class ProjectPhoneVerificationError(ForgeError):
+    pass
+
+
 class ToolError(ForgeError):
     pass
 

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index fb1c3b9..54eba13 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -708,6 +708,24 @@ class ProjectRegistrationProvider(object):
             if user_age < int(rate) and project_count >= count:
                 raise forge_exc.ProjectRatelimitError()
 
+    def phone_verified(self, user, neighborhood):
+        """
+        Check if user has completed phone verification.
+
+        Returns True if one of the following is true:
+            - phone verification is disabled
+            - :param user: has 'admin' access to :param neighborhood:
+            - phone is already verified for a :param user:
+
+        Otherwise returns False.
+        """
+        if asbool(config.get('project.verify_phone')):
+            return True
+        if security.has_access(neighborhood, 'admin', user=user)():
+            return True
+        # TODO: check user record
+        return False
+
     def register_neighborhood_project(self, neighborhood, users, allow_register=False):
         from allura import model as M
         shortname = '--init--'
@@ -773,6 +791,9 @@ class ProjectRegistrationProvider(object):
 
         self.rate_limit(user, neighborhood)
 
+        if not self.phone_verified(user, neighborhood):
+            raise forge_exc.ProjectPhoneVerificationError()
+
         if user_project and shortname.startswith('u/'):
             check_shortname = shortname.replace('u/', '', 1)
         else:

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/nf/allura/css/allura.css
----------------------------------------------------------------------
diff --git a/Allura/allura/nf/allura/css/allura.css b/Allura/allura/nf/allura/css/allura.css
index 4087e1e..7d7042a 100644
--- a/Allura/allura/nf/allura/css/allura.css
+++ b/Allura/allura/nf/allura/css/allura.css
@@ -71,13 +71,15 @@ tr.rev div.markdown_content p {
     margin-bottom: 0;
 }
 
-#login_overlay .title {
+#login_overlay .title,
+#phone_verification_overlay .title {
     margin-bottom: 0;
     padding-left: 10px;
     border-top-left-radius: 4px;
     border-top-right-radius: 4px;
 }
 
-#login_overlay iframe {
+#login_overlay iframe,
+#phone_verification_overlay iframe {
     width: 400px;
 }

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/templates/neighborhood_add_project.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/neighborhood_add_project.html b/Allura/allura/templates/neighborhood_add_project.html
index cd1f79c..6aebc2c 100644
--- a/Allura/allura/templates/neighborhood_add_project.html
+++ b/Allura/allura/templates/neighborhood_add_project.html
@@ -24,5 +24,21 @@
 {% block header %}Create a Project{% endblock %}
 
 {% block content %}
-          {{c.add_project.display(action=neighborhood.url()+'register',value=form_data,neighborhood=neighborhood)}}
+  {% if c.show_phone_verification_overlay %}
+    {% do g.register_js('js/jquery.lightbox_me.js') %}
+    <div id="phone_verification_overlay" class="ui-widget-content">
+      <h2 class="dark title">Phone Verification Required</h2>
+      <iframe src="{{neighborhood.url_prefix}}phone_verification_fragment"></iframe>
+    </div>
+    <script type="text/javascript">
+      $(function () {
+        $('#phone_verification_overlay').draggable().lightbox_me({
+          closeClick: false,
+          closeEsc: false,
+          centered: true
+        });
+      });
+    </script>
+  {% endif %}
+  {{c.add_project.display(action=neighborhood.url()+'register',value=form_data,neighborhood=neighborhood)}}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/allura/templates/phone_verification_fragment.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/phone_verification_fragment.html b/Allura/allura/templates/phone_verification_fragment.html
new file mode 100644
index 0000000..9985812
--- /dev/null
+++ b/Allura/allura/templates/phone_verification_fragment.html
@@ -0,0 +1,60 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+<!DOCTYPE html>
+<!-- Server: {{g.server_name}} -->
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+{% if g.theme.jinja_macros %}
+  {% import g.theme.jinja_macros as theme_macros with context %}
+{% endif %}
+{% do g.register_forge_js('js/jquery-base.js') %}
+{% do g.register_forge_js('js/allura-base.js') %}
+{% do g.theme.require() %}
+{% do g.resource_manager.register_widgets(c) %}
+{# paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ #}
+<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
+<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
+<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
+<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
+<!--[if (gt IE 9)|!(IE)]>--> <html lang="en" class="no-js"> <!--<![endif]-->
+    <head>
+        {{theme_macros.extra_header(g.theme_href(''))}}
+        {% for blob in g.resource_manager.emit('head_css') %}
+          {{ blob }}
+        {% endfor %}
+        {% for blob in g.resource_manager.emit('head_js') %}
+          {{ blob }}
+        {% endfor %}
+        <style type="text/css">
+            html {
+                overflow: hidden;
+            }
+            body {
+                padding-top: 1em;
+                width: 1000px;
+            }
+        </style>
+    </head>
+    <body>
+        TODO: Phone verification UI
+
+        {% for blob in g.resource_manager.emit('body_js_tail') %}
+          {{ blob }}
+        {% endfor %}
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/allura/blob/bde6588e/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 08a4828..baf479d 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -198,6 +198,9 @@ site_admin_project_nbhd = Projects
 ; phone.api_key =
 ; phone.api_secret =
 
+; Use phone verification on project registration (false by default)
+; project.verify_phone = true
+
 ; Webhook timeout in seconds
 webhook.timeout = 30
 ; List of pauses between retries, if hook fails (in seconds)