def post(self): form = auth_forms.SignupForm(request.form) message = None registered = False if form.validate(): password, salt = auth_utils.encode_password(form.password.data) current_user = auth_models.WTUser.all().filter('email', form.email.data).count() if not current_user: new_user = auth_models.WTUser(username=form.username.data, email=form.email.data, password=password, salt=salt) new_user.save() if new_user: registered = True subject = "Welcome to Web Tournaments" body = mail.generate_email_body("email/auth/registration_email.txt", username=new_user.username) mail.send_email(new_user.email, subject, body) flask_login.login_user(new_user) if current_user: message = "Whoops! An account has already been registered with that email." if form.errors: message = form.errors response = json.dumps({'registered': registered, 'error_message': message}) return response
def post(self): form = auth_forms.SignupForm(request.form) message = None registered = False if form.validate(): password, salt = auth_utils.encode_password(form.password.data) current_user = auth_models.WTUser.all().filter('email', form.email.data).count() if not current_user: new_user = auth_models.WTUser(email=form.email.data, password=password, salt=salt) new_user.save() if new_user: registered = True subject = "Welcome to BoxTrackr" body = mail.generate_email_body("email/auth/registration_email.html") mail.send_email(new_user.email, subject, body) flask_login.login_user(new_user) if current_user: message = "current_user" if form.errors: message = form.errors response = json.dumps({'registered': registered, 'error_message': message}) return response
def receive(self, mail_message): logging.debug("Received a message from: %s" % mail_message.sender) #TODO: Perhaps we could build a database of email addresses for common package senders #TODO: and then we could auto detect who the package is from. (Amazon, Newegg, etc) #TODO: Heck, for common ones, we could even try to parse even more info. Things like #TODO: what was in the package and whatnot. from_name, from_addr = parseaddr(mail_message.sender) if not from_addr: logging.debug("No from address found. Aborting.") return user = auth_models.WTUser.get_user_by_email(from_addr) new_user = None if not user: logging.debug("No user found for %s. Creating new account." % from_addr) new_user = auth_models.WTUser.create_placeholder_user(email=from_addr, name=from_name) if new_user: logging.debug("New placeholder user created for %s" % from_addr) user = new_user if not user: logging.debug("Whoops. User needed to go forward. Something went wrong.") raise Exception("Email parsing - Missing user entity.") for content_type, body in mail_message.bodies('text/plain'): message_body = body.decode() logging.info(message_body) tracking_nums = mail_utils.check_message_for_tracking_number(message_body) for tracking_num in tracking_nums: logging.info("Tracking number found: %s" % tracking_num) if not tracking_nums: subject = "BoxTrackr - No Tracking Number Found" missing_body = self.render_email('email/responses/missing_tracking_num.html') base_mail.send_email(from_addr, subject, missing_body) logging.debug("No tracking number found.") return if tracking_nums: #TODO: Add more info to the email response. subject = "BoxTrackr - Tracking Number Found" body = self.render_email('email/responses/found_tracking_num.html', nums=tracking_nums) base_mail.send_email(from_addr, subject, body) for tracking_num in tracking_nums: data = { 'tracking_number': tracking_num, 'site': from_name, 'new_user': True if new_user else False } shipping_actions.create_package(data, user) return
def send_reset_email(server, user): token = generate_signed_token(user.email) link = '%s/auth/reset_password?token=%s' % (server, token) body = base_mail.generate_email_body('email/auth/reset_email.html', {'username': '******', 'reset_link': link}) base_mail.send_email(user.email, "BoxTrackr Password Reset", body) return True