def register(): if current_user.is_authenticated(): return redirect('/') form = RegisterForm(request.form) if form.validate_on_submit(): user = User( email=form.email.data, password=form.password.data, confirmed=False ) db.session.add(user) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html) login_user(user) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for("user.unconfirmed")) return render_template('user/register.html', form=form)
def resend_confirmation(): token = generate_confirmation_token(current_user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(current_user.email, subject, html) flash('A new confirmation email has been sent.', 'success') return redirect(url_for('user.unconfirmed'))
def resend_confirmation(): #Token e mail token = current_user.generate_confirmation_token() send_email(current_user.email, 'Conferma il tuo account', '/email/confirm', user=current_user, token=token) flash('Una nuova mail di conferma è stata inviata', 'success') return redirect(url_for('main.index'))
def profile_delete(profile_id): profile = Profile.query.get(profile_id) user_id = profile.user_id user = User.query.filter_by(id=user_id).first() profile.validity = False db.session.commit() # user = User.query.filter_by(id=profile.user_id).first() html = render_template('profile/revoke.html') subject = "Your Membership Has been revoked" send_email(user.email, subject, html) flash('Membership has been Revoked. An email has been sent to the member', 'danger') return render_template('profile/profileView.html', profile=profile)
def register(): form = RegistrationForm() if form.validate_on_submit(): user = Utente(email=form.email.data.lower(), username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() #Token e mail token = user.generate_confirmation_token() send_email(user.email, 'Conferma registrazione', '/email/confirm', user=user, token=token) flash('Una mail di conferma è stata inviata', 'success') return redirect(url_for('auth.login')) return render_template('register.html', form=form)
def scheduled(): """ Command to run send of scheduled emails """ a_week_ago = date.today() - timedelta(days=7) # Retrieve Parent and Baby details for mail shot emails = db.session.query( User.email, User.name, Baby, ).join( Baby ).filter( Baby.dob.between(a_week_ago, date.today()), Baby.last_outcome_email == None, Baby.gender == 'u', Baby.predicted_gender != 'u', ).all() for parent_email, user_name, baby in emails: # get the user's name, and the baby's name (which is optional), else dob data = { 'user_name': user_name, } # use the baby name if it was set else use the dob if baby.name: data['baby_name'] = baby.name else: data['dob'] = baby.dob # generate email token = generate_outcome_token(parent_email, baby.id) confirm_url = url_for('prediction.confirm_outcome', token=token, _external=True) html = render_template( 'gender_confirm.html', confirm_url=confirm_url, data=data, ) subject = "Did we get it right?" # send email send_email(parent_email, subject, html) # set last_outcome_email value baby.last_outcome_email = date.today() db.session.add(baby) db.session.commit()
def contact(): form = ContactForm(request.form) if form.validate_on_submit(): d = { 'name': form.name.data, 'email': form.email.data, 'tel': form.tel.data, 'message': form.message.data, 'municipalite': form.municipalite.data } email = "*****@*****.**" html = render_template('user/email.html', d=d) subject = u"Join demande from municipality " + d['municipalite'] send_email(email, subject, html) return render_template('user/contact.html', send=True) return render_template('user/contact.html', form=form)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data.lower() token = current_user.generate_email_change_token(new_email) #Token e mail send_email(new_email, 'Conferma nuovo indirizzo email', '/email/change_email', user=current_user, token=token) flash('Email inviata al tuo nuovo indirizzo email', 'success') return redirect(url_for('main.index')) else: flash('Email o password non validi', 'danger') return render_template("change_email.html", form=form)
def send_email_verification(user_id: str): user = users_model.get_user(user_id, ["email_verification", "email"]) verification_str = user["email_verification"] try: verification_url = url_for("verify", username=user_id, verification_str=verification_str, _external=True) except RuntimeError: verification_url = "SENT FROM TERMINAL: %s" % (verification_str) return email.send_email("Thank you for registering for Sherwyn's CS 166 Security Blog! Go to the following link to verify your email: %s" % verification_url, user["email"])
def password_reset_request(): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): user = Utente.query.filter_by(email=form.email.data.lower()).first() if user: #Token e mail token = user.generate_reset_token() send_email(user.email, 'Ripristino password dimenticata', '/email/reset_password', user=user, token=token) flash('Una email con istruzioni è stata inviata', 'success') else: flash('Mail non presente in archivio', 'danger') return redirect(url_for('auth.login')) return render_template('reset_password.html', form=form)
def home(): form = RequestForm(request.form) if form.validate_on_submit(): token = generate_confirmation_token(form.mailbox.data) reset_url = url_for('main.reset_password', token=token, _external=True) html = render_template('main/reset.html', mailbox=form.mailbox.data, reset_url=reset_url) subject = "Reset your email password" send_email(form.email.data, subject, html) flash( 'A password reset email has been sent. Check your spam/junk folders if it does not arrive.', 'success') return redirect(url_for("main.home")) return render_template('main/request_pwdch.html', form=form)
def signup_post(): form = SignUpForm() if form.validate_on_submit(): user = User(email=form.email.data, name=form.name.data.strip(), password=form.password.data, doctor=form.doctor.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash('A confirmation email has been sent to you by email.', 'succes') login_user(user) return redirect(url_for('main.profile')) __flashErrors(form.errors.items()) return redirect(url_for('auth.signup'))
def forgot(): form = ForgotForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() token = generate_confirmation_token(user.email) user.password_reset_token = token db.session.commit() reset_url = url_for('user.forgot_new', token=token, _external=True) html = render_template('user/reset.html', username=user.email, reset_url=reset_url) subject = "Reset your password" send_email(user.email, subject, html) flash('A password reset email has been sent via email.', 'success') return redirect(url_for("main.home")) return render_template('user/forgot.html', form=form)
def send_password_recovery_email(email): """ :param email: :return: """ user = User.query.filter_by(email=email).first() token = ts.dumps(user.email, salt='recover-key') reset_url = url_for('user.recover_password', token=token, _external=True) html = render_template('emails/password_reset_request.html', reset_url=reset_url, user=user) subject = "SKEDD - Password Reset Requested" send_email(user.email, subject, html) flash('Password reset email sent to ' + email, 'success')
def export_posts(user_id): try: user = User.query.get(user_id) _set_task_progress(0) data = [] i = 0 total_posts = user.posts.count() for post in user.posts.order_by(Post.timestamp.asc()): data.append({ "body": post.body, "timestamp": post.timestamp.isoformat() + "Z" }) time.sleep(5) i += 1 _set_task_progress(100 * i // total_posts) try: send_email( "[ClothesManager] Your blog posts", sender=app.config["ADMINS"][0], recipients=[user.email], text_body=render_template("email/export_posts.txt", user=user), html_body=render_template("email/export_posts.html", user=user), attachments=[( "posts.json", "application/json", json.dumps({"posts": data}, indent=4), )], sync=True, ) except: print(data) except: app.logger.error("Unhandled exception", exc_info=sys.exc_info()) finally: _set_task_progress(100)
def register(): form = RegisterForm(request.form) if form.validate_on_submit(): user = User(email=form.email.data, password=form.password.data, confirmed=False) db.session.add(user) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html) login_user(user) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for("user.unconfirmed")) return render_template('user/register.html', form=form)
def register(): form = RegisterForm(request.form) if form.validate_on_submit(): profile = User( email=form.email.data, password=form.password.data, confirmed=False, ) db.session.add(profile) db.session.commit() token = generate_confirmation_token(profile.email) confirm_url = url_for('profile.confirm_email', token=token, _external=True) html = render_template('profile/activate.html', confirm_url=confirm_url) subject = "Please confirm your email for Pet Portrait Club" send_email(profile.email, subject, html) login_user(profile) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for("profile.unconfirmed")) return render_template('profile/register.html', form=form)
def signup(): form = SignupForm() verified=False; if request.method == 'POST': pass_hash = generate_password_hash(form.password.data, method='pbkdf2:sha256') verified = True; k = hashlib.pbkdf2_hmac('sha256', b'password', b'salt', 100000) stoken = binascii.hexlify(k) print(stoken) # Insert the user in the DB try: mongo.db.users.insert({"_id": form.username.data, "password": pass_hash, "email": form.email.data,"status":"activated","key":stoken}) #return 'Welcome! Thanks for signing up. Please follow this link in your email to activate your account:' return 'Welcome! Thanks for signing up, Please follow to the link to Login <a href="/login">Login</a>' # except DuplicateKeyError: # return 'user alreaday exist' except Exception as e: if 'duplicate key' in str(e): return "A user with that credentials already exist!" return str(e);#"User already present in DB." #user = mongo.db.users.find_one({"_id": form.username.data}) token = generate_confirmation_token(user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html) login_user(user) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for("home.html")) return render_template('signup.html', title='signup', form=form)
def register(): form = RegisterForm(request.form) if form.validate_on_submit(): user = User( email=form.email.data, password=form.password.data, confirmed=False ) db.session.add(user) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html) login_user(user) flash('You registered and are now logged in. Welcome!', 'success') return redirect(url_for('user.unconfirmed')) return render_template('user/register.html', form=form)
def calculator(): form = RegisterForm(request.form) if form.validate_on_submit(): user = User( driverName=form.driverName.data, carPrice=form.carPrice.data.replace(",", "."), medianConsumption=form.medianConsumption.data.replace(",", "."), medianDistance=form.medianDistance.data.replace(",", "."), gasPrice=form.gasPrice.data.replace(",", "."), taxesPrice=form.taxesPrice.data.replace(",", "."), maintenancePrice=form.maintenancePrice.data.replace(",", "."), securePrice=form.securePrice.data.replace(",", "."), penaltiesPrice=form.penaltiesPrice.data.replace(",", "."), parkingPrice=form.parkingPrice.data.replace(",", "."), email=form.email.data, password="******", confirmed=False) db.session.add(user) db.session.commit() car_annualDepreciation = round(((8 * float(user.carPrice)) / 100), 2) car_annualSpendWithGasoline = round( ((((float(user.medianDistance) / float(user.medianConsumption)) * float(user.gasPrice)) * 30) * 12), 2) car_annualSpendWithParking = round((float(user.parkingPrice) * 12), 2) car_annualCost = round( (car_annualSpendWithGasoline + car_annualSpendWithParking + float(user.penaltiesPrice) + float(user.maintenancePrice) + float(user.taxesPrice) + float(user.securePrice) + car_annualDepreciation), 2) car_annualOpportunityCost = round( ((float(user.carPrice) + car_annualCost) * (6.5 / 100)), 2) car_annualSpendTotal = round( (car_annualCost + car_annualOpportunityCost), 2) uber_baseFare = 2.70 uber_fixedCost = 1.00 uber_costPerMinute = 0.18 uber_costPerKM = 1.25 uber_distancePerRun = round((float(user.medianDistance) / 2), 2) uber_timePerRun = round(((uber_distancePerRun * 60) / 60), 2) uber_dailyCost = round(((uber_baseFare + uber_fixedCost + (uber_costPerMinute * uber_timePerRun) + (uber_costPerKM * uber_distancePerRun)) * 2), 2) uber_monthlyCost = round((uber_dailyCost * 30), 2) uber_annualCost = round((uber_monthlyCost * 12), 2) uber_totalCost = round((uber_annualCost - car_annualOpportunityCost), 2) taxi_baseFare = 0 taxi_fixedCost = 5.24 taxi_costPerMinute = 0.53 taxi_costPerKM = 2.85 taxi_distancePerRun = round((float(user.medianDistance) / 2), 2) taxi_timePerRun = round(((taxi_distancePerRun * 60) / 60), 2) taxi_dailyCost = round(((taxi_baseFare + taxi_fixedCost + (taxi_costPerMinute * taxi_timePerRun) + (taxi_costPerKM * taxi_distancePerRun)) * 2), 2) taxi_monthlyCost = round((taxi_dailyCost * 30), 2) taxi_annualCost = round((taxi_monthlyCost * 12), 2) taxi_totalCost = round((taxi_annualCost - car_annualOpportunityCost), 2) taxi99_baseFare = 0 taxi99_fixedCost = 2.38 taxi99_costPerMinute = 0.19 taxi99_costPerKM = 1.14 taxi99_distancePerRun = round((float(user.medianDistance) / 2), 2) taxi99_timePerRun = round(((taxi99_distancePerRun * 60) / 60), 2) taxi99_dailyCost = round( ((taxi99_baseFare + taxi99_fixedCost + (taxi99_costPerMinute * taxi99_timePerRun) + (taxi99_costPerKM * taxi99_distancePerRun)) * 2), 2) taxi99_monthlyCost = round((taxi99_dailyCost * 30), 2) taxi99_annualCost = round((taxi99_monthlyCost * 12), 2) taxi99_totalCost = round( (taxi99_annualCost - car_annualOpportunityCost), 2) html = render_template( 'user/debug.html', driverName=user.driverName, carPrice=user.carPrice, medianConsumption=user.medianConsumption, medianDistance=user.medianDistance, gasPrice=user.gasPrice, taxesPrice=user.taxesPrice, maintenancePrice=user.maintenancePrice, securePrice=user.securePrice, penaltiesPrice=user.penaltiesPrice, parkingPrice=user.parkingPrice, email=user.email, car_annualDepreciation=car_annualDepreciation, car_annualSpendWithGasoline=car_annualSpendWithGasoline, car_annualSpendWithParking=car_annualSpendWithParking, car_annualCost=car_annualCost, car_annualOpportunityCost=car_annualOpportunityCost, car_annualSpendTotal=car_annualSpendTotal, uber_baseFare=uber_baseFare, uber_fixedCost=uber_fixedCost, uber_costPerMinute=uber_costPerMinute, uber_costPerKM=uber_costPerKM, uber_distancePerRun=uber_distancePerRun, uber_timePerRun=uber_timePerRun, uber_dailyCost=uber_dailyCost, uber_monthlyCost=uber_monthlyCost, uber_annualCost=uber_annualCost, uber_totalCost=uber_totalCost, taxi_baseFare=taxi_baseFare, taxi_fixedCost=taxi_fixedCost, taxi_costPerMinute=taxi_costPerMinute, taxi_costPerKM=taxi_costPerKM, taxi_distancePerRun=taxi_distancePerRun, taxi_timePerRun=taxi_timePerRun, taxi_dailyCost=taxi_dailyCost, taxi_monthlyCost=taxi_monthlyCost, taxi_annualCost=taxi_annualCost, taxi_totalCost=taxi_totalCost, taxi99_baseFare=taxi99_baseFare, taxi99_fixedCost=taxi99_fixedCost, taxi99_costPerMinute=taxi99_costPerMinute, taxi99_costPerKM=taxi99_costPerKM, taxi99_distancePerRun=taxi99_distancePerRun, taxi99_timePerRun=taxi99_timePerRun, taxi99_dailyCost=taxi99_dailyCost, taxi99_monthlyCost=taxi99_monthlyCost, taxi99_annualCost=taxi99_annualCost, taxi99_totalCost=taxi99_totalCost) #html = render_template('user/activate.html', personName=user.driverName, annualSpendWithTheCar=annualSpendWithTheCar, annualSpendWithUber=annualSpendWithUber) subject = "Resultado: E ai, o que vale mais a pena? Carro ou Uber?" #token = generate_confirmation_token(user.email) #confirm_url = url_for('user.confirm_email', token=token, _external=True) #html = render_template('user/activate.html', confirm_url=confirm_url) #subject = "Please confirm your email" send_email(user.email, subject, html) #login_user(user) flash('A confirmation email has been sent via email', 'success') return redirect(url_for('user.calculator')) return render_template('user/calculator.html', form=form)
def register(): choices = [{'value': None, 'name': u'المنطقة البلدية'}] choices.extend([{ 'value': _.municipal_id, 'name': _.municipal_name_ar + ' ' + _.municipal_name } for _ in Municipality.query.filter_by(approved=True).all() if _.municipal_id != '1']) form = RegisterForm(request.form) if form.validate_on_submit(): if form.municipal_id.data != 'None': ckan_name = (form.email.data.split('@')[0] + '_' + form.municipal_id.data).replace('.', '').replace('-', '') password = form.password.data fullname = form.name.data + ' ' + form.last_name.data email = form.email.data list_ckan_user = get_list_user() ckan_email_list = [_['email'] for _ in list_ckan_user] if email in ckan_email_list: for e in list_ckan_user: if e['email'] == email: api_dict = e ckan_name = e['name'] else: api_dict = create_user_ckan(ckan_name, password, fullname, email) user = User(email=form.email.data, password=form.password.data, name=form.name.data, last_name=form.last_name.data, municipal_id=form.municipal_id.data, confirmed=False, deleted=False, activate=False, last_login=datetime.datetime.now(), phone_number=form.phone_number.data, work_position=form.work_position.data, api_key=api_dict['apikey'], ckan_id=api_dict['id'], ckan_name=ckan_name) db.session.add(user) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) mun_name = Municipality.query.filter_by(municipal_id=str( form.municipal_id.data)).first().municipal_name html = render_template('user/activate.html', confirm_url=confirm_url, name=form.name.data, last_name=form.last_name.data, last_login=datetime.datetime.now(), mun_name=mun_name) subject = u"برجاء تأكيد بريدك الالكترونى" send_email(user.email, subject, html) login_user(user) # flash(u'تم إرسال رسالة تأكيد عبر البريد الإلكتروني.', 'success') return redirect(url_for("user.unconfirmed")) else: flash(u'خانة المنطقة البلدية اجبارية', 'warning') return render_template('user/register.html', form=form, choices=choices)
def authorize(): form = request.form username = form.get('username') usernameReg = form.get('usernameReg') if form.get("signInButton") : """Log user in.""" if current_user.is_authenticated: return redirect(url_for('main.home')) # if user reached route via POST (as by submitting a form via POST) if request.method == "POST": # ensure username or pwd was submitted if not username or not form.get("pass"): flash('must provide username or pass', 'danger') return apology("must provide username or pass") user = User.query.filter_by(name = username).first() remember_me = False if form.get("check"): remember_me = True # ensure username exists and password is correct if user and bcrypt.check_password_hash(user.password, form.get("pass")): login_user(user, remember=remember_me) flash('Welcome.', 'success') return redirect(url_for('main.home')) else: flash('Invalid email and/or password.', 'danger') return render_template('user/authorize.html', form=form) else: """Register user.""" # if user reached route via POST (as by submitting a form via POST) if request.method == "POST": # ensure username was submitted if not usernameReg: return apology("Missing username!") # ensure password was submitted elif not form.get("password"): return apology("Missing password!") # ensure confirm_password was submitted elif not form.get("confirm_password"): return apology("Missing confirm password!") elif not form.get("password")==form.get("confirm_password"): return apology("Passwords do not match!") elif not form.get("email"): return apology("Missing email!") try: countryJson = requests.get('https://api.ipdata.co/').json() countryCode = countryJson['country_code'] except: countryCode = None user = User.query.filter_by(name = usernameReg).first() if user is None: gender = None; if not form.get("gender") == "null": gender = bool(distutils.util.strtobool(form.get("gender"))) user = User(password = form.get("password"), name = usernameReg) db.session.add(user) db.session.commit() email = form.get("email") details = Details(email = email, gender = gender, age = int(form.get("age")), locale = countryCode, user_id = user.id, confirmed = False, user = user) db.session.add(details) db.session.commit() else: return apology("Something wrong...Maybe the username was already registered.") token = generate_confirmation_token(email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url = confirm_url) subject = "Please confirm your email" send_email(email, subject, html) login_user(user) flash('You registered and are now logged in. Welcome!', 'success') return redirect(url_for('main.home')) # return redirect(url_for("unconfirmed")) return render_template("user/authorize.html", form=form)
import os from flask.ext.mail import Mail, Message from flask import Flask, render_template, url_for, redirect, send_from_directory from flask import request from project.email import send_email app = Flask(__name__) app.config.from_object(os.environ['APP_SETTINGS']) mail = Mail(app) subject = "test email" html = "test email" send_email('*****@*****.**', subject, html)