Beispiel #1
0
def UserCheck(request):
    userid = request.POST.get('userid'),
    password = request.POST.get('password')
    customer_id = request.POST.get('cis')

    if Authenticate(userid, password) == 1:

        cursor = connection.cursor()
        cursor.execute(
            "SELECT id,userid,email FROM customers_info where userid= %s ",
            [userid])
        rows = cursor.fetchall()
        count = common.ObjectCount(common, rows)

        if count > 0:
            result = []
            columns = [col[0] for col in cursor.description]
            for row in rows:
                result.append(dict(zip(columns, row)))
            json_data = json.dumps(result)
            data_sent = '{"status":"1","desc":"Successfully Changed your password","userData": ' + json_data + '}'
            return HttpResponse(data_sent, content_type="application/json")
        else:
            json_data = '{"status":"0","desc":"Failed to change your password"}'
            return HttpResponse(json_data, content_type="application/json")
    else:
        json_data = '{"status":"0","desc":"Invalid Authentication"}'
        return HttpResponse(json_data, content_type="application/json")
Beispiel #2
0
def login(request):
    userid = request.POST.get('userid'),
    password = request.POST.get('password')
    # sql = ("SELECT id,username,email FROM auth_user where username= %s and password=%s ", [userid, password])
    # result = DB.Query(sql)
    genPass = common.PasswordGenerate(common, password)

    cursor = connection.cursor()
    cursor.execute(
        "SELECT id,customer_id,type,name,phone,email,userid,status,address FROM customers_info where userid= %s and password=%s and status=1 ",
        [userid, genPass])
    rows = cursor.fetchall()
    count = common.ObjectCount(common, rows)

    if count > 0:
        result = []
        columns = [col[0] for col in cursor.description]
        for row in rows:
            result.append(dict(zip(columns, row)))
        json_data = json.dumps(result)
        data_sent = '{"status":"1","desc":"Authentication Success","UserData":' + json_data + '}'
        return HttpResponse(data_sent, content_type="application/json")
    else:
        json_data = '{"status":"0","desc":"Invalid Login Credential"}'
        return HttpResponse(json_data, content_type="application/json")
Beispiel #3
0
def Authenticate(userid, password):

    genPass = common.PasswordGenerate(common, password)
    cursor = connection.cursor()
    cursor.execute(
        "SELECT * FROM customers_info where userid= %s and password=%s and status=1 ",
        [userid, genPass])
    rows = cursor.fetchall()
    count = common.ObjectCount(common, rows)

    if count == 1:
        return 1
    else:
        return 0
Beispiel #4
0
def rgistration(request):
    userid = request.POST.get('userid'),
    password = request.POST.get('password')
    name = request.POST.get('name')
    phone = request.POST.get('phone')
    email = request.POST.get('email')
    status = 1
    type = 'Individual'
    passd = common.PasswordGenerate(common, password)
    # print(email)
    customer_id = common.CusotmerIDGen(common)
    # print(customer_id)

    if (str(userid) == ''):
        json_data = '{"status":"211","desc":"Userid can not be empty"}'
        return HttpResponse(json_data, content_type="application/json")
    elif (str(email) == ''):
        json_data = '{"status":"211","desc":"Email can not be empty"}'
        return HttpResponse(json_data, content_type="application/json")
    elif (str(name) == ''):
        json_data = '{"status":"211","desc":"Name can not be empty"}'
        return HttpResponse(json_data, content_type="application/json")
    elif (str(password) == ''):
        json_data = '{"status":"211","desc":"Password can not be empty"}'
        return HttpResponse(json_data, content_type="application/json")
    else:
        cursor = connection.cursor()
        cursor.execute(
            "SELECT id,userid,email FROM customers_info where userid= %s OR email =%s ",
            [userid, email])
        rows = cursor.fetchall()
        count = common.ObjectCount(common, rows)
        if count > 0:
            json_data = '{"status":"3","desc":"Email or username already exist, plesse try with different email or username"}'
            return HttpResponse(json_data, content_type="application/json")
        else:
            insert = cursor.execute(
                " INSERT INTO customers_info (customer_id,type,name,phone,email,userid,password,status) Values (%s,%s,%s,%s,%s,%s,%s,%s) ",
                [customer_id, type, name, phone, email, userid, passd, status])
            if (insert):
                json_data = '{"status":"1","desc":"Successfully Registered"}'
                return HttpResponse(json_data, content_type="application/json")
            else:
                json_data = '{"status":"0","desc":"Email or username already exist, plesse try with different email or username"}'
                return HttpResponse(json_data, content_type="application/json")
Beispiel #5
0
def ProfileUpdate(request):
    userid = request.POST.get('uid'),
    password = request.POST.get('pwd')
    phone = request.POST.get('phone')
    email = request.POST.get('email')
    address = request.POST.get('address')
    photo = request.POST.get('photo')

    if Authenticate(userid, password) == 1:

        if (str(userid) == ''):
            json_data = '{"status":"211","desc":"Userid can not be empty"}'
            return HttpResponse(json_data, content_type="application/json")
        elif (str(email) == ''):
            json_data = '{"status":"211","desc":"Email can not be empty"}'
            return HttpResponse(json_data, content_type="application/json")
        else:
            cursor = connection.cursor()
            cursor.execute(
                "SELECT id,userid,email FROM customers_info where userid= %s ",
                [userid])
            rows = cursor.fetchall()
            count = common.ObjectCount(common, rows)
            if count > 0:

                DataImageToFile(photo, userid)

                insert = cursor.execute(
                    " Update customers_info SET phone=%s,email=%s, address=%s WHERE userid =%s ",
                    [phone, email, address, userid])
                if (insert):
                    json_data = '{"status":"1","desc":"Successfully Updated"}'
                    return HttpResponse(json_data,
                                        content_type="application/json")
                else:
                    json_data = '{"status":"0","desc":"Failed to update"}'
                    return HttpResponse(json_data,
                                        content_type="application/json")
            else:
                json_data = '{"status":"3","desc":"Failed to updated"}'
                return HttpResponse(json_data, content_type="application/json")
    else:
        json_data = '{"status":"0","desc":"Invalid Authentication"}'
        return HttpResponse(json_data, content_type="application/json")