Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- except:
- abort(404)
- @app.errorhandler(404)
- def not_found(e):
- return render_template('404.html')
- email = ts.loads(token, salt='email-confirm-key', max_age=86400)
- @app.route('/signup', methods=['GET', 'POST'])
- def signup():
- if 'email' in session:
- return redirect(url_for('tutorials'))
- form = SignupForm()
- if request.method == 'POST':
- emailalreadyexists = False
- emails = []
- wholetable = User.query.all()
- for row in wholetable:
- emails.append(row.email)
- if not form.validate() or form.email.data in emails:
- if form.email.data in emails and form.email.data != '':
- emailalreadyexists = True
- dplctemailerror = "That email is already in use."
- return render_template('signup.html', emailalreadyexists=emailalreadyexists,
- dplctemailerror=dplctemailerror, form=form)
- else:
- signupuser = User(form.first_name.data, form.last_name.data, form.role.data, form.school.data,
- form.email.data, form.password.data)
- db.session.add(signupuser)
- db.session.commit()
- token = ts.dumps(form.email.data, salt='email-confirm-key')
- subject = 'subject goes here'
- msg = Message(subject=subject, sender='name@email.com', recipients=form.email.data.split())
- link = url_for('confirm_email', token=token, _external=True)
- # msg.body = render_template("email_confirmationemail.txt", link=link, name=request.form['first_name'])
- msg.html = render_template("email_confirmationemail.html", link=link, name=request.form['first_name'])
- with app.app_context():
- mail.send(msg)
- return redirect(url_for('checkyouremail'))
- elif request.method == "GET":
- return render_template('signup.html', form=form)
- @app.route('/confirmemail/<token>')
- def confirm_email(token):
- try:
- email = ts.loads(token, salt='email-confirm-key', max_age=86400)
- except:
- abort(404)
- update_this = User.query.filter_by(email=email).first_or_404()
- update_this.emailconfirmed = True
- db.session.commit()
- if update_this.role == 'teacher':
- email_myself = 'me@email.com'
- subject = 'the subject'
- msg = Message(subject=subject, sender='name@email.com', recipients=email_myself.split())
- # msg.body = render_template("teachertoapprove.txt", email=email)
- msg.html = render_template("teachertoapprove.html", email=email)
- with app.app_context():
- mail.send(msg)
- # create a session with the given email and send user to the tutorials page where they will be logged in
- session['email'] = update_this.email
- return redirect(url_for('tutorials'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement