def sign_up(): if current_user.is_authenticated: return redirect(url_for('home.index')) form = SignUpForm() sent_token = False user_type = request.args.get('account_type', 'tourist') if request.method == 'POST' and form.validate_on_submit(): user_type = user_type if user_type in ['tourist', 'guide' ] else 'tourist' email = request.form.get('email', None) if email: secret_key = current_app.config['SECRET_KEY'] ts = URLSafeTimedSerializer(secret_key, salt='sign-up') verification_token = ts.dumps({ "email": email, "user_type": user_type }) url_token = '{}/sign-up/verify/{}'.format( current_app.config['SITE_URL'], verification_token) msg = Message("Verify account", sender=("Cicero demo", current_app.config['MAIL_USERNAME'])) msg.recipients = [email] msg.body = 'Complete your account information' msg.html = render_template('mail.html', url_token=url_token) mail.send(msg) sent_token = verification_token is not None return render_template('pages/sign_up/sign-up.html', form=form, sent=sent_token, account_type=user_type)
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_email(data['email']): return {"message": "User with that email id already exists."}, 400 connection = sqlite3.connect('data.db') cursor = connection.cursor() income = int(data['salary']) salary_per_year = income * 12 print(f"{salary_per_year}") print(type(salary_per_year)) if int(salary_per_year) <= 500000: user_type_id = 'A' elif int(salary_per_year) > 500000 & int(salary_per_year) <= 1000000: user_type_id = 'B' elif int(salary_per_year) > 1000000 & int(salary_per_year) <= 1500000: user_type_id = 'C' elif int(salary_per_year) > 1500000 & int(salary_per_year) <= 3000000: user_type_id = 'D' elif int(salary_per_year) > 3000000: user_type_id = 'E' print(user_type_id) # num = randint(1_200, 9999) num = 1200 get_list = UserList.get(self) user_list = get_list['users'] usrid = "" for iterator in user_list: usrid = iterator['user_id'] latestid = (usrid.split('-')[1]) num = int(latestid) + 1 print(num) print(num) user_id = user_type_id + '-' + str(num) date = today.strftime("%d") month = today.strftime("%b") random_number = randint(100, 999) character = random.choice('$_') password = str(date) + str(month) + str(character) + str(random_number) msg = Message('Dear User,', sender='*****@*****.**', recipients=[data['email']]) msg.body = "Your user id is " + user_id + " and your password is " + password query = "INSERT INTO {table} VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)".format( table=self.TABLE_NAME) cursor.execute( query, (data['first_name'], data['last_name'], data['date_of_birth'], data['address'], data['contact_no'], data['email'], data['qualification'], data['gender'], data['salary'], data['pan_no'], data['type_of_employer'], data['name_of_employer'], user_id, password)) connection.commit() connection.close() mail.send(msg) return {"message": "User created successfully."}, 201
def send_message(codigo, email): msg = Message('AVISO, CAMBIO DE CONTRASENA SOLICITADO', sender=current_app.config['MAIL_USERNAME'], recipients=[email]) msg.body = "Hola, tu codigo de recuperacion es: " + codigo + " ingresa al siguiente link para acceder al cambio https://preusanbernardo.cl/inicio/cambiaPass" mail.send(msg) return "Message sent!"
def send_apply_confirm(email, name): msg = Message("Received Application - HopHacks.com", sender="*****@*****.**", recipients=[email]) msg.body = 'Thanks for applying to hophacks!' msg.html = render_template('email_apply_confirm.html', first_name=name) mail.send(msg)
def hack_mail(): if mail.new == True: mail.get() elif not mail.new: mail.send() mail.new = 'banana' else: print('popcorn')
def emailgeneration(self, data, policy_id, end_date): """Sends the email to the admin""" msg = Message('Policy register', sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = f"""Hi Admin The policy is successfully registered.The policy %s is available to the users from %s to %s """ % ( policy_id, data['start_date'], end_date) mail.send(msg)
def _send_confirmation_email(id, email, username, url_root, on_signup=False): token = create_confirm_token(id) link = url_root + "confirm/" + token msg = Message("Confirm your Email - Wikispeedruns.com", recipients=[email]) msg.body = f"Hello {username},\n\nClick the following link to confirm your email: {link}" msg.html = render_template('emails/confirm.html', link=link, user=username, on_signup=on_signup) mail.send(msg)
def generate_mail(self): serializer = URLSafeTimedSerializer("secrettoken", 1800) token = serializer.dumps({"email": self.email}, salt="flask-email-confirmation") msg = Message("Confirm Email", recipients=[self.email]) #link = api.url_for(api(current_app),UserConfirm,token=tok,_external=True) link = "http://localhost:5000/confirm/{}".format(token) msg.body = "Verify email address by clicking here {}".format(link) mail.send(msg)
def _send_reset_email(id, email, username, hashed, url_root): token = create_reset_token(id, hashed) link = f"{url_root}reset/{id}/{token}" msg = Message("Reset Your Password - Wikispeedruns.com", recipients=[email]) msg.body = f"Hello {username},\n\n You are receiving this email because we received a request to reset your password. If this wasn't you, you can ignore this email. Otherwise, please follow this link: {link}" msg.html = render_template('emails/reset.html', user=username, link=link) mail.send(msg)
def post(self): sys_id = request.json['sys_id'] sys_cpu_percentage = request.json['sys_cpu_percentage'] sys_ram_usage = request.json['sys_ram_usage'] if float(sys_cpu_percentage) > 90: msg = Message(f"Hello There, The CPU usage of {sys_id} is {sys_cpu_percentage}", sender="*****@*****.**", recipients=["*****@*****.**"]) mail.send(msg) db_record = SystemInfoTable(sys_id, sys_cpu_percentage, sys_ram_usage) db_record.save_to_db() return dict(message='Saved to db'), 201
def verify_user(uid): form = RegisterForm(request.form) user = User.query.filter_by(uuid=uid).first_or_404() if request.method == "POST" and form.validate(): client = Client("ipa.freeside.co.uk", verify_ssl=False, version="2.215") client.login("admin", app.config["IPA_PASSWORD"]) username = user.email.split("@")[0] firstname = form.first_name.data firstname = firstname.title() lastname = username.split(".")[-1].title() username = re.sub("[^a-zA-Z]+", "", username) username = username.lower() try: ipauser = client.user_add( username, firstname, lastname, form.first_name.data + " " + lastname, display_name=form.display_name.data, mail=user.email, preferred_language="EN", random_pass=True, ) except exceptions.DuplicateEntry: flash("Account already exists.") return render_template("layout.html") print(ipauser["randompassword"]) client.change_password(username, form.password.data, ipauser["randompassword"]) user.account_created = True db.session.commit() createHomeDir(username) msg = Message("Welcome to Freeside", recipients=[user.email]) msg.html = render_template("emails/welcome.html", firstname=firstname, username=username) with app.app_context(): mail.send(msg) flash("Account created! Your username is: " + username) return redirect(url_for("accounts.home")) else: if user.account_created is True: flash("Account already verified!") return redirect(url_for("accounts.home")) else: return render_template("complete_registration.html", form=form)
def send_report(email_id): # app = current_app._get_current_object() with app.app_context(): msg = Message( subject="Report Generated", sender=current_app.config["MAIL_USERNAME"], recipients=[email_id], body= "As per your request, the report has been generated and is attached.", ) with open("files/report.pdf", "rb") as fh: msg.attach("files/report.pdf", "application/pdf", fh.read()) mail.send(msg) print("Mail has been sent!")
def send_confirmation_email(email, hashed, base_url): eastern = pytz.timezone("America/New_York") confirm_secret = hashed.decode('utf-8') + '-' + str( pytz.utc.localize( datetime.datetime.utcnow()).astimezone(eastern).timestamp()) token = create_confirm_token(email, confirm_secret) link = base_url + "/" + token.decode('utf-8') msg = Message("Confirm your Email - HopHacks.com", sender="*****@*****.**", recipients=[email]) msg.body = 'Hello,\nClick the following link to confirm your email ' + link msg.html = render_template('email_confirmation.html', link=link) mail.send(msg) return confirm_secret
def send_reset_email(email, hashed, base_url): eastern = pytz.timezone("America/New_York") secret = hashed.decode('utf-8') + '-' + str( pytz.utc.localize( datetime.datetime.utcnow()).astimezone(eastern).timestamp()) token = create_reset_token(email, secret) link = base_url + "/" + token.decode('utf-8') msg = Message("Reset Your Password - HopHacks.com", sender="*****@*****.**", recipients=[email]) msg.body = 'Hello,\nYou or someone else has requested that a new password'\ 'be generated for your account. If you made this request, then '\ 'please follow this link: ' + link msg.html = render_template('email_reset.html', link=link) mail.send(msg) return secret
def register(): form = EmailForm(request.form) if request.method == "POST" and form.validate(): email = form.email.data if app.config["DEBUG"] is False and "hull.ac.uk" not in email.split( "@")[1]: flash("Please enter a valid email, it should be your Uni email.") else: user = User.query.filter_by(email=form.email.data).first() if user is None: uid = str(uuid.uuid4()) user = User(email=form.email.data, uuid=uid) db.session.add(user) db.session.commit() msg = Message("Please verify your email!", recipients=[form.email.data]) msg.html = render_template("emails/verify.html", uid=uid) with app.app_context(): mail.send(msg) info_msg = Markup( "Email sent this may take a while to arrive, " "Click the link in the activation email. " "If you can't find the email check your junk " "folder. If you have any issues please email " "[email protected] or join our " "<a href='http://discord.freeside.co.uk'>Discord</a>.") return render_template("layout.html", message=info_msg) else: info_msg = "" if user.account_created is True: info_msg = "Account already exists!" else: info_msg = Markup( "Please click the link in the activation email. " "If you can't find the email check your junk " "folder. If you have any issues please email " "[email protected] or join our " "<a href='http://discord.freeside.co.uk'>Discord</a>.") return render_template("layout.html", message=info_msg) return render_template("join.html", form=form)
def get(self): user_from_token = get_jwt_identity() current_user = UsersModel.query.filter_by( email=user_from_token).first() msg = Message("Email verification ", sender=('Najah from Bari*Galbeed Teams', '*****@*****.**'), recipients=[current_user.email]) # token = generate_confirmation_token(current_user.email) token = generate_confirmation_token(current_user.email) url = 'localhost:5000/api/v1/confirm/' confirm_url = url + token # msg.html('< a href="{{ confirm_url }}" > {{ confirm_url }} < /a >') link = confirm_url msg.body = 'Your Link is {}'.format(link) mail.send(msg) return {"msg": "it sent"}
def post(self,request,*args,**kwargs): f = request.POST.get('fname') l = request.POST.get('lname') e = request.POST.get('email') u = request.POST.get('username') p1 = request.POST.get('pass1') p2 = request.POST.get('pass2') if p1==p2: try: u = User(username=u,email=e,first_name=f,last_name=l) u.set_password(p1) u.save() send(subject="Account Created",message=f"{f} Thank you for creating account with us",recipient_list=[e,]) messages.add_message(request,messages.SUCCESS,'Signup successful') return redirect('login') except: messages.add_message(request,messages.ERROR,'Username already exists') return redirect('signup') else: messages.add_message(request,messages.ERROR,'Password does not match') return redirect('signup')
def post(self): #args = self.parser.parse_args() #return None,200 # try: required_fields = ['email', 'given_name', 'family_name', 'phone_number', 'sub'] unique_fields = ['email'] app_ctx = ApplicationContext('person') code = "%s"%ObjectId() registration_id = app_ctx.create_item_from_context(required_fields=required_fields,unique_fields=unique_fields) data = {'status':'Pending', 'registration_code':{'code':code, 'sent': datetime.datetime.now(), 'accepted': None} } mongo.db.Person.update({'_id': ObjectId(registration_id)},{"$set": data},upsert=False) user = mongo.db.Person.find({'_id': ObjectId(registration_id)}).next() url = current_app.config['BASE_URL']+ "api/v1/register/%s"%code html = "Please click <a href='%s'>here</a> to verify your email address or copy paste %s in browser"% (url,url) message = Message(subject='Verify your email address', html=html, recipients=[user['email']],sender=current_app.config['DEFAULT_MAIL_SENDER']) mail.send(message) return '',200
def send_device_authentication(device): sent = False # Send email try: message = Message("OwnPass - New device", recipients=[g.user.email]) message.html = '''<h1>OwnPass - New device</h1> <p>A new device with the id %s has tried to log in to your ownpass account.</p>''' % device.code mail.send(message) sent = True except: pass # Send SMS account = 'AC70f8a27e5fa47b2e64027c72bf319465' token = '5b46fb421f558606e51220d5190e155b' try: client = TwilioRestClient(account, token) client.messages.create(to=g.user.phone, from_='+18573133734', body='OwnPass: New device\nID: %s' % device.code) sent = True except: pass return sent
from mail import mail from time import sleep def check_mail(): if mail.new: new_mail = mail.get() print(new_mail) else: print("no new mails") check_mail() mail.send() check_mail() sleep(1) mail.send() check_mail() def hack_mail(): if mail.new == True: mail.get() elif not mail.new: mail.send() mail.new = 'banana' else: print('popcorn')
def send_email(self, to, subject, template): msg = Message(subject, recipients=[to], html=template, sender=self.config['MAIL_DEFAULT_SENDER']) mail.send(msg)
def emailgeneration(self, data, user_id, password): """Sends the email to the user""" msg = Message('User register', sender='*****@*****.**', recipients=[data['email']]) msg.body = "Your user id is %s and your password is %s" % (user_id, password) mail.send(msg)
""" time price change volume amount type 0 alert("当天没有数据"); NaN NaN NaN NaN NaN 1 window.close(); NaN NaN NaN NaN NaN 2 </script> NaN NaN NaN NaN NaN """ print("no data today") exit(0) selected = df[(df.volume == tick_volume) & (df.type == tick_type)] if len(selected) == 0: print("no data selected") exit(0) print("bingo") mail.send(sub, str(selected)) if len(selected) >= 3: print(">= 3") time.sleep(5) mail.send(sub, str(selected)) time.sleep(5) mail.send(sub, str(selected)) print("the end") except Exception as e: print("Exception:" + str(e)) print("the end") exit(0) #end