def post(self): to = self.request.get("to") subject = self.request.get("subject") body = self.request.get("body") sender = self.request.get("sender") utils.send_email(to, subject, body, sender)
def post(self): """ validate contact form """ if not self.form.validate(): return self.get() remoteip = self.request.remote_addr user_agent = self.request.user_agent name = self.form.name.data.strip() email = self.form.email.data.lower() message = self.form.message.data.strip() try: subject = _("Contact") body = """ IP Address : %s Web Browser : %s Sender : %s <%s> %s """ % (remoteip, user_agent, name, email, message) utils.send_email(config.contact_recipient, subject, body) message = _('Message sent successfully.') self.add_message(message, 'success') return self.redirect_to('contact') except (AttributeError, KeyError), e: message = _('Error sending the message. Please try again later.') self.add_message(message, 'error') return self.redirect_to('contact')
def form_contact(): nombre_from = request.POST.get('id_nombre') email_from = request.POST.get('id_email') web_from = request.POST.get('id_web') asunto_from = request.POST.get('id_asunto') comment_from = request.POST.get('id_comentario') send_email( FROM_NAME="{} {}".format(nombre_from, web_from), FROM=email_from, TO=TO_EMAIL, SUB=asunto_from, MSG=comment_from) return {'status': True}
def post(self): """ Get fields from POST dict """ if not self.form.validate(): return self.get() current_password = self.form.current_password.data.strip() password = self.form.password.data.strip() try: user_info = models.User.get_by_id(long(self.user_id)) auth_id = "own:%s" % user_info.username # Password to SHA512 current_password = utils.encrypt(current_password, config.salt) try: user = models.User.get_by_auth_password(auth_id, current_password) # Password to SHA512 password = utils.encrypt(password, config.salt) user.password = security.generate_password_hash(password, length=12) user.put() # send email subject = config.app_name + " Account Password Changed" # load email's template template_val = { "app_name": config.app_name, "first_name": user.name, "username": user.username, "email": user.email, "reset_password_url": self.uri_for("password-reset", _full=True) } email_body_path = "emails/password_changed.txt" email_body = self.jinja2.render_template(email_body_path, **template_val) utils.send_email(user.email, subject, email_body) #Login User self.auth.get_user_by_password(user.auth_ids[0], password) self.add_message(_('Password changed successfully'), 'success') return self.redirect_to('secure') except (InvalidAuthIdError, InvalidPasswordError), e: # Returns error message to self.response.write in # the BaseHandler.dispatcher message = _("Your Current Password is wrong, please try again") self.add_message(message, 'error') return self.redirect_to('edit-password') except (AttributeError,TypeError), e: login_error_message = _('Sorry you are not logged in!') self.add_message(login_error_message,'error') self.redirect_to('login')
def verification_code(): data = request.get_json() if data.__contains__('email'): if query_user(data['email']) is False: return returns(4, {}, '账号已被注册!') else: session['code'] = random.randint(1000, 9999) try: send_email(data['email'], '验证码', '注册验证码为' + str(session['code'])) return returns(0, {'status': 'success'}, '成功') except smtplib.SMTPException: return returns(5, {}, '邮件发送错误!') else: return returns(6, {}, '缺少参数!')
def post(self): """ Get fields from POST dict """ new_email = self.request.POST.get('new_email').strip() password = self.request.POST.get('password').strip() if new_email == "" or password == "": message = 'Sorry, some fields are required.' self.add_message(message, 'error') return self.redirect_to('edit-email') if not utils.is_email_valid(new_email): message = 'Sorry, the email %s is not valid.' % new_email self.add_message(message, 'error') return self.redirect_to('edit-email') try: user_info = models.User.get_by_id(long(self.user_id)) auth_id = "own:%s" % user_info.username # Password to SHA512 password = utils.encrypt(password, config.salt) try: # authenticate user by its password user = models.User.get_by_auth_password(auth_id, password) # if the user change his/her email address if new_email != user.email: # check whether the new email has been used by another user aUser = models.User.get_by_email(new_email) if aUser is not None: message = "The email %s is already registered. Want to <a href='/login/'>login</a> or <a href='/password-reset/'>recover your password</a>?" % new_email self.add_message(message, "error") return self.redirect_to("edit-email") # send email subject = config.app_name + " Email Changed Notification" user_token = models.User.create_auth_token(self.user_id) confirmation_url = self.uri_for("email-changed-check", user_id = user_info.get_id(), encoded_email = utils.encode(new_email), token = user_token, _full = True) # load email's template template_val = { "app_name": config.app_name, "first_name": user.name, "username": user.username, "new_email": new_email, "confirmation_url": confirmation_url, "support_url": self.uri_for("contact", _full=True) } old_body_path = "emails/email_changed_notification_old.txt" old_body = self.jinja2.render_template(old_body_path, **template_val) new_body_path = "emails/email_changed_notification_new.txt" new_body = self.jinja2.render_template(new_body_path, **template_val) utils.send_email(user.email, subject, old_body) utils.send_email(new_email , subject, new_body) logging.error(user) # display successful message msg = "Please check your new email for confirmation. " msg += "Your email will be updated after confirmation. " self.add_message(msg, 'success') return self.redirect_to('secure') else: self.add_message("You didn't change your email", "warning") return self.redirect_to("edit-email") except (InvalidAuthIdError, InvalidPasswordError), e: # Returns error message to self.response.write in # the BaseHandler.dispatcher message = "Your password is wrong, please try again" self.add_message(message, 'error') return self.redirect_to('edit-email') except (AttributeError,TypeError), e: login_error_message = _('Sorry you are not logged in!') self.add_message(login_error_message,'error') self.redirect_to('login')
head = '''<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>中介爬虫统计</title> </head> <body> <p>中介爬虫爬取周期为三个月,本次抓取入库结果如下:</p> <table border="1"> <tr> <th>名称</th> <th>入库数量</th> </tr> ''' tail = '''</table> </body> </html>''' content_str_list = [] for i, item in enumerate(middleman_list): content_str_list.append('<tr>') content_str_list.append('<td>' + middleman_cn_list[i] + '</td>') content_str_list.append('<td>' + str(middleman_count_dict[item]) + '</td>') content_str_list.append('</tr>') content_str = '\n'.join(content_str_list) return head + content_str + tail if __name__ == "__main__": update_db() send_email(email_list_str, '中介爬虫结果统计', generate_email_str(), 'html')