Explorar el Código

allow remote reset

David hace 9 años
padre
commit
abb928c524
Se han modificado 2 ficheros con 35 adiciones y 28 borrados
  1. 24 27
      back/mail.py
  2. 11 1
      back/web.py

+ 24 - 27
back/mail.py

@@ -6,6 +6,10 @@ import sys
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
 
+DB = "EBA_STOCK"
+USER = "root"
+PASSWORD = "howdoiturnthison"
+
 
 def sendmail(target, message, subject):
 	noreply = 'consultas@especificosba.com.ar'
@@ -41,31 +45,24 @@ def populate(tpl, data):
 	
 	return out
 
-_id = 1
-_id = 163
-
-DB = "EBA_STOCK"
-USER = "root"
-PASSWORD = "howdoiturnthison"
-
-conn = pymysql.connect(unix_socket='/var/run/mysqld/mysqld.sock', user=USER, passwd=PASSWORD, db=DB,cursorclass=pymysql.cursors.DictCursor)
-# print("pls no")
-# sys.exit(1)
-cur = conn.cursor()
-# cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where id=%s and mail like '%%@%%'", (_id,))
-# cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and mail like '%%@%%'")
-cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and mail like '%%pouso%%'")
-clientes = cur.fetchall()
-for cliente in clientes:
-	print(cliente)
-	DATA = { }
-	DATA["HASH"] = cliente["hash"]
-	target = cliente["mail"]
-	#target = "mpetrigliano@leticiapepe.com.ar"
-	message = open("mailtemplate.html").read()
-	subject = "Link pedidos ESPECIFICOS Buenos Aires"
-	# print(populate(message, DATA)) 
-	sendmail(target, populate(message, DATA), subject)
-	# sendmail("davidventura27@gmail.com", populate(message, DATA), subject)
-	# sendmail("especificosba@gmail.com", populate(message, DATA), subject)
+def reset(identity):
+	conn = pymysql.connect(unix_socket='/var/run/mysqld/mysqld.sock', user=USER, passwd=PASSWORD, db=DB,cursorclass=pymysql.cursors.DictCursor)
+	cur = conn.cursor()
+	if '@' in identity:
+		cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and mail = %s", identity)
+	else:  # hash
+		cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and hash = %s", identity)
+	clientes = cur.fetchall()
+	for cliente in clientes:
+		DATA = { }
+		DATA["HASH"] = cliente["hash"]
+		target = cliente["mail"]
+		message = open("/var/www/pedido/back/mailtemplate.html").read()
+		subject = "Link pedidos ESPECIFICOS Buenos Aires"
+		sendmail(target, populate(message, DATA), subject)
 
+if __name__ == '__main__':
+	if len(sys.argv) != 2:
+		print('usage %s mail' % sys.argv[0])
+		sys.exit(1)
+	reset(sys.argv[1])

+ 11 - 1
back/web.py

@@ -3,6 +3,7 @@ import json
 import urllib
 import datetime
 import os
+import mail
 
 from db import db
 from flask import Flask, jsonify, request, send_file
@@ -64,7 +65,7 @@ def confirm(_hash, pedidoid):
 @app.route(BASE_PATH + '/image/<_hash>')
 def image(_hash):
 	filename = '/var/www/pedido/back/images/%s.png' % _hash
-	if not os.path.isfile(filename) or True:
+	if not os.path.isfile(filename):
 		c=d.client(_hash)
 		draw = Drawing()
 		with Image(width=300,height=150,background=Color('#2A3A49')) as img:
@@ -82,5 +83,14 @@ def image(_hash):
 			img.save(filename=filename)
 	return send_file(filename, mimetype='image/png')
 
+@app.route(BASE_PATH + '/reset/<_hash>')
+def reset(_hash):
+	r = mail.reset(_hash)
+	if r:
+		return "{}"
+	else:
+		return "{}", 400
+
+
 if __name__ == '__main__':
 	app.run(host="0.0.0.0",port=PORT, debug=True)