def forgot(): form = ResetForm(request.form) msg = '' msg1 = '' if request.method == "POST" and form.validate(): email = request.form['email'] user = User.query.filter_by(email=email).first() if user: msg1 = 'Email has been sent!' #bad error message # sent = MIMEText('Your API password is ' + user.password) # sent['Subject'] = "Retrieve Password " # sent['From'] = 'Toilet Admin <*****@*****.**>' # sent['To'] = 'User <*****@*****.**>' # # server = smtplib.SMTP("smtp.gmail.com:587") # server.starttls() # server.login("*****@*****.**", "wrsshovpluevyelj") # # # # sent = Message("your API password is " + user.password, # # sender="*****@*****.**", # # recipients=[email]) # # mail.send(sent) # # server.sendmail("*****@*****.**", email, sent.as_string()) # server.sendmail("*****@*****.**", "*****@*****.**", sent.as_string()) # server.quit() return render_template("forgot.html", form=form, msg=msg1) # else: msg = 'Email does not exist!' return render_template("forgot.html", form=form, msg=msg) return render_template('forgot.html', form=form)
def index(self): """ Prompt user for APIC credentials :return: """ form = CredentialsForm() reset_form = ResetForm() if session.get('ipaddr') is None: session['ipaddr'] = None session['secure'] = None session['username'] = None session['password'] = None apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) sdb.session.set_login_credentials(apic_args) if form.validate_on_submit() and form.submit.data: old_ipaddr = session.get('ipaddr') old_username = session.get('username') old_secure = session.get('secure') old_password = session.get('password') if ((old_ipaddr is not None and old_ipaddr != form.ipaddr.data) or (old_username is not None and old_username != form.username.data) or (old_secure is not None and old_secure != form.secure.data) or (old_password is not None and old_password != form.password.data)): flash('APIC Credentials have been updated') session['ipaddr'] = form.ipaddr.data session['secure'] = form.secure.data session['username'] = form.username.data session['password'] = form.password.data apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) sdb.session.set_login_credentials(apic_args) return redirect(url_for('credentialsview.index')) elif reset_form.reset.data: session['ipaddr'] = None session['secure'] = None session['username'] = None session['password'] = None apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) sdb.session.set_login_credentials(apic_args) return redirect(url_for('credentialsview.index')) return self.render('credentials.html', form=form, reset_form=reset_form, ipaddr=session.get('ipaddr'), username=session.get('username'), security=session.get('secure', 'False'))