Ejemplo n.º 1
0
def apply(clubName):
    '''
    To apply in the club
    '''
    cur = mysql.connection.cursor()
    user = dict(session).get("email", None)

    if(user == None):
        return render_template("signIn.html")
    else:
        cur = mysql.connection.cursor()
        cur.execute(
            "select Club_Name FROM clubs WHERE Title='{}'".format(clubName))
        club = cur.fetchone()
        cur.execute(
            "INSERT INTO approvals VALUES('{}', '{}', 'U');".format(user, club[0]))
        mysql.connection.commit()
        cur.execute("select * from clubs WHERE Title=\'{}\'".format(clubName))
        club_title = cur.fetchone()
        cur.close()
        title = club_title[1]
        send_mail(user, "Subject: Thanks for applying\n\nThank you for applying to {}. \n You will soon recieve a mail regarding the interview from the club head".format(title))
        return render_template("applied.html", title=title)
Ejemplo n.º 2
0
    def post(self, request):
        random_password = str(randint(100000, 999999))
        login_user = request.user

        two_fa = TwoFactorAuthentication(user=login_user,
                                         code_to_verification=random_password)
        try:
            two_fa.save()
        except IntegrityError as e:
            return Response(
                '{0} (probably you try to login twice sequentially)'.format(e),
                status=status.HTTP_400_BAD_REQUEST)

        user_email_to_send = CbcEngine.get_engine().decrypt(login_user.email)
        subject = 'Verification Code - Funtestic'
        body = 'Hi, in order to login into Funtestic App - Please use the following security code: ' + \
               random_password
        try:
            send_mail(subject, body, user_email_to_send)
        except SMTPRecipientsRefused:
            two_fa.delete()
            raise exceptions.AuthenticationFailed(
                detail='Invalid email address.')
        return Response('Login successfully!')
Ejemplo n.º 3
0
    def put(self, request):
        try:
            child_id = CbcEngine.get_engine().encrypt(
                request.data['id_number'])
            child = Child.objects.get(id_number=child_id)
            quiz_of_child = Quiz.objects.filter(child=child)
        except KeyError:
            return Response('child_id field is missing.',
                            status=status.HTTP_400_BAD_REQUEST)
        except Child.DoesNotExist:
            return Response('child does not exist.',
                            status=status.HTTP_400_BAD_REQUEST)
        except Quiz.DoesNotExist:
            return Response('The child has no quiz.',
                            status=status.HTTP_400_BAD_REQUEST)

        request.data['id_number'] = child_id

        serializer = ReportSerializer(data=request.data)

        if not serializer.is_valid():
            print(serializer.errors)
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        try:
            pdf_name = "{}_report.pdf".format(child.id_number)
            pdf_dir = "media"

            if not os.path.exists(pdf_dir):
                os.makedirs(pdf_dir)
            try:
                report = Report.objects.get(child=child)
            except Report.DoesNotExist as e:
                report = None
                print(e)
            if report is not None:
                os.unlink('{0}/{1}'.format(pdf_dir, pdf_name))
                report.delete()

            serializer.save()
            # ____write report to pdf___:
            pdf = fpdf.FPDF(format='letter')
            pdf.add_page()
            pdf.set_font("Arial", "BU", size=24)
            pdf.set_text_color(0, 0, 128)

            pdf.write(5, "report:\n\n")

            pdf.set_font("Arial", size=12)
            pdf.set_text_color(0, 0, 0)
            pdf.write(
                5, "name: {0}\nage: {1}\ncreated Date: {2}\ngrades: ".format(
                    child,
                    CbcEngine.get_engine().decrypt(child.age),
                    (CbcEngine.get_engine().decrypt(
                        serializer.data['create_at'])).split(' ')[0]))

            i = 0
            for q in quiz_of_child:
                if i + 1 == len(quiz_of_child):
                    pdf.write(
                        5,
                        "{0} ".format(CbcEngine.get_engine().decrypt(q.grade)))
                else:
                    pdf.write(
                        5, "{0}, ".format(CbcEngine.get_engine().decrypt(
                            q.grade)))
                i += 1

            subject = 'Report for child - Funtestic'
            body = 'Hi! We sent you a report for your child.'
            pdf.output('{0}/{1}'.format(pdf_dir, pdf_name))
            # ___________________________

            send_mail(subject, body,
                      CbcEngine.get_engine().decrypt(child.parent.user.email),
                      pdf_name)
        except IntegrityError:
            return Response("The report is already exists",
                            status=status.HTTP_400_BAD_REQUEST)
        return Response('The report added successfully!')
Ejemplo n.º 4
0
def schedule(clubName, student):
    '''
    This Function helps to setup meeting with the following students who filled the form for joining
    respective club, It fetches the details from database and sends Mails to respective Email IDs  
    '''
    user = dict(session).get("email", None)
    if (user == None):
        return render_template("signIn.html")

    details = request.form

    verified = False
    cur = mysql.connection.cursor()
    cur.execute(
        f"SELECT Club_Title FROM clubheads WHERE Club_Head_Mail_Id ='{user}'")
    club = cur.fetchall()

    for i in club:
        if (i[0] == clubName):
            verified = True

    if (verified):

        if request.method == "POST":

            details = request.form
            time = details['time']
            time = time[:-3]

            date = details['date']
            date = date.split("/")
            date = date[2] + "-" + date[0] + "-" + date[1]

            link = details['link']
            host = details['host']

            # Insert into db

            send_mail(
                user,
                "Subject: Meeting Details\n\nMeeting scheduled with {}\nDetails: \nTime: {}\n Date: {}\n Link: {}"
                .format(student, time, date, link))
            send_mail(
                student,
                "Subject: Meeting Details\n\nHere are the scheduled meeting details:\nTime: {}\n Date: {}\n Link: {}"
                .format(time, date, link))

            cur = mysql.connection.cursor()
            cur.execute(
                "INSERT INTO meetings VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE host_mail_id=%s, student_mail_id=%s, meeting_time=%s, meeting_date=%s, link=%s",
                (host, student, time, date, link, host, student, time, date,
                 link))
            cur.execute(
                "UPDATE approvals SET CurrentStatus='A' WHERE Mail_Id='{}'".
                format(student))
            mysql.connection.commit()
            cur.close()
            # send mails
            return render_template("scheduled.html",
                                   student=student,
                                   link=link)

        else:
            if (checkIfMailIsValid(student)):
                cur = mysql.connection.cursor()
                cur.execute(
                    "SELECT meeting_time, meeting_date, link FROM meetings WHERE host_mail_id = '{}' AND student_mail_id = '{}'"
                    .format(user, student))
                meeting_details = cur.fetchone()
                date = str(meeting_details[1])
                date = date.split("-")
                date = date[1] + '/' + date[2] + '/' + date[0]
                date = date
                send_mail(
                    user,
                    "Subject: Meeting Updated\n\nMeeting updated with {}\nDetails:\nTime: {}\n Date: {}\n Link: {}"
                    .format(student, meeting_details[0], date,
                            meeting_details[2]))
                return render_template("interview.html",
                                       host=user,
                                       student=student,
                                       clubName=clubName,
                                       meeting_details=meeting_details,
                                       date=date)
            else:
                return render_template("error.html")

    else:
        return render_template("error.html")
Ejemplo n.º 5
0
def manage(clubName, manage, email):
    '''
    This function runs when club head  rejects,deletes and
    removes an applicant or schedule a meeting with the applicant.
    '''
    cur = mysql.connection.cursor()
    user = dict(session).get("email", None)
    if (user == None):
        return render_template("signIn.html")
    verified = False
    cur.execute(
        f"SELECT Club_Title FROM clubheads WHERE Club_Head_Mail_Id ='{user}'")
    club = cur.fetchall()

    for i in club:
        if (i[0] == clubName):
            verified = True

    if (verified):

        # Remove student from the club
        if (manage == "remove"):
            cur = mysql.connection.cursor()
            cur.execute("select Club_Name FROM clubs WHERE Title='{}'".format(
                clubName))
            club = cur.fetchone()
            cur.execute(
                "DELETE FROM clubMembers WHERE Mail_Id='{}' AND Club_Name='{}';"
                .format(email, club[0]))
            mysql.connection.commit()
            cur.close()
            flash("{} has been removed from the club.".format(user))
            return redirect("/clubs/{}".format(clubName))
        # Approve student and accept him to the club
        elif (manage == "approve"):
            cur = mysql.connection.cursor()
            cur.execute("select Club_Name FROM clubs WHERE Title='{}'".format(
                clubName))
            club = cur.fetchone()
            cur.execute("INSERT INTO clubmembers VALUES ('{}','{}');".format(
                email, club[0]))
            cur.execute(
                "DELETE FROM approvals WHERE Mail_Id='{}' AND Club_Name='{}';".
                format(email, club[0]))
            cur.execute(
                "DELETE FROM meetings WHERE student_mail_id = '{}' AND host_mail_id = '{}'"
                .format(email, user))
            send_mail(
                email,
                "Subject:Welcome Welcome!!\n\nCongrats from {}\n You have been accepted into the club!!"
                .format(club[0]))
            mysql.connection.commit()
            cur.close()
            flash("{} has been recruited into the club.".format(user))
            return redirect("/clubs/{}".format(clubName))
        # Reject the student
        elif (manage == "reject"):
            cur = mysql.connection.cursor()
            cur.execute("select Club_Name FROM clubs WHERE Title='{}'".format(
                clubName))
            club = cur.fetchone()
            cur.execute(
                "DELETE FROM approvals WHERE Mail_Id='{}' AND Club_Name='{}';".
                format(email, club[0]))
            mysql.connection.commit()
            cur.close()
            flash("{} has been rejected.".format(user))
            return redirect("/clubs/{}".format(clubName))

        elif (manage == "schedule"):
            if (checkIfMailIsValid(email)):
                # msg = "Scheduling Interview with clubhead of " + clubName
                # send_mail(user, "Interview scheduled with student")
                return render_template("interview.html",
                                       host=user,
                                       student=email,
                                       clubName=clubName,
                                       meeting_details=["", "", ""])

            else:
                return render_template("error.html")

        else:
            return render_template("error.html")

    else:
        return render_template("error.html")