You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/10/20 18:57:14 UTC

[kibble] 11/12: add script + specs for verifying user accounts

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git

commit e5aa00b8c9e84df41c059ff24e249e1c2c729f45
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Oct 20 20:56:40 2017 +0200

    add script + specs for verifying user accounts
    
    Needs some tweaking on the content type later on
---
 api/pages/verify.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/api/pages/verify.py b/api/pages/verify.py
new file mode 100644
index 0000000..0b4d707
--- /dev/null
+++ b/api/pages/verify.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# 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.
+########################################################################
+# OPENAPI-URI: /api/verify/{email}/{vcode}
+########################################################################
+# get:
+#      summary: Verify an account
+#      parameters:
+#        - name: email
+#          in: path
+#          description: Email address of account
+#          required: true
+#          schema:
+#            type: string
+#        - name: vcode
+#          in: path
+#          description: Verification code
+#          required: true
+#          schema:
+#            type: string
+#      responses:
+#        '200':
+#          description: 200 Response
+#          content:
+#            application/json:
+#              schema:
+#                $ref: '#/components/schemas/ActionCompleted'
+#        default:
+#          description: unexpected error
+#          content:
+#            application/json:
+#              schema:
+#                $ref: '#/components/schemas/Error'
+# 
+########################################################################
+
+
+
+
+
+"""
+This is the user account verifier for Kibble.
+"""
+
+
+def run(API, environ, indata, session):
+    
+    # Get vocde, make sure it's 40 chars
+    vcode = indata.get('vcode')
+    if len(vcode) != 40:
+        raise API.exception(400, "Invalid verification code!")
+    
+    # Find the account with this vcode
+    email = indata.get('email')
+    if len(email) < 7:
+        raise API.exception(400, "Invalid email address presented.")
+    
+    if session.DB.ES.exists(index=session.DB.dbname, doc_type='useraccount', id = email):
+        doc = session.DB.ES.get(index=session.DB.dbname, doc_type='useraccount', id = email)
+        # Do the codes match??
+        if doc['_source']['vcode'] == vcode:
+            doc['_source']['verified'] = True
+            # Save account as verified
+            session.DB.ES.index(index=session.DB.dbname, doc_type='useraccount', id = email, body = doc['_source'])
+            yield("Your account has been verified, you can now log in!")
+        else:
+            raise API.exception(404, "Invalid verification code presented!")
+    else:
+        raise API.exception(404, "Invalid verification code presented!") # Don't give away if such a user exists, pssst
+    
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.