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

[32/50] [abbrv] allura git commit: [#7868] ticket:760 Implement phone verification (only backend)

[#7868] ticket:760 Implement phone verification (only backend)


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

Branch: refs/heads/ib/7868
Commit: 14fb6733c2aba9d7768faf55437238a84fe6f6db
Parents: 06521d2
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 8 15:24:07 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 25 15:53:40 2015 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py | 21 +++++++++++++++++++++
 Allura/allura/lib/plugin.py          | 21 +++++++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/14fb6733/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index d01fb38..2816f83 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -19,6 +19,7 @@ import re
 import logging
 from datetime import datetime, timedelta
 from urllib import unquote
+from hashlib import sha1
 
 from bson import ObjectId
 from tg import expose, flash, redirect, validate, request, config
@@ -198,6 +199,26 @@ class NeighborhoodController(object):
         return {}
 
     @expose('json:')
+    def verify_phone(self, number):
+        p = plugin.ProjectRegistrationProvider.get()
+        result = p.verify_phone(c.user, number)
+        request_id = result.pop('request_id', None)
+        if request_id:
+            session['phone_verification.request_id'] = request_id
+            number_hash = sha1(h.really_unicode(number)).hexdigest()
+            session['phone_verification.number_hash'] = number_hash
+            session.save()
+        return result
+
+    @expose('json:')
+    def check_phone_verification(self, pin):
+        p = plugin.ProjectRegistrationProvider.get()
+        request_id = session.get('phone_verification.request_id')
+        number_hash = session.get('phone_verification.number_hash')
+        res = p.check_phone_verification(c.user, request_id, pin, number_hash)
+        return res
+
+    @expose('json:')
     def suggest_name(self, project_name=''):
         provider = plugin.ProjectRegistrationProvider.get()
         return dict(suggested_name=provider.suggest_name(project_name,

http://git-wip-us.apache.org/repos/asf/allura/blob/14fb6733/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 54eba13..7b7961e 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -723,8 +723,25 @@ class ProjectRegistrationProvider(object):
             return True
         if security.has_access(neighborhood, 'admin', user=user)():
             return True
-        # TODO: check user record
-        return False
+        return bool(user.get_tool_data('phone_verification', 'number_hash'))
+
+    def verify_phone(self, user, number):
+        ok = {'status': 'ok'}
+        if asbool(config.get('project.verify_phone')):
+            return ok
+        return g.phone_service.verify(number)
+
+    def check_phone_verification(self, user, request_id, pin, number_hash):
+        ok = {'status': 'ok'}
+        if asbool(config.get('project.verify_phone')):
+            return ok
+        res = g.phone_service.check(request_id, pin)
+        if res.get('status') == 'ok':
+            user.set_tool_data('phone_verification', number_hash=number_hash)
+            h.auditlog_user('Phone verification succeeded', user=user)
+        else:
+            h.auditlog_user('Phone verification failed', user=user)
+        return res
 
     def register_neighborhood_project(self, neighborhood, users, allow_register=False):
         from allura import model as M