コード例 #1
0
ファイル: userdao.py プロジェクト: raghothams/appsync
    def get(self, id):
        
        
        cur = self.db.cursor()
        user = None

        psycopg2.extras.register_uuid()
        try:

            cur.execute("SELECT * FROM public.users \
                          WHERE id = %s", (id,))

            row = cur.fetchone()
            # build the user object
            # get the user id & convert it to python UUID type

            user = User()
            user.id = row[0]
            user.name = row[1]
            user.email = row[2]
            user.password = row[3]

        except Exception as e:

            print "An error occurred while reading user id"
            print e
            raise e
        
        finally:
            # return user object
            cur.close()
            return user
コード例 #2
0
ファイル: routes.py プロジェクト: raghothams/appsync
def signup():

    email = request.form["email"]
    uname = request.form["name"]
    password = request.form["password"]
    repeat = request.form["repeat"]

    result = None
    json_response = {}

    try:
        if email and uname and password and repeat:

            email = email.lower()
            uname = uname.strip()

            user = User()
            user.name = uname
            user.email = email
            user.password = password

            user_mapper = UserDAO()
            user_id = user_mapper.add(user)
            print user_id, "new user"

        else:
            json_respons['error'] = True
            json_response['data'] = "params error"

    except Exception as e:
        print "error while signing up user"
        print e
        
        # 500 internal server error
        raise ExceptionResponse()

    if user_id:
        json_response['error'] = False
        json_response['data'] = "Success!"
    else:
        json_response['error'] = True
        json_response['data'] = "Error signing up user"

    return jsonify(json_response)