Ejemplo n.º 1
0
function check_post_values($db, $data)
{
    // If user has pressed "Rekisteröidy" -button,
    // then username key index is set. Let's try to
    // register new user.
    if (isset($data['username'])) {
        require 'CRegister.php';
        // Try to register new user.
        try {
            $reg = new CRegister($db, $data);
            // Message to show after registeration.
            $_SESSION['message'] = 'Käyttäjätunnus "' . $data['username'] . '" on nyt rekisteröity.';
            // Icon to show.
            $_SESSION['message_icon'] = 'graphics/32px-Crystal_Clear' . '_app_clean.png';
        } catch (Exception $e) {
            // Icon to show
            $_SESSION['message_icon'] = 'graphics/32px-Crystal_Clear' . '_app_logout.png';
            $_SESSION['message'] = $e->getMessage();
        }
        // If there were no errors, good.
        if (!isset($_SESSION['message'])) {
            create_site_top();
            create_top_menu();
            echo '<div class="register">';
            show_message();
            echo '</div>';
            create_site_bottom();
            die;
        } else {
            create_site_top();
            create_top_menu();
            echo '<div class="register">';
            // If message icon is app_logout then there
            // was problem while registering. We must give a link
            // where user can go back to registering page.
            if ($_SESSION['message_icon'] == 'graphics/32px-Crystal_Clear_app_logout.png') {
                $back_to_register = true;
            } else {
                $back_to_register = false;
            }
            show_message();
            // Show correct link, depending on how succesfully user
            // registering was.
            if ($back_to_register) {
                echo '<a href="register.php">Takaisin rekisteröitymissivulle</a><br><br>';
            } else {
                echo '<a href="login.php">Kirjautumissivulle</a><br><br>';
            }
            echo '</div>';
            create_site_bottom();
            die;
        }
    }
}
Ejemplo n.º 2
0
function get_id($db, $data)
{
    $id = null;
    $username = null;
    if (!isset($data['id'])) {
        set_message('Virheellinen käyttäjä-ID', 1);
    } else {
        $id = mysql_real_escape_string($data['id']);
    }
    if (!is_null($id)) {
        $username = get_poet_username($id);
        if (is_null($username)) {
            set_message('Annetulla ID:llä ei löydy käyttäjää!', 1);
        }
    }
    if (is_null($username)) {
        echo '<div class="poems">';
        show_message();
        echo '</div>';
        create_site_bottom();
        die;
    }
    return $id;
}
Ejemplo n.º 3
0
    echo '<td><input type="text" name="username"></td></tr>';
    echo '<tr><td>Salasana</td>';
    echo '<td><input type="password" name="password"></td></tr>';
    echo '<tr><td colspan="2"><input type="submit" ' . 'value="Kirjaudu"></td>';
    echo '</tr>';
    echo '</table>';
    echo '</form>';
    echo '<a href="register.php">Luo uusi käyttäjätunnus</a><br><br>';
    echo '</div>';
}
session_start();
require 'general_functions.php';
// Check POST-values if there is any.
check_post_values($db, $_POST);
// Create html start tags and top menu
create_site_top();
create_top_menu();
echo '<div class="login">';
// Show possible messages (eg. if login is succesfully made or
// if something has failed in login or something like that).
show_message();
// If we are not logged in, show login form.
if (!isset($_SESSION['username'])) {
    create_login_form();
}
echo '</div>';
// Create HTML end tags.
create_site_bottom();
?>