def register(): if current_user.is_authenticated: return redirect(url_for('users.create')) form = RegisterationForm() if form.validate_on_submit(): user = Users.query.filter_by(email=form.email.data).first() if user: flash(Markup('this email already exist login instead')) else: session['email'] = form.email.data session['password'] = form.password.data session['username'] = form.username.data session['code'] = randomcode() session['confirm'] = True message = Message('confirmation code', sender="*****@*****.**", recipients=[form.email.data]) message.body = f'here is the confirmation code {session["code"]}' message.html = render_template('confirmation.html') print(session['code']) try: mail.send(message) except: return abort(404) return redirect(url_for('users.confirm')) return render_template('register.html', form=form)
def register(): if current_user.is_authenticated: return redirect(detect(current_user, 'main')) form = RegistrationForm() if form.validate_on_submit(): session['employee_email'] = form.email.data session['employee_username'] = form.username.data session['employee_password'] = form.password.data session['employee_phone_number'] = form.phone_number.data session['employee_address_street'] = form.street.data session['employee_address_city'] = form.city.data session['employee_address_province'] = form.province.data session['employee_address_country'] = form.country.data session['employee_gender'] = form.gender.data session['employee_code'] = random_code() print(session['employee_code']) message = Message("confirmation code", sender='*****@*****.**', recipients=[ form.email.data ]) # -------- change it to the domain account message.body = f'your confirmation code: {session["employee_code"]}' message.html = render_template('employee_confirmation.html') session['employee_confirm'] = True try: mail.send(message) except: return abort(404) flash(gettext('check your email to verify your account')) print(form.errors) return render_template('employee_register.html', form=form)
def consultation(): form = Consul() if form.validate_on_submit(): name = '' email = '' specialization = form.Specialization.data # Create new csv file in myproject directory with doctor details - Have columns "Doc_Name, Specialization, # Email, Phone Number" with open('myproject/DoctorsList.csv', 'r') as docfile: read = DictReader(docfile) for row in read: if row['Specialization'] == specialization: name = row['Doc_Name'] email = row['Email'] msg = Message('New Appointment Confirmation', sender='*****@*****.**', recipients=[email]) msg.body = f"Hello Doctor {name}.\n" \ f"Here is a new appointment for you.\n" \ f"Could you confirm an appointment for {form.date.data} at {form.time.data}? " \ f"Please get back to the patient at {current_user.email} .\n" \ f"Thank You!\n" \ f"Regards\n" \ f"Predict It" mail.send(msg) flash(f"Email/Appointment Sent to Dr.{name}") return render_template('consultation.html', form=form)
def forget(): if current_user.is_authenticated: return render_template('logged_in_already.html') form = yourEmail() if form.validate_on_submit(): # print(form.email.data) d = Users.query.filter_by(email=form.email.data).first() # print(Users.query.filter_by(email='*****@*****.**').first().email) # print(d) if d is None: flash( Markup( "<div class='alert alert-warning' role='alert'>this email doesn't related to any account try " "<a href='/register'>register</a></div>")) else: session['user'] = d.id try: msg = Message('reset Email', sender="*****@*****.**", recipients=[form.email.data]) session['verification'] = "".join( random.choice(string.digits) for x in range(random.randint(1, 12))) link = f"{url_for('reset', _external=True)}?de={session['verification']}" msg.body = f"Here is the reset link copy it and put it into your browser to reset your password " \ f"http:/127.0.0.1/reset?de={session['verification']}'>reset password</a>" msg.html = render_template('/resetpassword.html', link=link) mail.send(msg) flash( Markup( '<div class="alert alert-success" role="alert">The email has been sent</div>' )) except Exception as e: abort(404, e) return render_template('forget-password.html', form=form)
def send_reset_email(user): token = user.get_reset_token() msg = Message('Password Reset Request', sender='*****@*****.**', recipients=[user.email]) msg.body = f'''To reset your password, visit the following link: {url_for('reset_token', token=token, _external=True)} If you did not make this request then simply ignore this email and no chachanges will be made. ''' mail.send(msg)
def send_reset_email(user): token = user.get_reset_token() msg = Message('Password Reset Request', sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = f''' To reset your password,visit the following link: {url_for('reset_token', token =token,_external =True)} If you did not make this request then simply ignore this email and no changes will be made ''' mail.send(msg)
def admin_dashboard(): if request.method == 'POST' and 'teach_search' in request.form: branch = request.form['branch'] tid = request.form['t_id'] teacher = Teachers.query.filter_by(branch=branch).all() if teacher != None: return render_template('admin/dashboard.html', teacher=teacher) else: teacher = Teachers.query.filter_by(t_id=tid).first() return render_template('admin/dashboard.html', teacher=teacher) if request.method == 'POST' and 'teach_submit' in request.form: email = request.form['email'] password = request.form['psw'] password1 = request.form['rpsw'] usertype = request.form['usertype'] username = request.form['username'] if User.query.filter_by(email=email).first(): flash('Email address already register') return redirect(url_for('admin_dashboard')) elif User.query.filter_by(username=username).first(): flash(' Username address already register') return redirect(url_for('admin_dashboard')) elif password == password1: teachers1 = User(email=email, username=username, password=password, user_type=usertype) db.session.add(teachers1) db.session.commit() flash('User successfully register') msg = Message("Confirm Email", sender="*****@*****.**", recipients=[email]) msg.html = render_template('/mail/register.html', email=email, password=password, username=username) mail.send(msg) return redirect(url_for('admin_dashboard')) else: flash('Please enter same password') return redirect(url_for('admin_dashboard')) return render_template('admin/dashboard.html')
def register(): if current_user.is_authenticated: return redirect('/') session['qwertyuiopdfghjkldfghjklsdfghjkfghjk'] = None form = RegisterationForm() if form.validate_on_submit(): print('i a m s a d s o f u c k i n g m u c h') print(form.email.data) user = Users.query.filter_by(email=form.email.data).first() # print(user) if user: flash( Markup( '''<div class="alert alert-secondary" role="alert">the email already exsit login instead <a href='/login'>login</a></div>''')) return render_template('register.html', form=form) else: print('except ') session['email'] = form.email.data # session['username'] = form.username.data session['password'] = form.password.data # try: messag = Message('confirmation code', sender="*****@*****.**", recipients=[form.email.data]) session['confirmation'] = "".join( random.choice(string.digits) for x in range(random.randint(1, 7))) # link = f"http://127.0.0.1:5000/reset?de={session['verification']}" print(session['confirmation']) messag.body = f"Here is the confirmation code copy it and put it into the confirmation box to your password {session['confirmation']} " messag.html = render_template('/confirmationmail.html') ser = Users(email=session['email'], password=session['password'], myid=generate_new_id()) db.session.add(ser) db.session.commit() # ---------------remove this when the internet come mail.send(messag) session['qwertyuiopdfghjkldfghjklsdfghjkfghjk'] = True return redirect(url_for('users.confirmation')) # except Exception as e: # print(e) # session['qwertyuiopdfghjkldfghjklsdfghjkfghjk'] = False print(form.errors) return render_template('register.html', form=form)
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash("All fields are required") return render_template("contact.html", form=form) else: msg = Message(form.subject.data, sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template("contact.html", success=True) elif request.method == "GET": return render_template("contact.html", form=form)
def forgot_password(): try: if current_user.is_authencitcated: return redirect(detect(current_user, 'main')) except: pass form = ResetForm() if form.validate_on_submit(): print('good') u = Users.query.filter_by(email=form.email.data).first() if u is None: flash(Markup(gettext("email doesn't exist try to") + "<a href='/'>" + gettext("register") + "</a>")) else: session['user'] = u.id message = Message('confirmation code', sender='*****@*****.**', recipients=[form.email.data]) session['reset_code'] = random_code() message.body = f'your reset code: copy this link and put it in browser {url_for("mained.reset")}?' \ f'reset_code={session["reset_code"]}' # ----- _external for url_for is external message.html = render_template('reset_email.html') mail.send(message) session['reset_true'] = True return redirect(detect(current_user, 'reset')) print(form.errors) return render_template('forget_password.html', form=form)
def send_email(recepient_email, subject, body_html, body_text): msg = Message(subject, sender=ADMINS[0], recipients=[recepient_email]) msg.body = body_html msg.html = body_text mail.send(msg)