public List <LoguearUsuario> Validar_Usuario(LoguearUsuario usuario) { using (SqlConnection cn = new SqlConnection(ConexionDAO.cnx)) { using (SqlCommand cmd = new SqlCommand("LoguearUsuario", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", usuario.UserName); cmd.Parameters.AddWithValue("@Password", usuario.Password); cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { List <LoguearUsuario> Logueo = new List <LoguearUsuario>(); while (dr.Read()) { LoguearUsuario _usuario = new LoguearUsuario(); _usuario.IdUsuario = Convert.ToString(dr["ID"]); _usuario.Tipo = Convert.ToString(dr["Name"] == DBNull.Value ? "" : dr["Name"]); _usuario.NombreUsuario = Convert.ToString(dr["UserName"]); Logueo.Add(_usuario); } return(Logueo); } } } }
protected void btnRegistrar_Click(object sender, EventArgs e) { using (UserSeguridad_DAO db = new UserSeguridad_DAO()) { try { if (chkAcepto.Checked == false) { string jss2 = "openModal()"; txtmensaje.Text = "Debe activar la aceptación de terminos y condiciones"; ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss2, true); return; } if (txtCorreoElectronico.Text != txtCorreoElectronicoConfirmar.Text) { txtmensaje.Text = "Verifique el correo electronico, no coinciden"; string jss10 = "openModal()"; ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss10, true); return; } //if (txtcontraseña.Text != txtconfirmar.Text) //{ // //lblError.Text = "Las contraseñas proporcionadas no coinciden"; // //ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "message();", true); // txtmensaje.Text = "Las contraseñas proporcionadas no coinciden"; // string jss10 = "openModal()"; // ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss10, true); // return; //} Captcha1.ValidateCaptcha(txtCaptcha.Text.ToUpper());//Validando - CAPTCHA********************//**//*** if (Captcha1.UserValidated) { Captcha1.Visible = true; Users oUser = new Users(); oUser.Id = GetUniqueKey(128); oUser.ApellidoPaterno = txtapepaterno.Text; oUser.ApellidoMaterno = txtapematerno.Text; oUser.Nombre = txtnombres.Text; oUser.Email = txtCorreoElectronico.Text; oUser.UserName = txtCorreoElectronico.Text; oUser.CustomPasswordHash = txtcontraseña.Text; oUser.PasswordHash = txtcontraseña.Text; oUser.EmailConfirmed = false; //oUser.TipoDocumento = Convert.ToInt32(ddlTipoDoc.SelectedValue); //oUser.NumeroDocumento = txtnumerodoc.Text; oUser.PhoneNumberConfirmed = false; oUser.TwoFactorEnabled = false; oUser.LockoutEnabled = false; oUser.AccessFailedCount = 0; oUser.Discriminator = "ApplicationUser"; oUser.Password = txtcontraseña.Text; //txtconfirmar.Text; string iduser = db.Agregar(oUser); Session["usuAfiliacion"] = oUser.Email; EnviarMensajeEmail(oUser.Email, "Hermes Seguros - Confirmacion de Afiliacion", oUser.Id); //txtmensaje.Text = "Se ha enviado un correo de confirmación de usuario al correo electrónico registrado, por favor verifique e ingrese a través del LINK AFILIACIÓN WEB"; //string jss3 = "openModal()"; //ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss3, true); //ROLES string r = cUtil.ObtenerValorParametro("CLIENTE", "ROL"); UserRoles ur = new UserRoles(); ur.RoleId = r; ur.UserId = iduser; db.AgregarRol(ur); //-------------------------------------------------------------------------------------- Usuario_DAO objn = new Usuario_DAO(); LoguearUsuario obje = new LoguearUsuario(); obje.UserName = txtCorreoElectronico.Text; obje.Password = txtcontraseña.Text; List <LoguearUsuario> logueo = objn.Validar_Usuario(obje); if (logueo.Count > 0) { string RolId = logueo[0].IdUsuario; Session["Usuario"] = logueo[0].NombreUsuario; Session["Password"] = txtcontraseña.Text; Response.Redirect("afiliados.aspx?Tipo=" + RolId); } //-------------------------------------------------------------------------------------- //FINROLES } else { string jss2 = "openModal()"; txtmensaje.Text = "El texto de la imagen ingresado es incorrecto."; ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss2, true); return; } } catch (Exception ex) { txtmensaje.Text = ex.Message; string jss2 = "openModal()"; ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", jss2, true); } } }