/// If the provided username and password are correct, will return with an
/// authentication token & user pair for authenticating requests.
If the provided username and password are correct, will return with an
authentication token & user pair for authenticating requests.
If the provided username and password are correct will return with an authentication token & user pair for authenticating requests .
pub async fn login(
        &self,
        context: &async_graphql::Context<'_>,
        username: String,
        password: String,
    ) -> Result<AuthPayload> {
        let (db, _) = Context::parse(context)?;
        let localuname = localize_username(&username);
        let result = User::collection(&db)
            .find_one(doc! { "localuname": localuname }, None)
            .await?;
        let user = match result {
            Some(user) => user,
            None => return Err(UserSideError::NoUserWithName(username).into()),
        };
        if !verify_pwd(&password, &user.pwd_hash)? {
            return Err(UserSideError::PasswordsDoNotMatch.into());
        }
        Ok(AuthPayload::new(user._id))
    }
pub async fn login ( & self , context : & async_graphql :: Context < ' _ > , username : String , password : String , ) -> Result < AuthPayload > { let ( db , _ ) = Context :: parse ( context ) ? ; let localuname = localize_username ( & username ) ; let result = User :: collection ( & db ) . find_one ( doc ! { " " localuname } , None ) . await ? ; let user = match result { Some ( user ) => user , None => return Err ( UserSideError :: NoUserWithName ( username ) . into ( ) ) , } ; if ! verify_pwd ( & password , & user . pwd_hash ) ? { return Err ( UserSideError :: PasswordsDoNotMatch . into ( ) ) ; } Ok ( AuthPayload :: new ( user . _id ) ) }
If the provided username and password are correct, will return with an
authentication token & user pair for authenticating requests.
If the provided username and password are correct will return with an authentication token & user pair for authenticating requests .
&self
context
&async_graphql::Context<'_>
username
String
password
String