allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [01/14] allura git commit: [#7868] ticket:759 Add base class for phone verification service
Date Tue, 12 May 2015 12:05:22 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/7868 [created] d4d18abe6


[#7868] ticket:759 Add base class for phone verification service


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

Branch: refs/heads/ib/7868
Commit: 1bcf411154017213cc9ca927e218f5fedb2166c1
Parents: 31189d4
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Apr 27 12:35:17 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon May 4 12:39:14 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/phone/__init__.py | 76 ++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1bcf4111/Allura/allura/lib/phone/__init__.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/phone/__init__.py b/Allura/allura/lib/phone/__init__.py
new file mode 100644
index 0000000..d0db85c
--- /dev/null
+++ b/Allura/allura/lib/phone/__init__.py
@@ -0,0 +1,76 @@
+#       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.
+
+import logging
+
+log = logging.getLogger(__name__)
+
+
+class PhoneService(object):
+    """
+    Defines the phone verification service interface and provides a default
+    no-op implementation.
+    """
+
+    def __init__(self, config):
+        pass
+
+    def verify(self, number):
+        """
+        Generate PIN and send it to phone number :param number:
+
+        Returns dict with following keys: status, request_id, error. status is
+        either 'ok' or 'error'.
+
+        If status is 'ok' then request_id is present (used later to verify PIN)
+        otherwise 'error' is an error message.
+        """
+        log.info('Phone service is not configured')
+        return {
+            'status': 'error',
+            'error': 'Phone service is not configured',
+        }
+
+    def check(self, request_id, pin):
+        """
+        Given the :param pin: code user entered and :param request_id:
+        (obtained by verify), verify that :param pin: is valid.
+
+        Returns dict with following keys: status, result, error. status is
+        either 'ok' or 'error'.
+
+        If status is 'ok' then result is present otherwise 'error' is an error
+        message.
+
+        result is True is phone verification succeeded, False otherwise.
+        """
+        log.info('Phone service is not configured')
+        return {
+            'status': 'error',
+            'error': 'Phone service is not configured',
+        }
+
+    @classmethod
+    def get(cls, config, entry_points):
+        """
+        Return an instance of PhoneService implementation based on ``config``.
+        """
+        method = config.get('phone.method')
+        if not method:
+            return cls(config)
+        service = entry_points[method]
+        return service(config)


Mime
View raw message