Beispiel #1
0
def editprofile(request):
    c = checkpermission(request, request.path)
    if (c == -1):
        return redirect('/')
    elif (c == 0):
        return redirect('/home')
    idd = request.session['user']
    marketerdata = database.child('marketers').child(idd).child(
        'details').get()
    from datetime import date
    data = database.child('mIds').child(
        marketerdata.val()["phone"]).child('createdOn').get().val() / 100
    date = date.fromtimestamp(data)
    l = {
        'id': idd,
        'name': marketerdata.val()["name"],
        'age': marketerdata.val()["age"],
        'city': marketerdata.val()["city"],
        'email': marketerdata.val()["email"],
        'experience': marketerdata.val()["experience"],
        'gen': marketerdata.val()["gen"],
        'phone': marketerdata.val()["phone"],
        'state': marketerdata.val()["state"],
        'createdOn': date
    }
    if (request.method == "POST"):
        currentpassword = request.POST.get("currentpassword")
        newpassword = request.POST.get("newpassword")
        confirmpassword = request.POST.get("confirmpassword")
        print('rahul')
        print(request.FILES)
        if (request.FILES):
            print('rahul')
            storage.child('/marketers/' + idd).put(request.FILES["images"])
            request.session['image'] = getimage(idd)
        if (currentpassword == "" and newpassword == ""
                and confirmpassword == ""):
            return redirect('/home')
        else:
            if (newpassword != confirmpassword or len(newpassword) < 6):
                return render(request, './marketer/editProfile.html', {
                    'data': l,
                    'error': "Check Your Password"
                })
            else:
                current = database.child('mIds').child(
                    marketerdata.val()["phone"]).child('pass').get().val()
                if (getpass(currentpassword)[2:-1] != current):
                    return render(request, './marketer/editProfile.html', {
                        'data': l,
                        'error': "Check Your Current Password"
                    })
                else:
                    database.child('mIds').child(
                        marketerdata.val()["phone"]).update(
                            {'pass': getpass(newpassword)[2:-1]})
                    return redirect('/home')
    else:
        return render(request, './marketer/editProfile.html', {'data': l})
Beispiel #2
0
def newPassword(request):
        try:
            step = request.session['step']
            number = request.session['number']
            if step == 2:
                if request.method == 'POST':
                    code = request.POST.get('code')
                    c = database.child('ids').child(number).child('forgetPass').get().val()['code']
                    if str(c) == code:                        
                        request.session['step'] = 3                        
                        return render(request,'./students/newPassword.html')
                    else:
                        return render(request,'./students/verify.html',{'error':"Please fill correct code"})
                else:
                    return render(request,'./students/verify.html')           
            if step == 3:                
                if request.method == 'POST':
                    password = request.POST.get('pass')
                    conpassword = request.POST.get('conpass')                    
                    if (password ==conpassword and len(password)>=6):                       
                        database.child('ids').child(number).update({'pass':getpass(password)[2:-1]})
                        del request.session['step']
                        del request.session['number']
                        return render(request,'./students/forgotPassword.html',{'success':"Password change successfully."})
                    else:
                        return render(request,'./students/newPassword.html',{'error':'Password and confirm password must be equal nd minimun length must be greater than or equal to 6'}) 
                else:
                    return render(request,'./students/newPassword.html')
        except:
            return redirect('/students/forgetPassword')
Beispiel #3
0
def editteacher(request):
    iduser = request.GET.get('id')
    i = database.child('teachers').child(iduser).child('details').get()
    from datetime import date
    data = database.child('tIds').child(
        i.val()["phone"]).child('createdOn').get().val() / 1000
    date = date.fromtimestamp(data)
    l = {
        'id': iduser,
        'name': i.val()["name"],
        'age': i.val()["age"],
        'city': i.val()["city"],
        'email': i.val()["email"],
        'experience': i.val()["experience"],
        'gen': i.val()["gen"],
        'phone': i.val()["phone"],
        'state': i.val()["state"],
        'createdOn': date
    }
    if (request.method == "POST"):
        currentpassword = request.POST.get("currentpassword")
        newpassword = request.POST.get("newpassword")
        confirmpassword = request.POST.get("confirmpassword")
        name = request.POST.get('name')
        number = request.POST.get('number')
        mail = request.POST.get('email')
        sate = request.POST.get('state')
        city = request.POST.get('city')
        age = request.POST.get('age')
        experience = request.POST.get('experience')
        if (currentpassword != "" and newpassword != ""
                and confirmpassword != ""):
            if (newpassword != confirmpassword or len(newpassword) < 6):
                return render(request, './users/editTeacher.html', {
                    'data': l,
                    'error': "Check Your Password"
                })
            else:
                current = database.child('tIds').child(
                    i.val()["phone"]).child('pass').get().val()
                if (getpass(currentpassword)[2:-1] != current):
                    return render(request, './users/editeditTeacher.html', {
                        'data': l,
                        'error': "Check Your Current Password"
                    })
                else:
                    database.child('tIds').child(i.val()["phone"]).update(
                        {'pass': getpass(newpassword)[2:-1]})
                    return redirect('/home')
        else:
            if (number == i.val()["phone"]):
                print(i.val()['phone'])
                database.child('teachers').child(iduser).child(
                    'details').update({
                        'name': name,
                        'age': age,
                        'city': city,
                        'email': mail,
                        'experience': experience,
                        'gen': i.val()["gen"],
                        'phone': i.val()["phone"],
                        'state': sate,
                    })
                return redirect('/user/editteacher')

            else:
                if (database.child('tIds').child(number).shallow().get().val()
                    ):
                    error = "Phone Number Already exists"
                    data['error'] = error
                    return render(request, './users/editTeacher.html', data)
                else:
                    from random import randint
                    database.child('tIds').child(number).update({
                        'createdOn':
                        data,
                        'id':
                        iduser,
                        'verify':
                        randint(100000, 999999),
                        'pass':
                        getpass(number + "@TP@" + age)[2:-1],
                        # 'createdBy': database.child('tIds').child(i.val()["phone"]).child('createdBy').get().val(),
                    })
                    database.child('tIds').child(i.val()['phone']).remove()
                    database.child('teachers').child(iduser).child(
                        'details').update({
                            'name': name,
                            'age': age,
                            'state': sate,
                            'city': city,
                            'experience': experience,
                            'phone': number,
                            'email': mail,
                            'gen': i.val()["gen"]
                        })
                    return redirect('/user/editteacher')
    else:

        return render(request, './users/editTeacher.html', {'data': l})
Beispiel #4
0
def editProfile(request):
    c = checkpermission(request, request.path)
    if(c == -1):
        return redirect('/')
    elif(c == 0):
        return redirect('/home')
    iduser = request.session['user']
    i = database.child('teachers').child(iduser).child('details').get()
    from datetime import date
    data = database.child('tIds').child(
        i.val()["phone"]).child('createdOn').get().val()/1000
    date = date.fromtimestamp(data)
    
    l = {
        'id': iduser,
        'name': i.val()["name"],
        'age': i.val()["age"],
        'city': i.val()["city"],
        'email': i.val()["email"],
        'experience': i.val()["experience"],
        'gen': i.val()["gen"],
        'phone': i.val()["phone"],
        'state': i.val()["state"],
        'createdOn': date
    }
    if 'reviewLine' in i.val():
        l['reviewL']=i.val()['reviewLine']
    if 'testMsg' in i.val():
        l['testL']=i.val()['testMsg']
    if(request.method == "POST"):
        currentpassword = request.POST.get("currentpassword")
        newpassword = request.POST.get("newpassword")
        confirmpassword = request.POST.get("confirmpassword")
        reviewL = request.POST.get('reviewL')
        testL = request.POST.get('testL')
        if(request.FILES):
            
            storage.child('/teachers/'+iduser).put(request.FILES["images"])
            request.session['image']=getimage(iduser)
        if reviewL:
            database.child('teachers').child(iduser).child('details').update({'reviewLine':reviewL})
        if testL:
            database.child('teachers').child(iduser).child('details').update({'testMsg':testL})

        if (currentpassword != "" or newpassword != "" or confirmpassword != ""):
            if(newpassword != confirmpassword or len(newpassword) < 6):
                return render(request, './teacher/editProfile.html', {'data': l, 'error': "Check Your Password"})
            else:
                current = database.child('tIds').child(
                    i.val()["phone"]).child('pass').get().val()
                if(getpass(currentpassword)[2:-1] != current):
                    return render(request, './teacher/editProfile.html', {'data': l, 'error': "Check Your Current Password"})
                else:
                    database.child('tIds').child(i.val()["phone"]).update(
                        {'pass': getpass(newpassword)[2:-1]})
                    return render(request, './teacher/editProfile.html', {'data': l})
        
        return render(request, './teacher/editProfile.html', {'data': l})
    else:

        return render(request, './teacher/editProfile.html', {'data': l})
Beispiel #5
0
def users(request):
    global typea, typeb, typec
    c = checkpermission(request, request.path)
    if (c == -1):
        return redirect('/')
    elif (c == 0):
        return redirect('/home')
    else:
        menu = database.child('menu').get()
        menuList = []
        for i in menu:
            if i.key() != "free":
                menuList.append({'id': i.key(), 'name': i.val()['name']})
        if request.method == "POST":
            name = request.POST.get('name')
            number = request.POST.get('number')
            email = request.POST.get('email')
            age = request.POST.get('age')
            experience = request.POST.get('experience')
            gen = request.POST.get('gen')
            s = request.POST.get('s')
            d = request.POST.get('d')
            userType = request.POST.get('userType')
            data = {
                'name': name,
                'number': number,
                'email': email,
                'age': age,
                'experience': experience,
                'gen': gen,
                's': s,
                'menu': menuList,
                'd': d,
            }
            if (not name.replace(' ', '').isalpha()):
                error = "Name is invalid"
                data['error'] = error
                return render(request, './users/addUser.html', data)
            elif (len(str(number)) != 10):
                error = "Phone Number is invalid"
                data['error'] = error
                return render(request, './users/addUser.html', data)
            elif (email == ''):
                error = "Email is invalid"
                data['error'] = error
                return render(request, './users/addUser.html', data)
            elif (s is None):
                error = "Please Select State"
                data['error'] = error
                return render(request, './users/addUser.html', data)
            elif (userType is None):
                error = "Please Select User Type"
                data['error'] = error
                return render(request, './users/addUser.html', data)
            from datetime import datetime
            from random import randint
            time_now = int(datetime.now().timestamp() * 1000)
            create = request.session['user']

            if userType == "Teacher":

                if (database.child('tIds').child(number).shallow().get().val()
                    ):
                    error = "Phone Number Already exists"
                    data['error'] = error
                    return render(request, './users/addUser.html', data)

                free = database.child('tIds').child(
                    'free').shallow().get().val()
                if free:
                    tempid = free
                else:
                    tempid = 100001
                database.child('tIds').child(number).update({
                    'createdOn':
                    time_now,
                    'id':
                    "12" + str(tempid),
                    'verify':
                    randint(100000, 999999),
                    'pass':
                    getpass(number + "@TP@" + age)[2:-1],
                    'createdBy':
                    create
                })
                database.child('teachers').child("12" + str(tempid)).child(
                    'details').update({
                        'name': name,
                        'age': age,
                        'state': s,
                        'city': d,
                        'experience': experience,
                        'phone': number,
                        'email': email,
                        'gen': gen
                    })
                database.child('share').child('teachers').child(
                    '12' + str(tempid)).update({'earned': '0'})

                typea = getcode('a')
                typeb = getcode('b')
                typec = getcode('c')

                database.child('share').child('teachers').child(
                    '12' + str(tempid)).child('typeA').update(
                        {'code': "12" + str(tempid) + str(typea)})

                database.child('share').child('teachers').child(
                    '12' + str(tempid)).child('typeB').update(
                        {'code': "12" + str(tempid) + str(typeb)})

                database.child('share').child('teachers').child(
                    '12' + str(tempid)).child('typeC').update(
                        {'code': "12" + str(tempid) + str(typec)})
                database.child('tIds').update({'free': tempid + 1})
                data = {
                    'name': '',
                    'email': '',
                    'menu': menuList,
                }

                d = database.child('email').child(
                    'registration').shallow().get().val()
                d = d.replace('[Full Name]', name)
                d = d.replace('[USER ID]', "12" + str(tempid))
                d = d.replace('[phone number]', number)

                d = d.replace('[password]', number + "@TP@" + age)

                send_mail(
                    subject="account",
                    message='None',
                    html_message=d,
                    from_email='Registration<*****@*****.**>',
                    recipient_list=[email])
                data['success'] = "Teacher has been added Successfully!"
                data[
                    'info'] = number + "@TP@" + age + "is the password and 12" + str(
                        tempid) + " is the ID for " + ("Mr. " if gen == 'Male'
                                                       else "Ms. ") + name
                return render(request, './users/addUser.html', data)
            elif userType == "Admin":
                permission = []
                for i in menuList:
                    permissions = request.POST.get(i["id"])
                    if permissions:
                        permission.append(permissions)

                if (database.child('aIds').child(number).shallow().get().val()
                    ):
                    error = "Phone Number Already exists"
                    data['error'] = error
                    return render(request, './users/addUser.html', data)
                free = database.child('aIds').child(
                    'free').shallow().get().val()
                if free:
                    tempid = free
                else:
                    tempid = 1000

                database.child('aIds').child(number).update({
                    'id':
                    '13' + str(tempid),
                    'createdOn':
                    time_now,
                    'createdBy':
                    create,
                    'pass':
                    getpass(number + "@TP@" + age)[2:-1],
                    'permissions':
                    permission
                })
                database.child('admin').child('13' + str(tempid)).child(
                    'details').update({
                        'name': name,
                        'age': age,
                        'state': s,
                        'city': d,
                        'experience': experience,
                        'phone': number,
                        'email': email,
                        'gen': gen
                    })
                database.child('aIds').update({'free': tempid + 1})
                data = {
                    'name': '',
                    'email': '',
                }
                d = database.child('email').child(
                    'registration').shallow().get().val()
                d = d.replace('[Full Name]', name)
                d = d.replace('[USER ID]', "13" + str(tempid))
                print(d.find('[phone number'))
                d = d.replace('[phone number]', number)
                print(d.find('[phone number'))

                d = d.replace('[password]', number + "@TP@" + age)

                send_mail(
                    subject="account",
                    message='None',
                    html_message=d,
                    from_email='Registration<*****@*****.**>',
                    recipient_list=[email])
                data['success'] = "Admin has been added Successfully!"
                data[
                    'info'] = number + "@TP@" + age + "is the password and 13" + str(
                        tempid) + " is the ID for " + ("Mr. " if gen == 'Male'
                                                       else "Ms. ") + name
                return render(request, './users/addUser.html', data)

            elif userType == 'Typer':
                print("wxx")
                if (database.child('tyIds').child(
                        number).shallow().get().val()):
                    error = "Phone Number Already exists"
                    data['error'] = error
                    return render(request, './users/addUser.html', data)
                free = database.child('tyIds').child(
                    'free').shallow().get().val()
                if free:
                    tempid = free
                else:
                    tempid = 100000

                database.child('tyIds').child(number).update({
                    'id':
                    '14' + str(tempid),
                    'createdOn':
                    time_now,
                    'createdBy':
                    create,
                    'pass':
                    getpass(number + "@TP@" + age)[2:-1]
                })
                database.child('typers').child('14' + str(tempid)).child(
                    'details').update({
                        'name': name,
                        'age': age,
                        'state': s,
                        'city': d,
                        'experience': experience,
                        'phone': number,
                        'email': email,
                        'gen': gen
                    })
                database.child('tyIds').update({'free': tempid + 1})
                data = {
                    'name': '',
                    'email': '',
                    'menu': menuList,
                }
                d = database.child('email').child(
                    'registration').shallow().get().val()
                d = d.replace('[Full Name]', name)
                d = d.replace('[USER ID]', "14" + str(tempid))
                print(d.find('[phone number'))
                d = d.replace('[phone number]', number)
                print(d.find('[phone number'))

                d = d.replace('[password]', number + "@TP@" + age)

                send_mail(
                    subject="account",
                    message='None',
                    html_message=d,
                    from_email='Registration<*****@*****.**>',
                    recipient_list=[email])
                data['success'] = "Typer has been added Successfully!"
                data[
                    'info'] = number + "@TP@" + age + "is the password and 14" + str(
                        tempid) + " is the ID for " + ("Mr. " if gen == 'Male'
                                                       else "Ms. ") + name
                return render(request, './users/addUser.html', data)
            elif userType == "Marketer":
                if (database.child('mIds').child(number).shallow().get().val()
                    ):
                    error = "Phone Number Already exists"
                    data['error'] = error
                    return render(request, './users/addUser.html', data)
                free = database.child('mIds').child(
                    'free').shallow().get().val()
                if free:
                    tempid = free
                else:
                    tempid = 100000

                database.child('mIds').child(number).update({
                    'id':
                    '11' + str(tempid),
                    'createdOn':
                    time_now,
                    'createdBy':
                    create,
                    'pass':
                    getpass(number + "@TP@" + age)[2:-1]
                })
                database.child('marketers').child('11' + str(tempid)).child(
                    'details').update({
                        'name': name,
                        'age': age,
                        'state': s,
                        'city': d,
                        'experience': experience,
                        'phone': number,
                        'email': email,
                        'gen': gen
                    })

                teachers = database.child('share').child('marketers').child(
                    '11' + str(tempid)).update({'earned': '0'})

                typea = getcode('a')
                typeb = getcode('b')
                typec = getcode('c')

                database.child('share').child('marketers').child(
                    '11' + str(tempid)).child('typeA').update(
                        {'code': "11" + str(tempid) + str(typea)})

                database.child('share').child('marketers').child(
                    '11' + str(tempid)).child('typeB').update(
                        {'code': "11" + str(tempid) + str(typeb)})

                database.child('share').child('marketers').child(
                    '11' + str(tempid)).child('typeC').update(
                        {'code': "11" + str(tempid) + str(typec)})

                database.child('mIds').update({'free': tempid + 1})
                data = {
                    'name': '',
                    'email': '',
                    'menu': menuList,
                }
                d = database.child('email').child(
                    'registration').shallow().get().val()
                d = d.replace('[Full Name]', name)
                d = d.replace('[USER ID]', "11" + str(tempid))
                d = d.replace('[phone number]', number)

                d = d.replace('[password]', number + "@TP@" + age)

                send_mail(
                    subject="account",
                    message='None',
                    html_message=d,
                    from_email='Registration<*****@*****.**>',
                    recipient_list=[email])
                data['success'] = "Marketer has been added Successfully!"
                data[
                    'info'] = number + "@MP@" + "is the password and 11" + str(
                        tempid) + " is the ID for " + ("Mr. " if gen == 'Male'
                                                       else "Ms. ") + name
                return render(request, './users/addUser.html', data)

        else:

            name = ""
            email = ""
            data = {
                'name': name,
                'email': email,
                's': 'Select State First',
                'error': '',
                'success': '',
                'info': '',
                'menu': menuList,
            }
            return render(request, './users/addUser.html', data)