def forgot_password(): try: # Send confirmation email f_email = request.form['f_email'] client = Client.query.filter_by(email=f_email).first() if client: token = s.dumps(f_email, salt='forgot-password') client.reset_password_token = token db.session.commit() msg = Message("Minute.tech - Forgot Password", sender="*****@*****.**", recipients=[f_email]) link = url_for('main.reset_password', token=token, _external=True) msg.body = render_template('email/forgot_password-email.txt', link=link, first_name=client.first_name) msg.html = render_template('email/forgot_password-email.html', link=link, first_name=client.first_name) mail.send(msg) flash(u'Password reset link sent to email', 'success') return redirect(url_for('main.homepage')) else: flash(u'The email you entered doesn\'t exists', 'danger') return redirect(url_for('main.login')) except Exception as e: return (str(e))
def send_email_verify(): if 'logged_in' in session and request.method == "GET": email = session['email'] first_name = session['first_name'] # Send confirmation email token = s.dumps(email, salt='email-verify') msg = Message("Minute.tech - Email Verification", sender="*****@*****.**", recipients=[email]) link = url_for('main.email_verify', token=token, _external=True) msg.body = render_template('email/send_email_verify.txt', link=link, first_name=first_name) msg.html = render_template('email/send_email_verify.html', link=link, first_name=first_name) mail.send(msg) flash(u'Verification email sent', 'success') return redirect(url_for('main.account')) else: flash(u'Log in as a client first, then click the link again', 'danger') return redirect(url_for('main.login'))
def register_page(): error = '' try: form = TechRegistrationForm(request.form) if request.method == "POST" and form.validate(): first_name = form.first_name.data last_name = form.last_name.data email = form.email.data phone = form.phone.data address = form.address.data city = form.city.data state = form.state.data tzip = form.tzip.data bio = "Not provided" password = sha256_crypt.encrypt((str(form.password.data))) technician = Technician.query.filter( or_(Technician.email == email, Technician.phone == phone)).first() if technician: if technician.email == email: flash( u'That email already has an account, please try a new email or send an email to [email protected]', 'danger') return render_template('technician/register.html', form=form) if technician.phone == phone: flash( u'That phone already has an account, please try a new phone or send an email to [email protected]', 'danger') return render_template('technician/register.html', form=form) else: technician = Technician(email=email, phone=phone, password=password, first_name=first_name, last_name=last_name, address=address, city=city, state=state, zip_code=tzip, bio=bio) db.session.add(technician) db.session.commit() flash(u'Thanks for registering!', 'success') session['logged_in'] = 'tech' # tid will be inputted once generated session['tid'] = technician.id session['first_name'] = technician.first_name session['email'] = technician.email session['phone'] = technician.phone session['rating'] = technician.rating # Send confirmation email token = s.dumps(email, salt='email-verify') msg = Message("Minute.tech - Email Verification", sender="*****@*****.**", recipients=[email]) link = url_for('technician.email_verify', token=token, _external=True) msg.body = render_template('technician/email/email_verify.txt', link=link, first_name=first_name) msg.html = render_template( 'technician/email/email_verify.html', link=link, first_name=first_name) mail.send(msg) return redirect(url_for('technician.account')) return render_template('technician/register.html', form=form) except Exception as e: return "Error: {}".format(e)
def register(): error = '' try: form = RegistrationForm(request.form) if request.method == "POST" and form.validate(): first_name = form.first_name.data last_name = form.last_name.data email = form.email.data phone = form.phone.data address = "Not provided" city = "Not provided" state = "NA" czip = form.czip.data bio = "Not provided" password = sha256_crypt.encrypt((str(form.password.data))) client = Client.query.filter( or_(Client.email == email, Client.phone == phone)).first() if client: if client.email == email: flash( u'That email already has an account, please try a new email or send an email to [email protected]', 'danger') return render_template('register.html', form=form) if client.phone == phone: flash( u'That phone already has an account, please try a new phone or send an email to [email protected]', 'danger') return render_template('register.html', form=form) else: client = Client(email=email, phone=phone, password=password, first_name=first_name, last_name=last_name, address=address, city=city, state=state, zip_code=czip, bio=bio) db.session.add(client) db.session.commit() flash(u'Thanks for registering!', 'success') session['logged_in'] = 'client' # we get the client ID on the first page after it is generated, # dont worry session['cid'] = client.id session['email'] = email # Send confirmation email token = s.dumps(email, salt='email-verify') msg = Message("Minute.tech - Email Verification", sender="*****@*****.**", recipients=[email]) link = url_for('main.email_verify', token=token, _external=True) msg.body = render_template('email/email_verify.txt', link=link, first_name=first_name) msg.html = render_template('email/email_verify.html', link=link, first_name=first_name) mail.send(msg) return redirect(url_for('main.account')) return render_template("register.html", form=form) except Exception as e: return "Error: {}".format(e)