protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { string constr = BIZUtilites.getConnection(); bool activo = false; string activationCode = !string.IsNullOrEmpty(Request.QueryString["ActivationCode"]) ? Request.QueryString["ActivationCode"] : Guid.Empty.ToString(); using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("DELETE FROM UserActivation WHERE ActivationCode = @ActivationCode")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ActivationCode", activationCode); cmd.Connection = con; con.Open(); int rowsAffected = cmd.ExecuteNonQuery(); con.Close(); if (rowsAffected == 1) { ltMessage.Text = "Felicitaciones! La activación de la cuenta se hizo satisfactoriamente. \r\nAhora ya podes iniciar sesión."; } else { ltMessage.Text = "No se pudo activar la cuenta. El código no es correcto. Escribinos a [email protected]"; } } } } if (activo) { BIZAspNetUsers.AspNetUsersUpdateEmailConfirmed(User.Identity.GetUserId()); } } }
private DataTable GetData(string query) { //string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; string conString = BIZUtilites.getConnection(); //string conString = @"workstation id=haylugardbnew.mssql.somee.com;packet size=4096;user id=sbiondini_SQLLogin_2;pwd=z9j9uo7kaq;data source=haylugardbnew.mssql.somee.com;persist security info=False;initial catalog=haylugardbnew"; SqlCommand cmd = new SqlCommand(query); using (SqlConnection con = new SqlConnection(conString)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); return(dt); } } } }
private void Send_Account_Activation_Link(string emailaddress, string userId) { try { string constr = BIZUtilites.getConnection(); string activationCode = Guid.NewGuid().ToString(); using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("INSERT INTO UserActivation VALUES(@UserId, @ActivationCode)")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@UserId", userId); cmd.Parameters.AddWithValue("@ActivationCode", activationCode); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); //Especificamos el correo desde el que se enviará el Email y el nombre de la persona que lo envía //mail.From = new MailAddress("*****@*****.**", "Info LO DE FITO", Encoding.UTF8); mail.From = new MailAddress("*****@*****.**", "Info Hay Lugar", Encoding.UTF8); //Aquí ponemos el asunto del correo mail.Subject = "Hay Lugar - Alta de usuario"; //Aquí ponemos el mensaje que incluirá el correo string body = string.Empty; string urlFinal = @"http://haylugar.somee.com/Account/CS_Activation.aspx?ActivationCode=" + activationCode; body += "<br /><br />Ingresa al siguiente enlace para activar tu cuenta:"; body += "<br /><br />"; body += "<br /><a href ='" + urlFinal + "'>ACTIVAR CUENTA</a>"; body += "<br /><br />"; using (StreamReader reader = new StreamReader(Server.MapPath("~/Uploads/EmailTemplate.htm"))) { body += reader.ReadToEnd(); } string url = "www.haylugar.somee.com"; body = body.Replace("{UserName}", txtMail.Text); body = body.Replace("{UserPass}", txtNroDocumento.Text); body = body.Replace("{Url}", url); body = body.Replace("{activationCode}", activationCode); mail.Body = body; mail.IsBodyHtml = true; //Especificamos a quien enviaremos el Email, no es necesario que sea Gmail, puede ser cualquier otro proveedor mail.To.Add(emailaddress); //Si queremos enviar archivos adjuntos tenemos que especificar la ruta en donde se encuentran //mail.Attachments.Add(new Attachment(@"C:\Documentos\carta.docx")); //Configuracion del SMTP SmtpServer.Port = 25; //Puerto que utiliza Gmail para sus servicios 587 //Especificamos las credenciales con las que enviaremos el mail SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "sandra2017"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception ex) { //String err = //lblErrorMail.Text = ex.Message; } }