void GatewayTask::slotPresence(const XMPP::Presence& p)
{
    if ( p.type() == Presence::Available ) {
        emit userLogIn(p.from(), p.show());
    } else if ( p.type() == Presence::Unavailable ) {
        emit userLogOut(p.from());
    }
}
Beispiel #2
0
bool AgendaService::deleteUser(std::string userName, std::string password) {
  // only the user that can login can be deleted by our human animal, or
  // what the bird egg can we delete
  if (userLogIn(userName, password)) {
    // delete the meeting created by this user
    storage_->deleteMeeting([&](const Meeting& m) {
	return m.getSponsor() == userName;});
    // delete the user now
    storage_->deleteUser([&](const User & u) {
	return (u.getName() == userName && u.getPassword() == password);});
    return true;
  } else {

    return false;
  }
}
Beispiel #3
0
// a user can only delete itself
bool AgendaService::deleteUser(std::string userName, std::string password) {
    if (!userLogIn(userName, password)) return false;
    std::function<bool(const Meeting&) > filter = [userName]
    (const Meeting &meet) {
        if (meet.getSponsor() == userName ||
                meet.getParticipator() == userName) return true;
        return false;
    };
    std::function<bool(const User&user_) > judge = [userName, password]
    (const User&user) {
        if (user.getName() != userName) return false;
        if (user.getPassword() != password) return false;
        return true;
    };
    int t = storage_ -> deleteUser(judge);
    if (t != 0) {
        storage_ -> deleteMeeting(filter);
        return true;
    } else {
        return false;
    }
}
void GatewayTask::slotRegister(const XMPP::IQ& iq)
{
    QString tag = iq.childElement().tagName();
    QString ns = iq.childElement().namespaceURI();

    if ( tag == "query" && ns == NS_IQ_REGISTER && iq.type() == "get" ) {
        Registration form(d->reg);
        form.setTo(iq.from());
        form.setFrom(iq.to());
        form.setId(iq.id());
        form.setType(IQ::Result);

        d->stream->sendStanza(form);
        return;
    }
    if ( tag == "query" && ns == NS_IQ_REGISTER && iq.type() == "set" ) {
        Registration request(iq);

        if ( request.from().isEmpty() ) {
            Registration err = IQ::createReply(request);
            err.setError( Stanza::Error(Stanza::Error::UnexpectedRequest) );
            d->stream->sendStanza(err);
            return;
        }

        if ( request.hasField(Registration::Remove) ) {
            Registration reply = IQ::createReply(iq);
            reply.clearChild();
            reply.setType(IQ::Result);
            d->stream->sendStanza(reply);

            Presence removeSubscription;
            removeSubscription.setTo( iq.from().bare() );
            removeSubscription.setType(Presence::Unsubscribe);
            d->stream->sendStanza(removeSubscription);

            Presence removeAuth;
            removeAuth.setTo( iq.from().bare() );
            removeAuth.setType(Presence::Unsubscribed);
            d->stream->sendStanza(removeAuth);

            Presence logout;
            logout.setTo( iq.from() );
            logout.setType(Presence::Unavailable);
            d->stream->sendStanza(logout);

            emit userUnregister(iq.from());
            return;
        }

        if ( request.getField(Registration::Username).isEmpty() || request.getField(Registration::Password).isEmpty() ) {
            Registration err(request);
            err.swapFromTo();
            err.setError( Stanza::Error(Stanza::Error::NotAcceptable) );
            d->stream->sendStanza(err);
            return;
        }

        /* registration success */
        IQ reply = IQ::createReply(iq);
        reply.clearChild();
        d->stream->sendStanza(reply);

        /* subscribe for user presence */
        Presence subscribe;
        subscribe.setFrom(iq.to());
        subscribe.setTo( iq.from().bare() );
        subscribe.setType(Presence::Subscribe);
        d->stream->sendStanza(subscribe);

        emit userRegister( request.from(), request.getField(Registration::Username), request.getField(Registration::Password) );

        Presence presence;
        presence.setFrom(iq.to());
        presence.setTo( iq.from().bare() );
        d->stream->sendStanza(presence);

        /* execute log-in case */
        emit userLogIn(iq.from(), Presence::None);
        return;
    }
}