Exemple #1
0
def insertsign():
    try:
        #__user = Markup(request.json['username']).striptags()
        __email = request.json['email']
        __first_name = request.json['first_name']
        __last_name = request.json['last_name']
        __password = request.json['password']
        query = """INSERT INTO user(first_name, last_name, email, password)VALUES('%s', '%s', '%s', '%s')""" % \
            (__first_name,  __last_name, __email, __password)
        pprint(query)

        conn = mysql.connect()
        cursor = conn.cursor()
        cursor.execute(query)
        conn.commit()
        data = cursor.fetchall()
        datas = {__first_name, __last_name, __email, __password}
        req_data = []
        logall(data, "REQUEST", 1, toJson(req_data.append(datas)))
        if cursor.execute(query):
            return jsonify({
                "responseCode": "000",
                "responseMsg": "Data stored!!",
                "data": req_data.append(datas)
            })
        else:
            return jsonify({"something went wrong"})
    except Exception as e:
        return jsonify({"status": str(e)})
Exemple #2
0
def addwish():
    try:
        if session.get('user'):
            __title = request.form['inputTitle']
            __desc = request.form['inputDescription']
            __user = session.get('user')
            __timestamp = datetime.datetime.now()


            sql = "INSERT INTO wishes(wish_title, wish_description,wish_user,time_posted) VALUES ('%s', '%s', '%s', '%s')" % \
            (__title,  __desc, __user, __timestamp)
            conn = mysql.connect()
            cursor = conn.cursor()
            cursor.execute(sql)
            data = cursor.fetchall()
            datas = {__title, __desc, __user, __timestamp}
            req_data = []
            logall(data, "REQUEST", 1, toJson(req_data.append(datas)))

            if len(data) is 0:
                conn.commit()
                return redirect('/userHome')
            else:
                return render_template('error.html',
                                       error="something went wrong")
        else:
            return render_template('error.html', error='Unauthorized Access')
    except Exception as e:
        return render_template('error.html', error=str(e))
    finally:
        cursor.close()
        conn.close()
Exemple #3
0
def getWish():
    try:
        if session.get('user'):
            __user = session.get('user')
            querystring = "SELECT * FROM wishes WHERE wish_user = '******'" % (
                __user)
            con = mysql.connect()
            cursor = con.cursor()

            cursor.execute(querystring)
            allWishes = cursor.fetchall()
            wishes_dict = []
            logall(allWishes, "REQUEST", 1, __user)
            for wish in allWishes:
                wish_dict = {
                    'Id': wish[0],
                    'Title': wish[1],
                    'Description': wish[2],
                    'Date': wish[4]
                }
                wishes_dict.append(wish_dict)

            return json.dumps(wishes_dict)
        else:
            return json.dumps({'status': 'unauthorised Access'})
    except Exception as e:
        return json.dumps({'status': str(e)})
Exemple #4
0
def validateLogin():
    try:
        _username = request.form['inputEmail']
        _password = hashlib.sha256(request.form['inputPassword']).hexdigest()

        # connect to mysql

        con = mysql.connect()
        cursor = con.cursor()
        sql = "SELECT * FROM wish_user WHERE email = '%s' AND password = '******' " % (
            _username, _password)
        cursor.execute(sql)
        data = cursor.fetchall()
        req_data = []
        datas = {'user': _username, 'pass': _password}

        logall(data, "REQUEST", 1, toJson(req_data.append(datas)))

        if len(data) > 0:
            for datas in data:
                uname = datas[1]
                session['user'] = uname
                return render_template('userHome.html', user=uname)
        else:
            return render_template('error.html',
                                   error='Wrong Email address or Password.' +
                                   str(len(data)))

    except Exception as e:
        return render_template('error.html', error=str(e))
    finally:
        cursor.close()
        con.close()
Exemple #5
0
def signin():
    try:
        __username = request.form['inputName']
        __useremail = request.form['inputEmail']
        __userpassword = request.form['inputPassword']
        __hashed_password = hashlib.sha256(__userpassword).hexdigest()
        if __username and __useremail and __userpassword:
            sql1 = "SELECT * FROM wish_user WHERE username = '******' AND password = '******'"
            #pprint(sql1)
            if cursor.execute(sql1) > 1:
                #pprint(cursor.execute(sql1))
                getdata = cursor.fetchone()
                return json.dumps({
                    "username": getdata[1],
                    "data": "This user exists"
                })
            else:
                sql = """INSERT IGNORE INTO wish_user(username, email, password, created_at) VALUES ('%s', '%s', '%s', '%s')""" % \
                (__username, __useremail, __hashed_password, getdate())

        if cursor.execute(sql):
            datas = {
                "username": __username,
                "email": __useremail,
                "password": __userpassword,
                "hashed password": __hashed_password
            }
            req_data = []
            getdata = cursor.fetchone()
            logall(str(cursor.execute(sql)), "RESPONSE", 1,
                   json.dumps({"data": datas}))
            conn.commit()
            return json.dumps({
                'success': 'signup was successful',
                "username": getdata[1]
            })
        else:
            conn.rollback()
            return json.dumps({'error': 'Something went wrong'})

    except Exception as e:
        return json.dumps({'error': str(e)})