def adminInsertUsername():
    try:
        loginDAO = LoginDAO()
        loginVO = LoginVO()

        loginUsername = request.form['loginUsername']
        loginVO.loginUsername = loginUsername
        loginVOList = loginDAO.validateLoginUsername(loginVO)
        loginDictList = [i.as_dict() for i in loginVOList]
        lenLoginDictList = len(loginDictList)
        if lenLoginDictList == 0:
            error = "E - mail is not exist !"
            return render_template("admin/forgotPassword.html", error=error)
        else:
            for row1 in loginDictList:

                loginId = row1['loginId']

                loginUsername = row1['loginUsername']

                session['session_loginId'] = loginId

                session['session_loginUsername'] = loginUsername

            otp = ''.join((random.choice(string.digits)) for x in range(6))

            sender = "*****@*****.**"

            receiver = loginUsername

            msg = MIMEMultipart()

            msg['From'] = sender

            msg['To'] = receiver

            msg['Subject'] = "Reset Password"

            msg.attach(MIMEText(otp, 'plain'))

            server = smtplib.SMTP('smtp.gmail.com', 587)

            server.starttls()

            server.login(sender, "keval12345")

            text = msg.as_string()

            server.sendmail(sender, receiver, text)

            server.quit()

            session["otp"] = otp
            return render_template("admin/addOtp.html")

    except Exception as ex:
        print(ex)
def userGenerateOTP():
    try:
        loginDAO = LoginDAO()
        loginVO = LoginVO()

        loginUsername = request.form['loginUsername']
        loginVO.loginUsername = loginUsername

        loginDictList = [
            i.as_dict() for i in loginDAO.validateLoginUsername(loginVO)
        ]

        if len(loginDictList) != 0:
            passwordOTP = ''.join(
                (random.choice(string.digits)) for x in range(4))

            session['session_OTP'] = passwordOTP
            session['session_loginUsername'] = loginUsername
            session['session_loginId'] = loginDictList[0]['loginId']

            sender = "*****@*****.**"

            receiver = loginUsername

            msg = MIMEMultipart()

            msg['From'] = sender

            msg['To'] = receiver

            msg['subject'] = "ACCOUNT PASSWORD"

            msg.attach(MIMEText('OTP to reset password is:'))

            msg.attach(MIMEText(passwordOTP, 'plain'))

            server = smtplib.SMTP('smtp.gmail.com', 587)

            server.starttls()

            server.login(sender, "9925646618")

            text = msg.as_string()

            server.sendmail(sender, receiver, text)

            server.quit()

            return render_template('user/addOTP.html')

        else:
            error = "The given Username is not registered yet!"
            return render_template("admin/login.html", error=error)

    except Exception as ex:
        print(ex)