def send_broadcast_messages(message_id): message = Message.query.get(message_id) email_users = User.query.filter( and_(User.is_active, User.prayer_requests_by_email)).all() for user in email_users: message_html = render_template('emails/new_message.html', user=user, message=message) send_bulk_mail([user.email], '*****@*****.**', message.subject, message_html=message_html) sms_users = User.query.filter( and_(User.is_active, User.prayer_requests_by_sms)).all() link = url_for('messages.view_messages', message_type=0, id=message_id, _external=True) for user in sms_users: message_text = render_template('sms/sms_message.txt', user=user, link=link) send_sms(user.mobile_phone, message_text)
def send_password_reset(login): user = get_user_by_login(login) reset_token = user.get_reset_token() sender = app.config['USER_EMAIL_SENDER_EMAIL'] app_name = app.config['USER_APP_NAME'] reset_link = url_for('users.reset_password', token=reset_token, _external=True) if is_valid_email(login): message_body = render_template('emails/password_reset_message.html', reset_link=reset_link, app_name=app_name) send_bulk_mail([login], sender, '{} password reset'.format(app_name), message_body) else: if app.config['DEBUG']: reset_link = "{}{}".format( app.config['NGROK'], url_for('users.reset_password', token=reset_token)) else: reset_link = url_for('users.reset_password', token=reset_token, _external=True) message_body = render_template('sms/password_reset_message.txt', reset_link=reset_link, app_name=app_name) send_sms(login, message_body)
def send_otp(): data = request.get_json() token = random.randint(100001, 999999) msg = '{} is one time password. Use this within 3 minutes'.format(token) msisdn = data['msisdn'] sms = utils.send_sms(msg, msisdn) print(sms) res = { 'status': -1, 'message': "Successfully sent the OTP", 'smsResultCode': sms['statusCode'] } if sms['statusCode'] in [100, 101, 102]: m1 = Sms(message=msg, msisdn=msisdn, message_id=sms['messageId'], status=1) now = datetime.datetime.now() expiry_date = now + datetime.timedelta(minutes=3) m2 = Token(token=token, owner_id=msisdn, status=0, expiry_date=expiry_date) db.session.add(m1) db.session.add(m2) db.session.commit() res['status'] = 0 res['message'] = "Successfully sent the OTP" return jsonify(res) else: return jsonify(res)
def post(self, request): ids = self.request.POST.get('ids') ids = ids.split(',') print(ids) title = self.request.POST.get('title') text = self.request.POST.get('text') if 'sms' in self.request.POST.get('action'): for id in ids: d = Doctor.objects.get(id=id) if d.phone: send_sms(d.phone, title + '\n' + text) if 'email' in self.request.POST.get('action'): for id in ids: d = Doctor.objects.get(id=id) if d.email: send_email(title, text, [d.email,]) return Response(status=201)
def send_invitation(log_in, is_phone_number, password, invited_user, current_user): token_manager = TokenManager(app) token = token_manager.generate_token(current_user.id, invited_user.id) sender = app.config['USER_EMAIL_SENDER_EMAIL'] app_name = app.config['USER_APP_NAME'] next_url = url_for('users.profile') accept_invitation_link = url_for('users.login', next=next_url, token=token, _external=True) accept_invitation_link = accept_invitation_link.replace( 'http://127.0.0.1:5000', app.config['NGROK']) home_link = url_for('main.home', _external=True) if not is_phone_number: message_html = render_template( 'emails/invite_user_message.html', invited_user=invited_user, password=password, user=current_user, accept_invitation_link=accept_invitation_link, home_link=home_link, app_name=app_name) send_bulk_mail([invited_user.email], sender, '{} invitation'.format(app_name), message_html=message_html) else: # accept_invitation_link = url_for('users.login', next=next_url, token=token, # _external=True) message_body = render_template( 'sms/invite_user_message.txt', invited_user=invited_user, password=password, user=current_user, accept_invitation_link=accept_invitation_link, app_name=app_name) send_sms(invited_user.mobile_phone, message_body)