private void EnviarMensajeUsuario(string EmailUsuario) { string validationCode = new Random().Next().ToString(); //1.-Destino del mensaje System.Net.Mail.MailAddressCollection MisDestinos = new System.Net.Mail.MailAddressCollection(); MisDestinos.Add(new System.Net.Mail.MailAddress(EmailUsuario)); //2.-Cuerpo del mensaje HttpServerUtility server = HttpContext.Current.Server; string sMensaje = "We have sucessfully received your registration request to DropKeys. To complete the subscription process, please click the following link :\r\n\r\n " + Request.Url.GetLeftPart(UriPartial.Authority) + "/validatecode.aspx?email=" + server.UrlEncode(EmailUsuario) + "&vc=" + validationCode + "\r\n\r\nThank you."; if (EmailUtils.SendMessageEmail(MisDestinos, "Verify your email", sMensaje)) { using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { MembershipUser Usuario = Membership.GetUser(EmailUsuario, false); objUsuario.userid = Convert.ToInt32(Usuario.ProviderUserKey); if (objUsuario.bConsultar()) { objUsuario.mensaje_validacion = true; objUsuario.validado = false; objUsuario.codigo_validacion = validationCode; objUsuario.bModificar(); } } } }
protected void RegistroDeUsuarioForm_CreatedUser(object sender, EventArgs e) { MembershipUser membershipUser = Membership.GetUser(RegistroDeUsuarioForm.Email); if (membershipUser != null) { //YA NO LO LOGEAMOS DE FORMA AUTOMÁTICA //FormsAuthentication.SetAuthCookie(RegistroDeUsuarioForm.UserName, false); using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { if (membershipUser.ProviderUserKey != null) { objUsuario.userid = Convert.ToInt32(membershipUser.ProviderUserKey); TextBox txtFirstName = (TextBox)RegistroDeUsuarioForm.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName"); if (txtFirstName != null) { objUsuario.nombre = txtFirstName.Text; } TextBox txtLastName = (TextBox)RegistroDeUsuarioForm.CreateUserStep.ContentTemplateContainer.FindControl("txtLastName"); if (txtLastName != null) { objUsuario.apellidos = txtLastName.Text; } if (objUsuario.bModificar()) { EnviarMensajeAdministradores(RegistroDeUsuarioForm.Email); EnviarMensajeUsuario(RegistroDeUsuarioForm.Email); } Response.Redirect("~/novalidated.aspx?userid=" + objUsuario.userid.Value.ToString()); } } } }
protected void btnSaveDataProfile_Click(object sender, EventArgs e) { if (this.iduser.HasValue) { using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { objUsuario.userid = this.iduser; if (objUsuario.bConsultar()) { if (!string.IsNullOrEmpty(txtFirstName.Text)) { objUsuario.nombre = txtFirstName.Text; } if (!string.IsNullOrEmpty(txtLastName.Text)) { objUsuario.apellidos = txtLastName.Text; } if (!string.IsNullOrEmpty(txtResume.Text)) { objUsuario.resumen = txtResume.Text; } if (objUsuario.bModificar()) { RellenaDatosPerfil(); } else { RegistraIncidencia("registrado_profile", "Error en la función << btnSaveDataProfile_Click() >>. Motivo : No se ha podido MODIFICAR el perfil del usuario", 4); } } else { Response.Redirect("~/errors/notfound.aspx"); } } } else { Response.Redirect("~/errors/notfound.aspx"); } }
protected void btnSendCode_Click(object sender, EventArgs e) { if (!usuarioid.HasValue) { return; } MembershipUser Usuario = Membership.GetUser(usuarioid, false); if (Usuario != null) { string validationCode = new Random().Next().ToString(); //1.-Destino del mensaje System.Net.Mail.MailAddressCollection MisDestinos = new System.Net.Mail.MailAddressCollection(); MisDestinos.Add(new System.Net.Mail.MailAddress(Usuario.Email)); //2.-Cuerpo del mensaje HttpServerUtility server = HttpContext.Current.Server; string sMensaje = "We have sucessfully received your registration request to DropKeys. To complete the subscription process, please click the following link :\r\n\r\n " + Request.Url.GetLeftPart(UriPartial.Authority) + "/validatecode.aspx?email=" + server.UrlEncode(Usuario.Email) + "&vc=" + validationCode + "\r\n\r\nThank you."; if (EmailUtils.SendMessageEmail(MisDestinos, "Verify your email", sMensaje)) { using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { objUsuario.userid = usuarioid; if (objUsuario.bConsultar()) { objUsuario.mensaje_validacion = true; objUsuario.validado = false; objUsuario.codigo_validacion = validationCode; objUsuario.bModificar(); } } } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string email = string.Empty; string vc = string.Empty; if (!string.IsNullOrEmpty(Request.QueryString["email"])) { email = Request.QueryString["email"].ToString(); } if (!string.IsNullOrEmpty(Request.QueryString["vc"])) { vc = Request.QueryString["vc"].ToString(); } // Validate this email and validation code if (string.IsNullOrEmpty(email)) { lbResultado.Text = "<div class='alert alert-danger fade in'>Sorry but the e-mail user " + email + " can't be found in our database</div>"; btnGoWebsite.Visible = false; } else if (string.IsNullOrEmpty(vc)) { // Send email for validation MembershipUser Usuario = Membership.GetUser(email, false); using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { objUsuario.userid = Convert.ToInt32(Usuario.ProviderUserKey); objUsuario.validado = true; if (objUsuario.bConsultar()) { //GREEN lbResultado.Text = "<div class='alert alert-success fade in'>The e-mail user " + email + " has already been successfully validated, it is not necessary re-validate it again.</div>"; } else { try { string validationCode = new Random().Next().ToString(); //1.-Destino del mensaje System.Net.Mail.MailAddressCollection MisDestinos = new System.Net.Mail.MailAddressCollection(); MisDestinos.Add(new System.Net.Mail.MailAddress(email)); //2.-Cuerpo del mensaje HttpServerUtility server = HttpContext.Current.Server; string sMensaje = "We have received your registration request to DropKeys. To complete the subscription process, please click the following link:\r\n\r\n " + Request.Url.GetLeftPart(UriPartial.Authority) + "/validatecode.aspx?email=" + server.UrlEncode(email) + "&vc=" + validationCode + "\r\n\r\nThank you."; if (EmailUtils.SendMessageEmail(MisDestinos, "Check your email", sMensaje)) { objUsuario.userid = Convert.ToInt32(Usuario.ProviderUserKey); objUsuario.mensaje_validacion = true; objUsuario.validado = false; objUsuario.codigo_validacion = validationCode; objUsuario.suscrito = false; objUsuario.bModificar(); lbResultado.Text = "<div class='alert alert-success fade in'>We have sent an e-mail to " + email + ". Please click on the link enclosed in the mail to complete the subscription process.</div>"; } else { //RED lbResultado.Text = "<div class='alert alert-danger fade in'>We are very sorry we were unable to send the email with the validation key <a href=\"validatecode.aspx?email=" + Server.UrlEncode(email) + "\">Press here</a> to try it again.</div>"; } } catch (Exception) { //RED lbResultado.Text = "<div class='alert alert-danger fade in'>We are very sorry we were unable to send the email with the validation key <a href=\"validatecode.aspx?email=" + Server.UrlEncode(email) + "\">Press here</a> to try it again.</div>"; } } } } else if (!string.IsNullOrEmpty(vc)) { MembershipUser Usuario = Membership.GetUser(email, false); using (Clases.cASPNET_INFO_USUARIO objUsuario = new Clases.cASPNET_INFO_USUARIO()) { objUsuario.userid = Convert.ToInt32(Usuario.ProviderUserKey); objUsuario.codigo_validacion = vc; if (objUsuario.bConsultar()) { //GREEN lbResultado.Text = "<div class='alert alert-success fade in'>Congratulations, the e-mail " + email + " has been successfully validated.</div>"; objUsuario.validado = true; objUsuario.suscrito = true; objUsuario.bModificar(); //Logeamos FormsAuthentication.SetAuthCookie(email, true); } else { //RED lbResultado.Text = "<div class='alert alert-danger fade in'>Sorry but the email " + email + " could not be validated by our system. The validation code provided is not correct. " + "<a href=\"validatecode.aspx?email=" + email + "\">Click here</a>" + " to request a new validation code.</div>"; } } } } }