Registro Usuario Externo
git-tfs-id: [http://192.168.1.10:8080/tfs/AyA]$/SINORT;C452
This commit is contained in:
parent
f5b3917ef1
commit
4588165cb6
4 changed files with 172 additions and 4 deletions
|
|
@ -81,6 +81,14 @@ namespace AYA.SlnSinort.WCF
|
|||
List<Usuario> ObtenerUsuario();
|
||||
#endregion
|
||||
|
||||
#region UsuarioExterno
|
||||
[OperationContract]
|
||||
string VerificarUsuario(CatalogosPostJSON model);
|
||||
|
||||
[OperationContract]
|
||||
BaseJson InsertarUsuarioExterno(UsuarioExterno model);
|
||||
#endregion
|
||||
|
||||
#region RolesUsuario
|
||||
[OperationContract]
|
||||
List<RolesUsuario> ValidarRolesUsuario(CatalogosPostJSON model);
|
||||
|
|
|
|||
|
|
@ -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<Estado> ObtenerEstado()
|
||||
{
|
||||
|
|
@ -360,7 +419,6 @@ namespace AYA.SlnSinort.WCF
|
|||
}
|
||||
return respuesta;
|
||||
}
|
||||
|
||||
public List<RolesUsuario> ObtenerUsuariosRol(CatalogosPostJSON model)
|
||||
{
|
||||
List<RolesUsuario> respuesta = null;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue