Esempio n. 1
0
// Takes care of all the choices the user can
// make with the menu.
void LogIn::menuChoices()
{
	switch(choice)
	{
	case 1:
		createAccount();
		cout << endl;
		mainMenu();
		break;
	case 2:
		getUserInfo();
		cout << endl;
		mainMenu();
		break;
	case 3: 
		deleteQuery();
		deleteAccount();
		break;
	case 4:
		displayContents();
		mainMenu();
		break;
	case 9:
		cout << "You have exitted the program.\n";
		exit(EXIT_SUCCESS);
	}
}
Esempio n. 2
0
int main()
{

    string fileName = "";
    string input = "";

    cout << "Enter filename: \n> ";
    cin >> fileName;

    AccountNode* head = new AccountNode;
    head = loadAccountsFromFile(fileName);
    displayAccounts(head);

    cout << "Enter first name: \n> ";
    cin >> input;

    AccountNode* result = searchAccountListByFirstName(head, input); 

    cout << "Enter last name to find and remove: \n> ";
    cin >> input;

    result = searchAccountListByLastName(head, input); 
    if (result != NULL && deleteAccount(&head, result->account) == 0)
        cout << "Removal of \"" << result->account->firstName << " " << result->account->lastName << "\" was successful." << endl; 
    else
        cout << "Not found." << endl;
result = searchAccountListByLastName(head, "Almighty"); 
if (result != NULL && deleteAccount(&head, result->account) == 0)
        cout << "Removal of \"" << result->account->firstName << " " << result->account->lastName << "\" was successful." << endl; 
    else
        cout << "Not found." << endl;
result = searchAccountListByLastName(head, "Borden"); 
cout << result << endl;
    if (result != NULL && deleteAccount(&head, result->account) == 0)
        cout << "Removal of \"" << result->account->firstName << " " << result->account->lastName << "\" was successful." << endl; 
    else
        cout << "Not found." << endl;
    displayAccounts(head);

    // unless we delete the memory 
    // we're going to have a ton of memory leaks
    return 0;
}
Esempio n. 3
0
/*
 * Close_socket()
 *
 * Will close one socket directly, freeing all
 * resources and making the socket availably on
 * the socket free_list.
 */
void close_socket(SOCKET_DATA *dsock, bool reconnect)
{
  if (dsock->lookup_status > TSTATE_DONE) return;
  dsock->lookup_status += 2;

  /* remove the socket from the polling list */
  FD_CLR(dsock->control, &fSet);

  /* remove ourself from the list */
  //
  // NO! We don't want to remove ourself from the list just yet.
  // We will do that the next time we show up in the game_loop.
  // removing now will not close the socket completely. Why, I'm not
  // entirely sure... but it doesn't ;)
  //   - Geoff, Dec26/04
  //
  //  listRemove(socket_list, dsock);
  //

  // we have a character, and it's one that's
  // not in the process of being created
  if (dsock->player && charGetUID(dsock->player) != NOBODY) {
    if (reconnect)
      text_to_socket(dsock, "This connection has been taken over.\r\n");
    else {
      charSetSocket(dsock->player, NULL);
      log_string("Closing link to %s", charGetName(dsock->player));
    }
  }
  else if(dsock->player) {
    charSetSocket(dsock->player, NULL);
    extract_mobile(dsock->player);
  }
  
  if(dsock->account) {
    if(account_exists(accountGetName(dsock->account)))
      unreference_account(dsock->account);
    else
      deleteAccount(dsock->account);
  }

  /* set the closed state */
  dsock->closed = TRUE;
  //  dsock->state = STATE_CLOSED;
}
Esempio n. 4
0
/**
 * Update the account menu when accounts changed
 */
void CloudView::updateAccountMenu()
{
    // Remove all menu items
    account_menu_->clear();

    // Add accounts again
    const std::vector<Account>& accounts = seafApplet->accountManager()->accounts();

    if (!accounts.empty()) {
        if (!hasAccount()) {
            setCurrentAccount(accounts[0]);
        }

        for (int i = 0, n = accounts.size(); i < n; i++) {
            Account account = accounts[i];
            QAction *action = makeAccountAction(accounts[i]);
            if (account == current_account_) {
                action->setChecked(true);
            }
            account_menu_->addAction(action);
        }

        account_menu_->addSeparator();
    }

    // Add rest items
    add_account_action_ = new QAction(tr("Add an account"), this);
    add_account_action_->setIcon(awesome->icon(icon_plus));
    add_account_action_->setIconVisibleInMenu(true);
    connect(add_account_action_, SIGNAL(triggered()), this, SLOT(showAddAccountDialog()));
    account_menu_->addAction(add_account_action_);

    if (hasAccount()) {
        add_account_action_->setVisible(false); // disk42
        delete_account_action_ = new QAction(tr("Delete this account"), this);
        delete_account_action_->setIcon(awesome->icon(icon_remove));
        delete_account_action_->setIconVisibleInMenu(true);
        connect(delete_account_action_, SIGNAL(triggered()), this, SLOT(deleteAccount()));
        account_menu_->addAction(delete_account_action_);
    }
}
Esempio n. 5
0
void Session::input(){
	printf("Enter a command:\n");
	getline(cin, command);
	command = lower(command);
	while(command.compare("logout") != 0){
		if(command.compare("deposit") == 0){
			deposit();
		} else if(command.compare("withdraw") == 0){
			withdraw();
		} else if(command.compare("create") == 0){
			create();
		} else if(command.compare("delete") == 0){
			deleteAccount();
		} else if(command.compare("enable") == 0){
			enable();
		} else if(command.compare("disable") == 0){
			disable();
		} else if(command.compare("paybill") == 0){
			paybill();
		} else if(command.compare("transfer") == 0){
			transfer();
		} else if(command.compare("changeplan") == 0){
			changeplan();
		} else if(command.compare("login") == 0){
			printf("ERROR: You are currently in an active session. Log out first\n");
		} else {
			printf("Error, unrecognized command\n");
		}
		printf("Enter a command:\n");
		if(!getline(cin, command)){
			printf("End of file, logging out.\n");
			break;
		}
		command = lower(command);
	}

	logout();

	return;
}
Esempio n. 6
0
bool executeCommand(sqlite3 *db, const char *command)
{
    char **params;
    int paramsCount;
    int i;

    int from, to;
    double sum;

    (void)db;   // unused


    // parse command
    paramsCount = countWords(command);
    params = malloc(sizeof(char*) * paramsCount);
    for (i=0; i<paramsCount; i++)
        params[i] = getWord(command, i);            

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_HELP)))
        commandHelp();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_1)))
        command1();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_2)))
        command2();

    if ((paramsCount >= 4) && (!strcmp(params[0], COMMAND_TRANSF)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[3], "%lf", &sum);
        sscanf(params[2], "%i", &to);
        //transfer(db, from, to, sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
        credit(db, to, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_DEB)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_CRED)))
    {
        sscanf(params[1], "%i", &to);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0) return false;
        credit(db, to, sum);
    }

    if ((paramsCount >= 2) && (!strcmp(params[0], COMMAND_CHCK)))
    {
        sscanf(params[1], "%i", &to);
        checkAccount(db, to);
    }

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_UNDO)))
        undo(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADD)))
        createNewCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DEL)))
        deleteCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DELACC)))
        deleteAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADDACC)))
        addAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_COMMIT)))
        commit(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_SHOW)))
        showAll(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_LOGGER)))
        logger(db);

    for (i=0; i<paramsCount; i++)
        free(params[i]);
    free(params);

    return true;
}
Esempio n. 7
0
void Ui::start() {
  std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
  std::string next = mainMenu();
  std::string username = "";
  Account* account = nullptr;

  while (next != "quit") {
    std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

    if (next == "mainMenu") {
      next = mainMenu();
    }
    else if (next == "accountMenu") {
      next = accountMenu();
    }
    else if (next == "createAccount") {
      username = createAccount();
      next = "mainMenu";
      if (username.length() != 0) {
        next = "loadAccount";
      }
    }
    else if (next == "deleteAccount") {
      deleteAccount();
      next = "mainMenu";
    }
    else if (next == "loadAccount") {
      account = loadAccount(username);
      username = "";
      next = "accountMenu";
      if (account == nullptr) {
        next = "loadAccount";
      }
    }
    else if (next == "updateAccount") {
      updateAccount(account);
      next = "accountMenu";
    }
    else if (next == "getWithdrawals") {
      getWithdrawals(account);
      next = "accountMenu";
    }
    else if (next == "getDeposits") {
      getDeposits(account);
      next = "accountMenu";
    }
    else if (next == "withdraw") {
      withdraw(account);
      next = "accountMenu";
    }
    else if (next == "deposit") {
      deposit(account);
      next = "accountMenu";
    }
    else if (next == "quitAccountMenu") {
      delete account;
      account = nullptr;
      next = "mainMenu";
    }
  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  delete entries from a users account
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void MainWindow::on_deleteButton_clicked()
{
    deleteAccount();
}
Esempio n. 9
0
/**
 * Update the account menu when accounts changed
 */
void AccountView::onAccountChanged()
{
    const std::vector<Account>& accounts = seafApplet->accountManager()->accounts();

    // Remove all menu items
    account_menu_->clear();

    if (!accounts.empty()) {
        for (size_t i = 0, n = accounts.size(); i < n; i++) {
            const Account &account = accounts[i];
            QString text = account.username + "(" + account.serverUrl.host() + ")";
            if (!account.isValid()) {
                text += ", " + tr("not logged in");
            }
            QMenu *submenu = new QMenu(text, account_menu_);
            if (i == 0) {
                submenu->setIcon(QIcon(":/images/account-checked.png"));
            } else {
                submenu->setIcon(QIcon(":/images/account-else.png"));
            }

            QAction *submenu_action = submenu->menuAction();
            submenu_action->setData(QVariant::fromValue(account));
            connect(submenu_action, SIGNAL(triggered()), this, SLOT(onAccountItemClicked()));

            QAction *action = new QAction(tr("Choose"), submenu);
            action->setIcon(QIcon(":/images/account-checked.png"));
            action->setIconVisibleInMenu(true);
            action->setData(QVariant::fromValue(account));
            connect(action, SIGNAL(triggered()), this, SLOT(onAccountItemClicked()));

            submenu->addAction(action);
            submenu->setDefaultAction(action);

            QAction *account_settings_action = new QAction(tr("Account settings"), this);
            account_settings_action->setIcon(QIcon(":/images/account-settings.png"));
            account_settings_action->setIconVisibleInMenu(true);
            account_settings_action->setData(QVariant::fromValue(account));
            connect(account_settings_action, SIGNAL(triggered()), this, SLOT(editAccountSettings()));
            submenu->addAction(account_settings_action);

            QAction *toggle_action = new QAction(this);
            toggle_action->setIcon(QIcon(":/images/logout.png"));
            toggle_action->setIconVisibleInMenu(true);
            toggle_action->setData(QVariant::fromValue(account));
            connect(toggle_action, SIGNAL(triggered()), this, SLOT(toggleAccount()));
            if (account.isValid())
                toggle_action->setText(tr("Logout"));
            else
                toggle_action->setText(tr("Login"));
            submenu->addAction(toggle_action);

            QAction *delete_account_action = new QAction(tr("Delete"), this);
            delete_account_action->setIcon(QIcon(":/images/delete-account.png"));
            delete_account_action->setIconVisibleInMenu(true);
            delete_account_action->setData(QVariant::fromValue(account));
            connect(delete_account_action, SIGNAL(triggered()), this, SLOT(deleteAccount()));
            submenu->addAction(delete_account_action);

            account_menu_->addMenu(submenu);
        }

        account_menu_->addSeparator();
    }

    add_account_action_ = new QAction(tr("Add an account"), this);
    add_account_action_->setIcon(QIcon(":/images/add-account.png"));
    add_account_action_->setIconVisibleInMenu(true);
    connect(add_account_action_, SIGNAL(triggered()), this, SLOT(showAddAccountDialog()));
    account_menu_->addAction(add_account_action_);

    updateAccountInfoDisplay();
}
Esempio n. 10
0
void Pages::account(Document *doc){

    if(path == "/account/delete")
        return deleteAccount(doc);
    else if (path == "/goodbye")
        return doc->setHtml("html/goodbye.tpl", "Goodbye");

    if(path != "/account")
        return;

    if(!Session::user())
        return doc->redirect("/login?redirect=/account");

    Account a(Session::user().id);

    if(cgi.getEnvironment().getRequestMethod() != "POST" || Session::nonce() != cgi("nonce"))
        return form(doc, a);

    Session::newNonce();

    std::string name = cgi("name");
    if(!name.empty() && name != a.name){
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE lower(name) = lower($1))", name)[0][0] == "t")
            return form(doc, a, "Name already in use.");
    }
    else
        name = a.name;

    std::string email = cgi("email");
    if(!email.empty() && email != a.email){
        if(!validEmail(email))
            return form(doc, a, "Invalid email address.");
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE lower(email) = lower($1))", email)[0][0] == "t")
            return form(doc, a, "Email already in use.");
    }
    else
        email = a.email;

    std::string oldpw = cgi("oldpw"), newpw = cgi("newpw");
    if(!oldpw.empty() && !newpw.empty()){
        if(newpw != cgi("newpwconf"))
            return form(doc, a, "Passwords mismatch.");
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE id = " + number(a.id) + " AND password = crypt($1, password))", oldpw)[0][0] != "t")
            return form(doc, a, "Wrong password.");

        // Everything has been checked. Committing.

        DB::query("UPDATE users SET password = crypt($1, gen_salt('bf')) WHERE id = " + number(a.id), newpw);
    }


    DB::query(
        "UPDATE users SET name = $1, email = $2, about = $3, notify = $4 WHERE id = " + number(a.id),
        name, email, cgi("about"), cgi("notify").empty() ? "f" : "t"
    );

    if(a.name != cgi("name")){ // The name has changed.
        log("Renaming user: "******" -> " + cgi("name"));
        Session::destroy();
        Session::start();
        //std::vector<Track> tracks = a.tracks(true);
        //for(std::vector<Track>::iterator i=tracks.begin(); i!=tracks.end(); i++)
            //Media(*i).updateTags();
    }

    doc->setHtml("html/account.tpl", "Your account");
    doc->dict()->SetValueAndShowSection("MESSAGE", "Changes applied.", "MESSAGE");
    Account(a.id).fill(doc->dict());

}
Esempio n. 11
0
void SyncWindow::on_buttonDeleteAccount_clicked()
{
    deleteAccount();
}
Esempio n. 12
0
File: server.c Progetto: Vuzi/SFSS
/* Programme principal serveur */
void startServer(void) {

    /* Socket du serveur */
    SOCKET sock = startConnection(); /* Fonction de lancement du serveur, ici le serveur passe en écoute */
    int max = sock;

    /* Liste des différents comptes */
    Account *accounts = NULL;

    User *users = NULL;
    User *u_cursor = NULL, *tmp = NULL;

    /* Descripteur */
    fd_set rdfs;

    bool quit = false;


    /* A ajouter : commande permettant de quitter §§§ */
    while(!quit) {

        /* On vide le descripteur */
		FD_ZERO(&rdfs);

		/* On ajoute le socket du serveur */
		FD_SET((u_int)sock, &rdfs);

        u_cursor = getFirstUser(users);

        /* On ajoute le socket de chaque User */
        while(u_cursor) {
            FD_SET((u_int)(u_cursor->sock), &rdfs);
            u_cursor = u_cursor->next;
        }

		/* On effectue le select pour lier le descripteur à la lecture sur le socket */
		if(select(max+1, &rdfs, NULL, NULL, NULL) == SOCKET_ERROR) {
            sock_error("select()");
		} else {
			/* Ici on attends un changement d'un des descripteurs */

			/* Si c'est un nouveau client qui effectue une connexion */
			if(FD_ISSET(sock, &rdfs)) {

				HERROR_WRITE(HERROR_DEBUG, "[Serveur] Nouveau client detecte");

				/* Variables du nouveau client */
				SOCKADDR_IN csin;
				size_t sinsize = sizeof csin;

				/* Socket du nouveau client */
				int csock = accept(sock, (SOCKADDR *)&csin, (socklen_t *)&sinsize);

				/* Si erreur */
				if(csock == SOCKET_ERROR)
                    sock_error("accept()");

				/* On ajoute le client en attente de connexion */
				users = addUser(users, (SOCKET)csock, copy(inet_ntoa(csin.sin_addr)));

				/* Nouveau max : */
				max = csock > max ? csock : max;

				HERROR_WRITE(HERROR_INFO, "[Serveur] Nouveau client ajoute ( ip '%s')", users->ip);
			}
			/* Sinon c'est un client qui effectue une action */
			else {
                u_cursor = getFirstUser(users);

				/* Pour chaque Uset */
                while(u_cursor) {
                    /* S'il a envoyé des données */
                    if(FD_ISSET(u_cursor->sock, &rdfs)){

                        if(u_cursor->state == WAITING_MSG || u_cursor->state == WAITING_END_MSG) {
                            if(u_cursor->acc) {
                                HERROR_WRITE(HERROR_INFO, "[Serveur] Message client (ip '%s' | login '%s')", u_cursor->ip, u_cursor->acc->login);
                            } else {
                                HERROR_WRITE(HERROR_INFO, "[Serveur] Message client (ip '%s' | login '--')", u_cursor->ip);
                            }
                        }

                        /* Ici, fonction qui lit la réception du message */
                        if(rcvMsgFromUser(u_cursor, &accounts) == 0) {
                            /* si == 0, client déconnecté */
                            if(u_cursor->acc) {
                                HERROR_WRITE(HERROR_INFO, "[Serveur] Deconnexion client (ip '%s' | login '%s')", u_cursor->ip, u_cursor->acc->login);
                            } else {
                                HERROR_WRITE(HERROR_INFO, "[Serveur] Deconnexion client (ip '%s' | login '--')", u_cursor->ip);
                            }
                            /* On ferme la connexion */
                            closesocket(u_cursor->sock);

                            /* On l'enleve des Users */
                            tmp = u_cursor->next;
                            removeUserAndAccount(&u_cursor, &accounts);
                            users = u_cursor;
                            u_cursor = tmp;
                        } else
                            u_cursor = u_cursor->next;
                    } else
                        u_cursor = u_cursor->next;
                }
			}

		}
	}

	endConnection();

	deleteUser(users);
	deleteAccount(accounts);
}