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:57:57 UTC

[25/50] [abbrv] allura git commit: [#7868] ticket:759 Add base class for phone verification service

[#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/33d9106c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/33d9106c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/33d9106c

Branch: refs/heads/ib/7868
Commit: 33d9106c72ddfd6a96accadc122431b406066164
Parents: 1accce5
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Apr 27 12:35:17 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 25 15:53:38 2015 +0000

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


http://git-wip-us.apache.org/repos/asf/allura/blob/33d9106c/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)