Beispiel #1
0
def upload():
    print "####################"
    # data = json.dumps(request.data)
    print request.data
    # print request.data[0]
    # print request.file
    # print request.template
    tokenUserName = get_jwt_identity()
    if tokenUserName:
        con = conection_admin_db()
        c = con.regform.find_one({'username':tokenUserName})
        admin_db_name =  c['db_name']
        print admin_db_name


        # data = json.loads(request.data)
        print "~~~~~~~~~~~~~~~~"
        f = request.files['template']

        # f = request.files['data_file']

        #store the file contents as a string
        fstring = f.read()
        import csv
        print fstring
        #create list of dictionaries keyed by header row
        csv_dicts = [{k: v for k, v in row.items()} for row in csv.DictReader(fstring.splitlines(), skipinitialspace=True)]
        d =conection_user_db()
        d.local.insert_many(csv_dicts)
        # p protected()
        print csv_dicts
        print "hello"
        return jsonify({'Found':True}), 200
    else:
        return jsonify({'Found':False}), 401
Beispiel #2
0
def checkusername(value):
    collection = conection_admin_db()
    d = str(uuid.uuid4())[:8]
    if (collection.regform.find_one({'username': value})):
        checkusername(d)
    else:
        print(d)
        return d
Beispiel #3
0
def prelogin():
    print(request, 2 * "#")
    print("############# On Pre Email Validation #############")
    print(type(request.data))
    d = str(request.data, 'utf-8')
    print(type(d))
    collection = conection_admin_db()
    cursor = collection.regform
    f = cursor.find_one({'email': d})
    if f:
        return "1"
    else:
        return "0"
Beispiel #4
0
def prelogin():
#    print dir(request)   
    print "############# On Pre Email Validation #############"        
    print request.data
    d = request.data
    #print type(d)
    con = conection_admin_db()        
    f = con.regform.find_one({'email': d})
    print f
    # print type(f)
    if f:
        return "1"
    else:
        return "0"
Beispiel #5
0
def onforgetPassword():
#    print dir(request)   
    print "############# On Forget Password #############"
    print request.data
    d = json.loads(request.data)
    print d["email"]
    email = d["email"]
    con = conection_admin_db()
    c =con.regform.find_one({'email':email})
    if c:
        msg = Message('Your New Password', sender = '*****@*****.**', recipients = [d['email']])
        print d
        msg.body = "Hello,"
        msg.html = "<br>Your new password is ..... generate new password"
        print msg,type(msg)
        mail.send(msg)
        return jsonify({'Found':True}), 200
    else:
        return jsonify({'Found':False}), 404
Beispiel #6
0
def onlogin():
#    print dir(request)   
    print "############# On User Login #############"        
    print request.data
    d = json.loads(request.data)
    print d["password"]
    print d["username"]
    psw = d["password"] 
    uname = d["username"]

    access_token = create_access_token(identity=d['username'])
    refresh_token = create_refresh_token(identity=d['username'])

    con = conection_admin_db()
    c =con.regform.find_one({'username':uname,'password':psw})
    print c
    if c:
        return jsonify({'Found':True, 'access_token': access_token,'refresh_token': refresh_token}), 200
    else:
        return jsonify({'Found':False}), 404
Beispiel #7
0
def onlogin():
    print "############# On User Login #############"
    print request.data
    d = json.loads(request.data)
    psw = d["password"]
    uname = d["username"]

    access_token = create_access_token(identity=d['username'])
    refresh_token = create_refresh_token(identity=d['username'])

    con = conection_admin_db()
    c = con.regform.find_one({'username': uname, 'password': psw})
    print c
    if c:
        return json.dumps({
            'Found': True,
            'access_token': access_token,
            'refresh_token': refresh_token
        }), 200, {
            'ContentType': 'application/json'
        }
Beispiel #8
0
def register():
    #    print dir(request)
    if request.method == 'POST':
        print("-------------- On Register --------------")
        print(request.data)
        d = json.loads(request.data)
        username = str(uuid.uuid4())[:8]

        print('*********')
        print(username)
        print('*********')
        cleanusername = checkusername(username)
        d['username'] = cleanusername
        d['password'] = "******"
        d['role'] = 'admin'
        d['db_name'] = d['business_name'].replace(' ', '')

        # -------------- GENERATING RANDOM PASSWORD --------------
        userpass = str(uuid.uuid4())[:8]
        # -------------- ^^^^^^ NOT SAVING PASSWORD --------------
        UUID_STRIN = uuid.uuid4()
        d['UUID'] = UUID_STRIN
        d['createdAt'] = datetime.datetime.now()
        con = conection_admin_db()
        con.regform.insert_one(d)
        msg = Message('Welcome',
                      sender='*****@*****.**',
                      recipients=[d['email']])
        print(d)

        # confirm_url = "http://localhost:4200/"+str(UUID_STRIN)
        # msg.html=render_template('confirm.html', confirm_url=confirm_url)
        # msg.body = html
        # print(msg,type(msg.body))
        # mail.send(msg)

        return jsonify({'success': True}), 200
    else:
        return jsonify({'success': False}), 404