Ejemplo n.º 1
0
bool MySqlStorage::addContactToRoster(QString jid, Contact contact)
{
    if (contactExists(jid, contact.getJid()))
    {
        updateNameToContact(jid, contact.getJid(), contact.getName());
        updateGroupToContact(jid, contact.getJid(), contact.getGroups());
        return true;
    }
    else
    {
        if (userExists(contact.getJid()))
        {
            QJsonDocument document;
            QJsonObject object;
            object.insert("groups", QJsonArray::fromStringList(QStringList::fromSet(contact.getGroups())));
            document.setObject(object);

            QSqlQuery query;
            query.prepare("INSERT INTO qjabberd_contact(user_id, approved, ask, groups, jid, name, subscription, version)"
                          " VALUES(:user_id, :approved, :ask, :groups, :jid, :name, :subscription, :version)");
            query.bindValue(":user_id", getUserId(jid));
            query.bindValue(":version", contact.getVersion());
            query.bindValue(":approved", (int)contact.getApproved());
            query.bindValue(":ask", contact.getAsk());
            query.bindValue(":jid", contact.getJid());
            query.bindValue(":name", contact.getName());
            query.bindValue(":subscription", contact.getSubscription());
            query.bindValue(":groups", document.toJson());
            return query.exec();
        }
    }
    return false;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	int status = 0;

	if (argc != 2)
	{
		usage(argv[0]);
		return (status = ERR_ARGUMENTCOUNT);
	}

	// Make sure the user exists
	if (!userExists(argv[1]))
	{
		fprintf(stderr, "User %s does not exist.\n", argv[1]);
		return (status = ERR_NOSUCHUSER);
	}

	status = userDelete(argv[1]);
	if (status < 0)
	{
		errno = status;
		return (status);
	}

	printf("User deleted.\n");

	// Done
	return (status = 0);
}
Ejemplo n.º 3
0
char db_createUser( const char *username, const char *password )
{
	int userId, userLen, passLen;	
	User_t *user;
   	unsigned char hashpass[ SHA256_LEN ];
		
	userId = 0;
	userLen = strlen( username );
	passLen = strlen( password );
	memset( hashpass, 0, sizeof( hashpass ) );

	if( userLen < 1 || userLen > USER_MAX || passLen < 1 || passLen > SHA256_LEN )
		return DB_ERR_CREATE_LENGTH;
	
	if( userExists( username ) )
		return DB_ERR_CREATE_EXISTS;

	db_hashPass( password, hashpass );

	userId = getNextID();
	user = malloc( sizeof( User_t ) );
	memset( user, 0, sizeof( User_t ) );
	user->userId = userId;
	memcpy( user->username, username, strlen( username ) );
	memcpy( user->userpass, hashpass, SHA256_LEN );
	user->flags = 0;
	addUser( user );
	free( user );
		
	return DB_CREATE;
}
Ejemplo n.º 4
0
bool LoginControl::registerTempUser(string _username)
{
    if(!userExists(_username)){
        user = &(m_Parent->getStorageAccess().setNamePlaceholder(_username));
        return true;
    }
    else{
        return false;
    }
}
Ejemplo n.º 5
0
void LoginControl::loginUser(string _username, QPoint* _point)
{
	if (userExists(_username)){
         user = &(m_Parent->getStorageAccess().getProfile(_username));
		 m_Parent->setUserProfile(*user);
         m_Parent->completeLogin(_point);
         //login_window = NULL;
         //(login_window)->deleteLater();
	}
}
Ejemplo n.º 6
0
void UserDialog::addUser()
{
    QSqlRecord record;

    QSqlField id("id", QVariant::Int);
    QSqlField username("username", QVariant::String);
    QSqlField email("email", QVariant::String);
    QSqlField hashedPassword("hashed_password", QVariant::String);
    QSqlField salt("salt", QVariant::String);
    QSqlField roleId("role_id", QVariant::Int);

    id.setAutoValue(true);
    username.setValue(QVariant(usernameLineEdit->text()));
    email.setValue(QVariant(emailLineEdit->text()));

    QString generatedSalt = QUuid::createUuid().toString();
    QString generatedHashedPassword = QCryptographicHash::hash(passwordLineEdit->text().toAscii()
                                                               + generatedSalt.toAscii(),
                                                               QCryptographicHash::Sha1);

    hashedPassword.setValue(QVariant(generatedHashedPassword));
    salt.setValue(QVariant(generatedSalt));
    roleId.setValue(QVariant(getRoleId()));

    record.append(id);
    record.append(username);
    record.append(email);
    record.append(hashedPassword);
    record.append(salt);
    record.append(roleId);

    if(isFieldInputValid()
        && !isPasswordEmpty()
        && !userExists()
        && userModel->insertRecord(-1, record))
    {
        accept();
    }
    else
    {
        userModel->revertAll();
    }
}
Ejemplo n.º 7
0
/** 
\fn void ParticipantManager::setUser( int session, PlayerState state )
\brief Adds a user to the quiz. 
\param session Session ID of the player to be added
\param state State to set the player to
*/
void ParticipantManager::setUser( int session, PlayerState state )
{
	int userIndex = userExists(session);
	if ( userIndex != -1  ) 
	{
		//std::cout << "Setting user " << session << " state = " << state; 
		//set the session only
		quizUsers.at(userIndex)->setState(state);
	}
	
	else
	{
		QuizParticipant *p = new QuizParticipant(session);
		p->setState( state);
		std::cout << "Session ID : " << p->getSessionID() << std::endl;
		quizUsers.push_back(p);		
		//std::cout << "Added user " << session << " Num = " << quizUsers.size(); 
	}
}
Ejemplo n.º 8
0
void DesktopGridWidget::slotAddUser(int userid)
{
    Q_ASSERT(!userExists(userid));

    UserDesktopWidget* userdesktop = new UserDesktopWidget(this, userid, BORDER_WIDTH);
    userdesktop->setFocusPolicy(Qt::StrongFocus); //so we can get keyboard input
    userdesktop->setAttribute(Qt::WA_DeleteOnClose);
    connect(this, SIGNAL(userDesktopWindowUpdate(int,int)),
            userdesktop, SLOT(slotDesktopUpdate(int,int)));
    connect(userdesktop, SIGNAL(userDesktopWindowEnded(int)),
            SIGNAL(userDesktopWindowEnded(int)));
    connect(userdesktop, SIGNAL(userWidgetFocused(int, bool)), 
            this, SLOT(slotDesktopWidgetFocused(int, bool)));
    connect(this, SIGNAL(userDesktopCursorUpdate(int,const DesktopInput&)),
            userdesktop, SLOT(slotDesktopCursorUpdate(int,const DesktopInput&)));
    connect(this, SIGNAL(userUpdated(const User&)), userdesktop,
            SLOT(slotUserUpdated(const User&)));
    addUserWidget(userid, userdesktop);

    emit(desktopCountChanged(getActiveUsersCount()));
}
Ejemplo n.º 9
0
current_user_t* userLogin(int socket_id)
{
	int loggedIn;// = (int*)malloc(sizeof(int));
	loggedIn = 0;
	char* userName = (char*)malloc(15);
	int numbytes = recv(socket_id, userName, 15, 0);
	fflush(stdout);
	
	current_user_t* logInUser = (current_user_t*)malloc(sizeof(current_user_t));
	
	if (userExists(userName) == 1)
	{
		send_number(socket_id, 1);
		userpw_t * User;
		User = node_find_name(userName);
		char* password = (char*)malloc(15);
		recv(socket_id, password, 15, 0);
		int pwc = passwordCorrect(User, password);
		free(password);
		if (pwc == 1)
		{
			send_number(socket_id, 1);
			loggedIn = 1;
			logInUser->loggedIn=loggedIn;
			logInUser->user=User;
		} else {
			send_number(socket_id, 0);
			close(socket_id);
		}
	} else {
		send_number(socket_id, 0);
		close(socket_id);
		//perror("wrong user");
		//exit(1);
	}
	//free(userName);
	return logInUser;	
}
Ejemplo n.º 10
0
bool Server::requestBetween(string user, string request)
{
	return userExists(request) && getUser(user).hasRequest(request);
}
Ejemplo n.º 11
0
bool Server::arePartners(string user, string other)
{
	return userExists(other) && getUser(user).isPartner(other);
}
Ejemplo n.º 12
0
void UI::handleCommand(const std::string &command) {

	std::pair<std::string::size_type, std::string::size_type> pos
		= nextToken(command);
	std::string::size_type len = pos.second - pos.first;

	if (!len) {
		return;
	}

	std::string data(command, pos.first, len);

	if (len == 1 && data == "/" && command.length() > 2) {
		pos.first += 2;
		goto chatmsg;
	}

	if (command[pos.first] != '/') {
	chatmsg:
		if (! chatNetwork.length()) {
			messageW->printf("Message not sent, use /chat or /msg command\n");
			messageW->refresh();
			return;
		}

		if (! userExists(chatUser, chatNetwork)) {
			messageW->printf("Message not sent, user not found\n");
			messageW->refresh();
			return;
		}

		sendSignal("/net/msg/send", chatNetwork,
				   new sig::MessageData(chatUser,
									std::string(command, pos.first), 0));

	}

	if (len == 5 && (data == "/quit" || data == "/exit")) {
		sendSignal("/core/module/exits", Core::coreName);
		return;
	}

	if ((len == 2 && (data == "/n" || data == ":n"))
	|| (len == 6 && data == "/names")) {
		/* /names command */
		if (networkUsers.empty()) {
			messageW->printf("There are no connected networks\n");
		} else {
			NetworkUsers::iterator nuit;
			sig::UsersListData::Users::iterator uit;
			for(nuit=networkUsers.begin(); nuit!=networkUsers.end(); ++nuit) {
				if (nuit->second->users.empty()) {
					messageW->printf("Network %s has no connected users\n",
					                 nuit->first.c_str());
				} else {
					messageW->printf("Connected users in network %s:\n",
					                 nuit->first.c_str());
					for(uit=nuit->second->users.begin();
					    uit!=nuit->second->users.end();
					    ++uit) {
						messageW->printf("%s (%s) (%s)\n",
						          uit->second->name.c_str(),
						          uit->first.toString().c_str(),
						          uit->second->status.toString().c_str()
						);
					}
				}
			}
		}
	}

	if (len == 5 && data == "/chat") {

		/* trim */
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* end chat */
			messageW->printf("Chat with %s (network %s) finished\n",
			                chatUser.toString().c_str(),
							chatNetwork.c_str());
			chatNetwork.clear();
			statusW->printf("\n");
			statusW->refresh();
			return;
		}

		std::string userString(command, pos.first, pos.second-pos.first);

		std::multimap< std::string, User* >::iterator it;
		findUsers(userString);

		if(usersFound.size() == 0) {
			messageW->printf("No users match to '%s', try /names command.\n", userString.c_str());
		} else if(usersFound.size() > 1) {
			int iii;
			messageW->printf("Ambiguous user '%s', possible matches:\n",
			                 userString.c_str());
			for(iii=1, it=usersFound.begin(); it!=usersFound.end(); ++iii, ++it) {
				messageW->printf("[#%d] %s\n", iii, it->second->id.toString().c_str());
			}
			completionModeEnter();
		} else {

			it = usersFound.begin();
			chatUser = it->second->id;
			chatNetwork = it->first;
			messageW->printf("Chatting with %s (network %s)\n",
			                 chatUser.toString().c_str(),
							 chatNetwork.c_str());
			statusW->printf("Chatting with %s (network %s)\n",
			                 chatUser.toString().c_str(),
							 chatNetwork.c_str());
			statusW->refresh();
		}
		messageW->refresh();
	}

	if ((len == 4 && data == "/msg") ||
	    (len == 3 && data == "/me")) {
		/* if len == 0 then data == "/" */

		/* trim */
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* refuse to send empty line */
			return;
		}

		std::string userString(command, pos.first, pos.second-pos.first);
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* no message? */
			return;
		}
		std::string msgString(command, pos.first, pos.second-pos.first);

		std::multimap< std::string, User* >::iterator it;
		findUsers(userString);

		if(usersFound.size() == 0) {
			messageW->printf("No users match to '%s', try /names command.\n", userString.c_str());
		} else if(usersFound.size() > 1) {
			int iii;
			messageW->printf("Ambiguous user '%s', possible matches:\n",
			                 userString.c_str());
			for(iii=1, it=usersFound.begin(); it!=usersFound.end(); ++iii, ++it) {
				messageW->printf("[#%d] %s\n", iii, it->second->id.toString().c_str());
			}
			completionModeEnter();
		} else {

			it = usersFound.begin();
			std::string net = it->first;
			sendSignal("/net/msg/send", net,
			           new sig::MessageData(it->second->id,
		                                std::string(command, pos.first),
		                                len==3?sig::MessageData::ACTION:0));
		}

	} else if (len == 3 && data == "/aw") {
		/* dirty trick */
		pos.second = pos.first + 1;
		goto status;

	} else if (len == 7 && data == "/status") {
	status:
		enum User::State state;
		bool valid;

		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			return;
		}

		data.assign(command, pos.first, pos.second - pos.first);
		state = User::getState(data, valid);
		if (!valid) {
			return;
		}

		/* send to all networks */
		std::string net = "/net/";
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			data.clear();
		} else {
			data.assign(command, pos.first, std::string::npos);
		}

		/*
		 * in UserData we must supply valid data only for these
		 * information which has changed (status and/or displayname)
		 */
		sendSignal("/net/status/change", net,
		           new sig::UserData(User("dummy", Address(),
		                                  User::Status(state, data)),
		                             sig::UserData::STATE |
		                             sig::UserData::MESSAGE));
	} else if((len == 3 && data == "/dn")
	|| (len = 12 && data == "/displayname")) {



	} else if(len == 8 && data == "/history") {
		std::list<std::string>::iterator hi;
		int i;

		messageW->printf("Command history:\n");
		for(hi=history.begin(), ++hi, i=1; hi!=history.end(); ++hi, ++i) {
			messageW->printf("[%2d] %s\n", i, hi->c_str());
		}
		messageW->refresh();


	/* ... and so it may go with other commands */
	} else {
		/* print error message -- unkonw command */
	}
}