Exemplo n.º 1
0
        protected void Button1_Click1(object sender, EventArgs e)
        {
            string emailVal    = email.Text;
            string nameVal     = nombre.Text;
            string surnamesVal = apellidos.Text;
            string passwordVal = hashPassword(password.Text);
            string rolVal      = rol.SelectedValue.ToLower();

            Random rnd           = new Random();
            int    confirmNumber = rnd.Next(10 ^ 5, 2147483647);

            Connection con = new Connection();

            int res = con.Register(emailVal, nameVal, surnamesVal, confirmNumber, rolVal, passwordVal);

            con.Close();

            if (res == 1)
            {
                string protocol = Request.ServerVariables["HTTPS"].ToLower() == "on" ? "https" : "http";
                string server   = Request.ServerVariables["SERVER_NAME"];
                string port     = Request.ServerVariables["SERVER_PORT"];

                string url  = $"{protocol}://{server}:{port}/Confirmar.aspx?email={emailVal}&confirmationCode={confirmNumber}&method=email";
                string body = $"<h1>Gracias por registrarte</h1><p>Pulsa <a href='{url}'>aquí</a> para activar tu cuenta.</p>" +
                              $"<p>¿Prefieres copiar el enlace a mano? Aquí lo tienes <a href='{url}'>{url}</a></p><hr>" +
                              $"<p style='text-align:center;font-size:.75rem;'>Este mensaje se ha enviado de forma automática</p>";

                string subject = "Confirmar cuenta";

                MailClient.sendMail(emailVal, subject, body);

                Response.Redirect("Inicio.aspx");
            }
        }
Exemplo n.º 2
0
        protected void requestChange_Click(object sender, EventArgs e)
        {
            Connection con = new Connection();

            string mail = email.Text;
            // string sql = $"select count(*) from Usuarios where email = '{mail}';";

            int exists = con.emailExsist(mail);

            if (exists == 0)
            {
                requestChangeError.Text = "El email indicado no está dado de alta en la plataforma.";
                email2.Text             = "";
                con.Close();
                return;
            }

            Random rnd         = new Random();
            int    confirmCode = rnd.Next(10 ^ 5, 2147483647);

            // sql = $"update usuarios set codpass = {confirmCode} where email = '{mail}';";
            int dbUpdated = con.setCodePass(mail, confirmCode);

            if (dbUpdated == 0)
            {
                requestChangeError.Text = "Error executando sentencia SQL.";
                email2.Text             = "";
                con.Close();
                return;
            }

            string protocol = Request.ServerVariables["HTTPS"].ToLower() == "on" ? "https" : "http";
            string server   = Request.ServerVariables["SERVER_NAME"];
            string port     = Request.ServerVariables["SERVER_PORT"];
            string url      = $"{protocol}://{server}:{port}/CambiarPassword.aspx?email={mail}&confirmationCode={confirmCode}&method=email";

            string body = $"<h1>Solicitud de cambio de contraseña</h1><p>Hola, introduce el siguiente código " +
                          $"para proceder a cambiar la clave de tu cuenta:</p><h2>{confirmCode.ToString()}</h2><p>También puedes pulsar <a href='{url}'>este enlace</a>.</p><hr>" +
                          $"<p style='text-align:center;font-size:.75rem;'>Este mensaje se ha enviado de forma automática</p>";
            string subject = "Cambio de contraseña";

            MailClient.sendMail(mail, subject, body);

            email2.Text          = mail;
            email.Text           = "";
            requestChangeOk.Text = "Se ha enviado un email con un código de confirmación.";

            con.Close();
        }