Bladeren bron

allow resetting link

David 9 jaren geleden
bovenliggende
commit
048899dce2
3 gewijzigde bestanden met toevoegingen van 28 en 12 verwijderingen
  1. 14 8
      back/mail.py
  2. 12 2
      controllers/errorCtrl.js
  3. 2 2
      views/error.html

+ 14 - 8
back/mail.py

@@ -28,10 +28,13 @@ def sendmail(target, message, subject):
 	s.login(noreply, noreplypass)
 	s.login(noreply, noreplypass)
 	try:
 	try:
 		s.sendmail(noreply, target, msg.as_string())
 		s.sendmail(noreply, target, msg.as_string())
+		ok = True
 	except Exception:
 	except Exception:
+		ok = False
 		print("Error al enviar la consulta")
 		print("Error al enviar la consulta")
 	finally:
 	finally:
 		s.quit()
 		s.quit()
+		return ok
 
 
 def populate(tpl, data):
 def populate(tpl, data):
 	out = ""
 	out = ""
@@ -52,14 +55,17 @@ def reset(identity):
 		cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and mail = %s", identity)
 		cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and mail = %s", identity)
 	else:  # hash
 	else:  # hash
 		cur.execute("SELECT nombre,apellido,mail,hash FROM clientes where tipo=1 and hash = %s", identity)
 		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)
+
+	cliente = cur.fetchone()
+	if cliente is None:
+		return False
+
+	DATA = {}
+	DATA["HASH"] = cliente["hash"]
+	target = cliente["mail"]
+	message = open("/var/www/pedido/back/mailtemplate.html").read()
+	subject = "Link pedidos ESPECIFICOS Buenos Aires"
+	return sendmail(target, populate(message, DATA), subject)
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
 	if len(sys.argv) != 2:
 	if len(sys.argv) != 2:

+ 12 - 2
controllers/errorCtrl.js

@@ -1,4 +1,14 @@
-app.controller('errorCtrl', function ($scope, $http) {
-	$scope.email="asd";
+app.controller('errorCtrl', function ($scope, $http, notify) {
+	$scope.email="";
+	$scope.reset = function(email) {
+		$http.get("https://pedido.especificosba.com.ar/back/reset/" + email).then(
+		function(data) {
+			notify("Reiniciado correctamente");
+		},
+		function(err) {
+			notify({classes:"alert alert-danger", message:"error"});
+		});
+	}
+
 });
 });
 
 

+ 2 - 2
views/error.html

@@ -5,8 +5,8 @@
 
 
 	<div class="form-group">
 	<div class="form-group">
 		<h4 class="error-info">Para recuperar su ID, por favor, ingrese su email</h4>
 		<h4 class="error-info">Para recuperar su ID, por favor, ingrese su email</h4>
-		<input type="text" ng-model="mail" class="form-control" placeholder="Ingrese su email"/>
+		<input type="text" ng-model="email" class="form-control" placeholder="Ingrese su email"/>
 	</div>
 	</div>
 
 
-	<button class="btn btn-default btn-eba">Recuperar link</button>
+	<button class="btn btn-default btn-eba" ng-click="reset(email)">Recuperar link</button>
 </div>
 </div>