From 4588165cb6296b659e9d3b06a6decbf0be6d8146 Mon Sep 17 00:00:00 2001 From: jmoya Date: Thu, 6 Sep 2018 17:42:52 +0000 Subject: [PATCH] Registro Usuario Externo git-tfs-id: [http://192.168.1.10:8080/tfs/AyA]$/SINORT;C452 --- .../AYA.SlnSynor.WCF/ISinortCatalogos.cs | 8 ++ .../AYA.SlnSynor.WCF/SinortCatalogos.svc.cs | 60 ++++++++++++++- .../AYA.SlnSynor/Sinort-Scripts/Signup.js | 35 ++++++++- .../Sinort/UsuarioExternoDAL.cs | 73 +++++++++++++++++++ 4 files changed, 172 insertions(+), 4 deletions(-) diff --git a/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs b/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs index 6ab6039ba..013440935 100644 --- a/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs +++ b/AYA.SlnSynor/AYA.SlnSynor.WCF/ISinortCatalogos.cs @@ -81,6 +81,14 @@ namespace AYA.SlnSinort.WCF List ObtenerUsuario(); #endregion + #region UsuarioExterno + [OperationContract] + string VerificarUsuario(CatalogosPostJSON model); + + [OperationContract] + BaseJson InsertarUsuarioExterno(UsuarioExterno model); + #endregion + #region RolesUsuario [OperationContract] List ValidarRolesUsuario(CatalogosPostJSON model); diff --git a/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs b/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs index dac1477e2..91ee090ee 100644 --- a/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs +++ b/AYA.SlnSynor/AYA.SlnSynor.WCF/SinortCatalogos.svc.cs @@ -293,6 +293,65 @@ namespace AYA.SlnSinort.WCF } #endregion + #region UsuarioExterno + public string VerificarUsuario(CatalogosPostJSON model) + { + UsuarioDAL usuarioDal = null; + Usuario respuesta = null; + UsuarioExternoDAL usuarioExternoDal = null; + UsuarioExterno respuesta2 = null; + bool repetido = true; + int indice = 0; + string nombre = model.codigo; + try + { + usuarioDal = new UsuarioDAL(); + usuarioExternoDal = new UsuarioExternoDAL(); + model.codigo = model.codigo[0] + model.filtro; + while (repetido) + { + respuesta = usuarioDal.BuscarUsuario(model); + if (respuesta != null) + { + indice++; + model.codigo = nombre.Substring(0, indice) + model.filtro; + } + else + { + respuesta2 = usuarioExternoDal.BuscarUsuario(model); + if (respuesta2 != null) + { + indice++; + model.codigo = nombre.Substring(0, indice) + model.filtro; + } + else + repetido = false; + } + } + } + catch (Exception ex) + { + log.Error(ex); + } + return model.codigo; + } + public BaseJson InsertarUsuarioExterno(UsuarioExterno model) + { + BaseJson respuesta = new BaseJson(); + try + { + respuesta = new UsuarioExternoDAL().InsertarUsuarioExterno(model); + } + catch (Exception ex) + { + + log.Error(ex); + } + return respuesta; + } + + #endregion + #region Estado public List ObtenerEstado() { @@ -360,7 +419,6 @@ namespace AYA.SlnSinort.WCF } return respuesta; } - public List ObtenerUsuariosRol(CatalogosPostJSON model) { List respuesta = null; diff --git a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js index afda0e96a..f60a4194d 100644 --- a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js +++ b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Signup.js @@ -1,5 +1,6 @@ var model = {}; var usuario; +var UsuarioExterno = {}; jQuery(document).ready(function () { @@ -116,7 +117,35 @@ var normalize = (function () { })(); this.BuscarUsuario = function (model) { - - var uri = SinorSignupWCF + '/api/BuscarUsuario'; - AjaxPostData(uri, model, false, false, null, null, null); + var uri = SinorSignupWCF + '/api/VerificarUsuario'; + AjaxPostData(uri, model, false, true, NombreUsuario, null, null); +} +this.NombreUsuario = function (data) { + usuario = data; + LeerFormulario(); + RegistrarUsuario(); +} +this.LeerFormulario = function () { + + UsuarioExterno = { + + Usuario: usuario, + Password: $('#txtContrasena').val(), + Nombre: $('#txtNombre').val(), + Apellido1: $('#txtApellido1').val(), + Apellido2: $('#txtApellido2').val(), + Email: $('#txtEmail').val() + } +} +this.RegistrarUsuario = function () { + + var uri = SinorSignupWCF + '/api/InsertarUsuarioExterno'; + AjaxPostData(uri, UsuarioExterno, true, false, null, null, null); + + url = $("#hiddenHref").val(); + url = url.replace("View", "LoginExterno"); + url = url.replace("Controller", "Login"); + + document.location.href = url; + } \ 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 928db32ff..273bccd1e 100644 --- a/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs +++ b/AYA.SlnSynor/AYA.SlnSynorModel.DAL/Sinort/UsuarioExternoDAL.cs @@ -10,6 +10,8 @@ using System.Threading.Tasks; using System.Data.Entity; using System.Data.Entity.Validation; using AYA.SlnSinortModel.Constantes; +using System.Security.Cryptography; +using System.IO; namespace AYA.SlnSinortModel.DAL.Sinort { @@ -42,6 +44,77 @@ namespace AYA.SlnSinortModel.DAL.Sinort return usuario; } + #endregion + + public BaseJson InsertarUsuarioExterno(UsuarioExterno model) + { + BaseJson Respuesta = new BaseJson(); + try + { + using (SinortContex Conn = new SinortContex()) + { + model.Password = encriptarContrasena(model.Password); + model.Estado = true; + model.FechaCreacion = DateTime.Now; + Conn.UsuarioExterno.Add(model); + Conn.SaveChanges(); + Conn.Commit(); + Respuesta.CodigoRespuesta = EnumTipoCodigoRespuesta.EXITOSO.ToString(); + } + } + catch (DbEntityValidationException ex) + { + log.Error(ex); + Respuesta.CodigoRespuesta = EnumTipoCodigoRespuesta.ERROR.ToString(); + } + catch (Exception ex) + { + log.Error(ex); + Respuesta.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; + } } }