🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-08 19:34:24.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-08 19:34:24.0 +00:00:00
commit
511f35bcd6fc181b5db9e62dfcc96923285d5343 [patch]
tree
b854e84114da39ea622433d5592d3364d92735a2
parent
e383b00ff83c99bdf37c3cef37a3bd1da79ef911
download
511f35bcd6fc181b5db9e62dfcc96923285d5343.tar.gz

Send LOGGEDIN message to the user after authentication



Diff

 src/connection.rs | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/connection.rs b/src/connection.rs
index 774ba76..6817b0d 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -235,9 +235,9 @@ async fn start_authenticate_flow(
        };

        if authenticated {
            write
                .send(SaslSuccess(connection.nick.to_string()).into_message())
                .await?;
            for message in SaslSuccess(connection.clone()).into_messages() {
                write.send(message).await?;
            }

            return Ok(true);
        }
@@ -385,19 +385,37 @@ impl SaslStrategyUnsupported {
}

/// Returned to the client when authentication is successful.
pub struct SaslSuccess(String);
pub struct SaslSuccess(InitiatedConnection);

impl SaslSuccess {
    #[must_use]
    pub fn into_message(self) -> Message {
        Message {
            tags: None,
            prefix: None,
            command: Command::Response(
                Response::RPL_SASLSUCCESS,
                vec![self.0, "SASL authentication successful".to_string()],
            ),
        }
    pub fn into_messages(self) -> [Message; 2] {
        [
            Message {
                tags: None,
                prefix: None,
                command: Command::Response(
                    Response::RPL_SASLSUCCESS,
                    vec![
                        self.0.nick.to_string(),
                        "SASL authentication successful".to_string(),
                    ],
                ),
            },
            Message {
                tags: None,
                prefix: None,
                command: Command::Response(
                    Response::RPL_LOGGEDIN,
                    vec![
                        self.0.nick.to_string(),
                        self.0.to_nick().to_string(),
                        self.0.user.to_string(),
                        format!("You are now logged in as {}", self.0.user),
                    ],
                ),
            },
        ]
    }
}