From 558b38e51e0766ee28ab1e187c99c574938bf45f Mon Sep 17 00:00:00 2001 From: jnunez Date: Thu, 6 Sep 2018 21:40:49 +0000 Subject: [PATCH] git-tfs-id: [http://192.168.1.10:8080/tfs/AyA]$/SINORT;C455 --- .../AYA.SlnSynor.WCF/ISinortCatalogos.cs | 2 +- AYA.SlnSynor/AYA.SlnSynor.WCF/Sinort.svc.cs | 4 +- .../AYA.SlnSynor.WCF/SinortCatalogos.svc.cs | 21 ++++-- .../AYA.SlnSynor/Sinort-Scripts/Signup.js | 67 +++++++----------- .../Sinort/UsuarioExternoDAL.cs | 69 ++++--------------- .../Entidades/CatalogosJSON.cs | 1 + AYA.SlnSynor/Atesa.Utilitarios/Encriptar.cs | 48 ++++++++++++- 7 files changed, 104 insertions(+), 108 deletions(-) diff --git a/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs b/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs index 091e41a59..c17572fa1 100644 --- a/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs +++ b/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs @@ -83,7 +83,7 @@ namespace AYA.SlnSinort.WCF #region UsuarioExterno [OperationContract] - string VerificarUsuario(CatalogosPostJSON model); + CatalogosPostJSON VerificarUsuario(CatalogosPostJSON model); [OperationContract] UsuarioExterno BuscarEmail(CatalogosPostJSON model); diff --git a/AYA.SlnSynor/AYA.SlnSynor.WCF/Sinort.svc.cs b/AYA.SlnSynor/AYA.SlnSynor.WCF/Sinort.svc.cs index 05559eee8..c9d8c22f6 100644 --- a/AYA.SlnSynor/AYA.SlnSynor.WCF/Sinort.svc.cs +++ b/AYA.SlnSynor/AYA.SlnSynor.WCF/Sinort.svc.cs @@ -955,7 +955,7 @@ namespace AYA.SlnSinort.WCF PlantillaEmailDAL PlantillalDAL = new PlantillaEmailDAL(); PlantillaEmail plantilla = new PlantillaEmail(); List Listaplantillas = new List(); - + Encriptar encriptar = new Encriptar(); int respuesta = 0; string email; @@ -980,7 +980,7 @@ namespace AYA.SlnSinort.WCF body = plantilla.Body.Replace("$Nombre", model.UsuarioExterno.Nombre).Replace("$Apellido", model.UsuarioExterno.Apellido1) - .Replace("$Usuario", model.UsuarioExterno.Usuario).Replace("$Password", model.UsuarioExterno.Password).Replace("|", "
"); + .Replace("$Usuario", model.UsuarioExterno.Usuario).Replace("$Password",encriptar.desencriptaConstrasena(model.UsuarioExterno.Password)).Replace("|", "
"); correo.CUERPO = body; email = model.UsuarioExterno.Email; correo.DESTINATARIOS = email; diff --git a/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs b/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs index 92e2fa81d..d221d312f 100644 --- a/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs +++ b/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs @@ -294,7 +294,7 @@ namespace AYA.SlnSinort.WCF #endregion #region UsuarioExterno - public string VerificarUsuario(CatalogosPostJSON model) + public CatalogosPostJSON VerificarUsuario(CatalogosPostJSON model) { UsuarioDAL usuarioDal = null; Usuario respuesta = null; @@ -328,18 +328,31 @@ namespace AYA.SlnSinort.WCF repetido = false; } } + + if (model.codigo != null) + { + respuesta2 = new UsuarioExternoDAL().BuscarEmail(model.UsuarioExterno.Email); + } + if (respuesta2 == null) + { + model = new UsuarioExternoDAL().InsertarUsuarioExterno(model); + }else + { + model.CodigoRespuesta = EnumTipoCodigoRespuesta.ADVERTENCIA.ToString(); + model.DescripcionRespuesta = "El email digitado ya se encuentra registrado"; + } } catch (Exception ex) { log.Error(ex); } - return model.codigo; + return model; } public UsuarioExterno BuscarEmail(CatalogosPostJSON model) { UsuarioExterno respuesta = null; try { - respuesta = new UsuarioExternoDAL().BuscarEmail(model); + //respuesta = new UsuarioExternoDAL().BuscarEmail(model); } catch (Exception ex) @@ -353,7 +366,7 @@ namespace AYA.SlnSinort.WCF BaseJson respuesta = new BaseJson(); try { - respuesta = new UsuarioExternoDAL().InsertarUsuarioExterno(model); + //respuesta = new UsuarioExternoDAL().InsertarUsuarioExterno(model); } catch (Exception ex) { diff --git a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js index 481363836..b17596596 100644 --- a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js +++ b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js @@ -27,6 +27,7 @@ function validarFormulario() { var patron = /^[a-zñA-ZÑ\u00E0-\u00FC]+$/; var nombre; var apellido1; + var validacion = 'Los campos son obligatorios'; if ($('#txtNombre').val().length > 0) { nombre = document.getElementById("txtNombre").value; @@ -55,7 +56,8 @@ function validarFormulario() { Contador++; } else { - toastr.warning('El email no es valido', Message_Warning); + toastr.warning('El formato de email no es valido', Message_Warning); + return; } } if ($('#txtContrasena').val().length > 0) { @@ -88,7 +90,7 @@ function validarFormulario() { BuscarUsuario(model); } else { - toastr.warning('Los campos son obligatorios', Message_Warning); + toastr.warning(validacion, Message_Warning); } @@ -117,16 +119,7 @@ var normalize = (function () { })(); this.BuscarUsuario = function (model) { - var uri = SinorSignupWCF + '/api/VerificarUsuario'; - AjaxPostData(uri, model, false, true, NombreUsuario, null, null); -} -this.NombreUsuario = function (data) { - usuario = data; - LeerFormulario(); -} -this.LeerFormulario = function () { - - UsuarioExterno = { + model.UsuarioExterno = { Usuario: usuario, Password: $('#txtContrasena').val(), @@ -135,46 +128,32 @@ this.LeerFormulario = function () { Apellido2: $('#txtApellido2').val(), Email: $('#txtEmail').val() } - model = { - codigo: UsuarioExterno.Email - } - - var uri = SinorSignupWCF + '/api/BuscarEmail'; - AjaxPostData(uri, model, false, false, RegistrarUsuario, null, null); + + var uri = SinorSignupWCF + '/api/VerificarUsuario'; + AjaxPostData(uri, model, false, true, EnviarCorreo, null, null); + + + url = $("#hiddenHref").val(); + url = url.replace("View", "LoginExterno"); + url = url.replace("Controller", "Login"); + + document.location.href = url; + } -this.RegistrarUsuario = function (data) { - if (data == null) { - var uri = SinorSignupWCF + '/api/InsertarUsuarioExterno'; - AjaxPostData(uri, UsuarioExterno, false, false, null, null, null); - - - EnviarCorreo(); - - url = $("#hiddenHref").val(); - url = url.replace("View", "LoginExterno"); - url = url.replace("Controller", "Login"); - - document.location.href = url; - } - else { - toastr.error('El email digitado ya se encuentra registrado', Message_Warning); - ENDREQUEST(); - } - -} -this.EnviarCorreo = function() -{ +this.EnviarCorreo = function (data) { var Plantilla = { NombrePlatilla: 'Correo Registro Externo', } - correo = { } + correo = {} correo.PlantillaEmail = Plantilla; - correo.UsuarioExterno = UsuarioExterno; + correo.UsuarioExterno = data.UsuarioExterno; var uri = SinorLoginWCF + '/api/EnviarCorreoAExterno'; - AjaxPostData(uri, correo, false, false, null, null, null); + AjaxPostData(uri, correo, false, true, null, null, null); ENDREQUEST(); -} \ No newline at end of file +} + + diff --git a/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs b/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs index 6416c4e8d..67a633a57 100644 --- a/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs +++ b/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs @@ -46,10 +46,10 @@ namespace AYA.SlnSinortModel.DAL.Sinort } #endregion - public UsuarioExterno BuscarEmail(CatalogosPostJSON model) + public UsuarioExterno BuscarEmail(string email) { UsuarioExterno usuario = new UsuarioExterno(); - string filtro = model != null ? model.filtro : null; + try { @@ -57,7 +57,7 @@ namespace AYA.SlnSinortModel.DAL.Sinort { - usuario = db.UsuarioExterno.Where(r => r.Email.ToString() == model.codigo).FirstOrDefault(); + usuario = db.UsuarioExterno.Where(r => r.Email.ToString() == email).FirstOrDefault(); } @@ -70,74 +70,35 @@ namespace AYA.SlnSinortModel.DAL.Sinort return usuario; } - public BaseJson InsertarUsuarioExterno(UsuarioExterno model) + public CatalogosPostJSON InsertarUsuarioExterno(CatalogosPostJSON model) { - BaseJson Respuesta = new BaseJson(); + Encriptar encriptar = new Encriptar(); try { using (SinortContex Conn = new SinortContex()) { - model.Password = encriptarContrasena(model.Password); - model.Estado = true; - model.FechaCreacion = DateTime.Now; - Conn.UsuarioExterno.Add(model); + model.UsuarioExterno.Password = encriptar.encriptarContrasena(model.UsuarioExterno.Password); + model.UsuarioExterno.Estado = true; + model.UsuarioExterno.FechaCreacion = DateTime.Now; + model.UsuarioExterno.Usuario = model.codigo; + Conn.UsuarioExterno.Add(model.UsuarioExterno); Conn.SaveChanges(); Conn.Commit(); - Respuesta.CodigoRespuesta = EnumTipoCodigoRespuesta.EXITOSO.ToString(); + model.CodigoRespuesta = EnumTipoCodigoRespuesta.EXITOSO.ToString(); } } catch (DbEntityValidationException ex) { log.Error(ex); - Respuesta.CodigoRespuesta = EnumTipoCodigoRespuesta.ERROR.ToString(); + model.CodigoRespuesta = EnumTipoCodigoRespuesta.ERROR.ToString(); } catch (Exception ex) { log.Error(ex); - Respuesta.CodigoRespuesta = EnumTipoCodigoRespuesta.ERROR.ToString(); + model.CodigoRespuesta = EnumTipoCodigoRespuesta.ERROR.ToString(); } - return Respuesta; - } - public static byte[] Clave = Encoding.ASCII.GetBytes("f7QkGjna2q2"); - public static byte[] IV = Encoding.ASCII.GetBytes("Devjoker7.37hAES"); - - public static String encriptarContrasena(String Cadena) - { - byte[] inputBytes = Encoding.ASCII.GetBytes(Cadena); - byte[] encripted; - RijndaelManaged cripto = new RijndaelManaged(); - using (MemoryStream ms = new MemoryStream(inputBytes.Length)) - { - using (CryptoStream objCryptoStream = new CryptoStream(ms, cripto.CreateEncryptor(Clave, IV), CryptoStreamMode.Write)) - { - objCryptoStream.Write(inputBytes, 0, inputBytes.Length); - objCryptoStream.FlushFinalBlock(); - objCryptoStream.Close(); - } - encripted = ms.ToArray(); - } - return Convert.ToBase64String(encripted); - - } - - public static String desencriptaConstrasena(string Cadena) - { - - byte[] inputBytes = Convert.FromBase64String(Cadena); - byte[] resultBytes = new byte[inputBytes.Length]; - string textoLimpio = String.Empty; - RijndaelManaged cripto = new RijndaelManaged(); - using (MemoryStream ms = new MemoryStream(inputBytes)) - { - using (CryptoStream objCryptoStream = new CryptoStream(ms, cripto.CreateDecryptor(Clave, IV), CryptoStreamMode.Read)) - { - using (StreamReader sr = new StreamReader(objCryptoStream, true)) - { - textoLimpio = sr.ReadToEnd(); - } - } - } - return textoLimpio; + return model; } + } } diff --git a/AYA.SlnSynor/AYA.SlnSynorModel/Entidades/CatalogosJSON.cs b/AYA.SlnSynor/AYA.SlnSynorModel/Entidades/CatalogosJSON.cs index 4e9d986f1..a6327e929 100644 --- a/AYA.SlnSynor/AYA.SlnSynorModel/Entidades/CatalogosJSON.cs +++ b/AYA.SlnSynor/AYA.SlnSynorModel/Entidades/CatalogosJSON.cs @@ -26,6 +26,7 @@ namespace AYA.SlnSinortModel.Entidades public int? IdTipo { get; set; } public int? IdPantalla { get; set; } public List pantallas { get; set; } + public UsuarioExterno UsuarioExterno { get; set; } } public class RolesPantallasJSON : BaseJson diff --git a/AYA.SlnSynor/Atesa.Utilitarios/Encriptar.cs b/AYA.SlnSynor/Atesa.Utilitarios/Encriptar.cs index 9410e889a..c079077e9 100644 --- a/AYA.SlnSynor/Atesa.Utilitarios/Encriptar.cs +++ b/AYA.SlnSynor/Atesa.Utilitarios/Encriptar.cs @@ -1,15 +1,57 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Atesa.Utilitarios { - class Encriptar + public class Encriptar { - - + + public static byte[] Clave = Encoding.ASCII.GetBytes("f7QkGjna2q2"); + public static byte[] IV = Encoding.ASCII.GetBytes("Devjoker7.37hAES"); + + public String encriptarContrasena(String Cadena) + { + byte[] inputBytes = Encoding.ASCII.GetBytes(Cadena); + byte[] encripted; + RijndaelManaged cripto = new RijndaelManaged(); + using (MemoryStream ms = new MemoryStream(inputBytes.Length)) + { + using (CryptoStream objCryptoStream = new CryptoStream(ms, cripto.CreateEncryptor(Clave, IV), CryptoStreamMode.Write)) + { + objCryptoStream.Write(inputBytes, 0, inputBytes.Length); + objCryptoStream.FlushFinalBlock(); + objCryptoStream.Close(); + } + encripted = ms.ToArray(); + } + return Convert.ToBase64String(encripted); + + } + + public String desencriptaConstrasena(string Cadena) + { + + byte[] inputBytes = Convert.FromBase64String(Cadena); + byte[] resultBytes = new byte[inputBytes.Length]; + string textoLimpio = String.Empty; + RijndaelManaged cripto = new RijndaelManaged(); + using (MemoryStream ms = new MemoryStream(inputBytes)) + { + using (CryptoStream objCryptoStream = new CryptoStream(ms, cripto.CreateDecryptor(Clave, IV), CryptoStreamMode.Read)) + { + using (StreamReader sr = new StreamReader(objCryptoStream, true)) + { + textoLimpio = sr.ReadToEnd(); + } + } + } + return textoLimpio; + } } }