Esempio n. 1
0
def adminSendForgotPassword():
    try:
        loginDAO = LoginDAO()
        loginVO = LoginVO()

        OTP = request.form["otp"]

        if session['session_OTP'] != OTP:
            msg = "OTP IS NOT MATCHED"

            return render_template('user/otp.html', error=msg)
        else:
            loginId = session['session_loginId']

            password = ''.join((random.choice(string.ascii_letters + string.digits)) for x in range(8))

            print(password)

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

            receiver = session['session_loginUsername']

            msg = MIMEMultipart()

            msg['From'] = sender

            msg['To'] = receiver

            msg['Subject'] = "YOUR PASSWORD"

            msg.attach(MIMEText('Your Password is:' + password, 'plain'))

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

            server.starttls()

            server.login(sender, "Qwer123@")

            text = msg.as_string()

            server.sendmail(sender, receiver, text)
            print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")

            loginVO.loginId = loginId
            loginVO.loginPassword = password

            loginDAO.forgotPassword(loginVO)

            return render_template('user/login.html')
    except Exception as ex:
        print(ex)
Esempio n. 2
0
def adminResetPassword():
    try:
        loginDAO = LoginDAO()
        loginVO = LoginVO()

        oldPassword = request.form["oldPassword"]
        newPassword = request.form["newPassword"]
        conformPassword = request.form["conformPassword"]

        loginUsername = session['session_loginUsername']

        loginVOList = loginDAO.findUser(loginUsername)
        print(loginVOList)
        loginDictList = [i.as_dict() for i in loginVOList]

        print(loginDictList)

        if loginDictList[0]['loginPassword'] != oldPassword:
            msg = "PASSWORD IS NOT MATCHED"

            return render_template('bloodbank/resetPassword.html', error=msg)
        else:
            if newPassword == conformPassword:
                loginId = session['session_loginId']

                loginVO.loginId = loginId
                loginVO.loginPassword = newPassword

                loginDAO.forgotPassword(loginVO)

                if adminLoginSession() == 'bloodbank':

                    return render_template('bloodbank/index.html')

                elif adminLoginSession() == 'user':

                    return render_template('user/index.html')
            else:
                msg = "NEWPASSWORD AND CONFORMPASSWORD IS NOT MATCHED"

                return render_template('bloodbank/resetPassword.html', error=msg)
    except Exception as ex:
        print(ex)