Example #1
0
                <td><input type="password" name="password2" id="password2"/></td>
            </tr><tr>
                <td> </td>
                <td><input type="submit" value="Zapisz"/></td>
                <td><input type="hidden" name="submitted" value="1"/></td>
            </tr><tr>
        </table>
    </form>
<?php 
$form = ob_get_clean();
// wyświetlenie formularza, jeśli strona jest wyświetlana po raz pierwszy
if (!isset($_POST['submitted'])) {
    $GLOBALS['TEMPLATE']['content'] = $form;
} else {
    // sprawdzenie poprawności hasła
    $password1 = isset($_POST['password1']) && $_POST['password1'] ? sha1($_POST['password1']) : $user->password;
    $password2 = isset($_POST['password2']) && $_POST['password2'] ? sha1($_POST['password2']) : $user->password;
    $password = $password1 == $password2 ? $password1 : '';
    // uaktualnienie rekordu, jeżeli dane wejściowe są poprawne
    if (User::validateEmailAddr($_POST['email']) && $password) {
        $user->emailAddr = $_POST['email'];
        $user->password = $password;
        $user->save();
        $GLOBALS['TEMPLATE']['content'] = '<p><strong>Informacje ' . 'w bazie danych zostały uaktualnione.</strong></p>';
    } else {
        $GLOBALS['TEMPLATE']['content'] .= '<p><strong>Podano nieprawidłowe ' . 'dane.</strong></p>';
        $GLOBALS['TEMPLATE']['content'] .= $form;
    }
}
// wyświetlenie strony
include '../templates/template.php';
Example #2
0
 </table>
</form>
<?php 
$form = ob_get_clean();
// show the form if this is the first time the page is viewed
if (!isset($_POST['submitted'])) {
    $GLOBALS['TEMPLATE']['content'] = $form;
} else {
    // validate password
    $password1 = isset($_POST['password1']) ? $_POST['password1'] : '';
    $password2 = isset($_POST['password2']) ? $_POST['password2'] : '';
    $password = $password1 && $password1 == $password2 ? sha1($password1) : '';
    // validate CAPTCHA
    $captcha = isset($_POST['captcha']) && strtoupper($_POST['captcha']) == $_SESSION['captcha'];
    // add the record if all input validates
    if ($password && $captcha && User::validateUsername($_POST['username']) && User::validateEmailAddr($_POST['email'])) {
        // make sure the user doesn't already exist
        $user = User::getByUsername($_POST['username']);
        if ($user->userId) {
            $GLOBALS['TEMPLATE']['content'] = '<p><strong>Sorry, that ' . 'account already exists.</strong></p> <p>Please try a ' . 'different username.</p>';
            $GLOBALS['TEMPLATE']['content'] .= $form;
        } else {
            // create an inactive user record
            $u = new User();
            $u->username = $_POST['username'];
            $u->password = $password;
            $u->emailAddr = $_POST['email'];
            $token = $u->setInactive();
            $GLOBALS['TEMPLATE']['content'] = '<p><strong>Thank you for ' . 'registering.</strong></p> <p>Be sure to verify your ' . 'account by visiting <a href="verify.php?uid=' . $u->userId . '&token=' . $token . '">verify.php?uid=' . $u->userId . '&token=' . $token . '</a></p>';
        }
    } else {