Exemplo n.º 1
0
function pageController()
{
    $errors = [];
    if (!Auth::isLoggedIn()) {
        header('Location: users.create.php');
        exit;
    }
    $userObject = UserModel::find($_SESSION['user_id']);
    if (!empty($_POST)) {
        try {
            $userObject->first_name = Input::getString('firstName');
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $userObject->last_name = Input::getString('lastName');
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        if (Input::get('password1') == Input::get('password2')) {
            try {
                $userObject->password = Input::getPassword('password1', $userObject->first_name, $userObject->last_name, $userObject->email);
            } catch (Exception $e) {
                $errors[] = $e->getMessage();
            }
        }
        $userObject->save();
    }
    return ['user' => $userObject, 'errors' => $errors];
}
Exemplo n.º 2
0
function processForm()
{
    $errors = [];
    $errors['count'] = 0;
    //form was submitted when $_POST is not empty
    if (!empty($_POST)) {
        try {
            $firstName = Input::getString('first_name');
        } catch (Exception $e) {
            $errors['first_name'] = 'First Name: ' . $e->getMessage();
            $errors['count']++;
        }
        try {
            $lastName = Input::getString('last_name');
        } catch (Exception $e) {
            $errors['last_name'] = 'Last Name: ' . $e->getMessage();
            $errors['count']++;
        }
        try {
            $email = Input::getString('email');
        } catch (Exception $e) {
            $errors['email'] = 'Email Address: ' . $e->getMessage();
            $errors['count']++;
        }
        try {
            if ($_POST['password1'] != $_POST['password2']) {
                throw new UnexpectedValueException("Do Not Match!");
            }
            $passwordOneHashed = Input::getPassword('password1', $firstName, $lastName, $email);
        } catch (Exception $e) {
            $errors['password1'] = 'Password: '******'count']++;
        }
        if ($errors['count'] == 0) {
            //no errors - add to the database
            $userObject = new UserModel();
            $userObject->first_name = $firstName;
            $userObject->last_name = $lastName;
            $userObject->email = $email;
            $userObject->password = $passwordOneHashed;
            $userObject->save();
            header("Location: /users.show.php?id=" . $userObject->id);
            //this will be the $_GET for the users.show.php
            die;
        }
    }
    return $errors;
}