Example #1
0
function pageController()
{
    session_start();
    $errors = array();
    if (!empty($_POST)) {
        // this block checks to see if an error is going to be thrown
        $username = ValidateUser::getUsername();
        $email = ValidateUser::getEmail();
        $password = ValidateUser::getPassword();
        $passwordmatch = ValidateUser::getPasswordMatch();
        //makes sure that passwords match
        if (isset($password) && isset($passwordmatch)) {
            ValidateUser::getCheckMatch($password, $passwordmatch);
        }
        $errors = ValidateUser::getErrors();
        // add inputed data into database
        if (Input::notEmpty('username') && Input::notEmpty('password') && Input::notEmpty('passwordmatch') && Input::notEmpty('email')) {
            ////does not save any user info yet
            if (empty($errors)) {
                // using models to save information
                $user = new User();
                $user->username = $username;
                $user->email = $email;
                $user->password = $password;
                try {
                    $user->save();
                    $log = new Log();
                    // if someone attempts to create a profile using a username and hypothetically the same password they cant get to the existing users profile
                    if (Auth::attempt($username, $password)) {
                        $log->info('User {$username} logged in.');
                        header('Location: /users');
                        exit;
                    } else {
                        $log->error('User {$username} failed to log in!');
                        $message = 'Please input the proper username and password.';
                    }
                } catch (Exception $e) {
                    $error = $e->getMessage();
                    array_push($errors, $error);
                }
                if (empty($errors)) {
                    $errors = array();
                }
            }
        }
    }
    return array('errors' => $errors);
}
Example #2
0
function pageController()
{
    session_start();
    if (!Auth::check()) {
        header('Location: /auth/login');
        exit;
    }
    $username = Auth::user();
    $user = User::findUserByUsername($username);
    $email = $user->attributes['email'];
    $password = $user->attributes['password'];
    $errors = array();
    if (!empty($_POST)) {
        if (Input::notEmpty('email')) {
            $email = ValidateUser::getEmail();
        }
        if (Input::notEmpty('password')) {
            $password = ValidateUser::getPassword();
        }
        if (Input::notEmpty('passwordmatch')) {
            $passwordmatch = ValidateUser::getPasswordMatch();
        }
        if (Input::notEmpty('passwordmatch') && Input::notEmpty('password')) {
            ValidateUser::getCheckMatch($password, $passwordmatch);
        }
        $errors = ValidateUser::getErrors();
        if (empty($errors)) {
            $user->attributes['username'] = $username;
            $user->attributes['email'] = $email;
            $user->attributes['password'] = $password;
            $user->save();
            header('Location: /users');
            exit;
        }
    }
    return array('username' => $username, 'email' => $email, 'password' => $password);
}