示例#1
0
function createPage($smarty)
{
    if (Users::loggedIn()) {
        Redirect::to('?page=profile');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'register') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/register_info'), Config::get('validation/set_password')));
            if ($validation->passed()) {
                try {
                    Users::create(array('student_id' => Input::get('sid'), 'password' => Hash::hashPassword(Input::get('password')), 'permission_group' => 1, 'name' => Input::get('name'), 'email' => Input::get('email'), 'umail' => Input::get('sid') . '@umail.leidenuniv.nl', 'phone' => Phone::formatNumber(Input::get('phone')), 'joined' => DateFormat::sql()));
                    Users::login(Input::get('sid'), Input::get('password'));
                    Notifications::addSuccess('You have been succesfully registered!');
                    Redirect::to('?page=profile');
                } catch (Exception $e) {
                    Notifications::addError($e->getMessage());
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'login') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/login'));
            if ($validation->passed()) {
                $login = Users::login(Input::get('sid'), Input::get('password'), Input::getAsBool('remember'));
                if ($login) {
                    Notifications::addSuccess('You have been logged in!');
                    Redirect::to('?page=profile');
                } else {
                    Notifications::addValidationFail('Invalid student number or password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
    }
    $smarty->assign('remember', Input::getAsBool('remember'));
    $smarty->assign('name', Input::get('name'));
    $smarty->assign('sid', Input::get('sid'));
    $smarty->assign('email', Input::get('email'));
    $smarty->assign('phone', Input::get('phone'));
    return $smarty;
}
示例#2
0
function createPage($smarty)
{
    if (!Users::loggedIn()) {
        Redirect::to('?page=login');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'logout') {
            if (Users::loggedIn()) {
                Users::logout();
                Notifications::addSuccess('You have been logged out!');
                Redirect::to('?page=login');
            }
        }
        if (Input::get('action') === 'update_info') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/user_info'));
            if ($validation->passed()) {
                $data = array('name' => Input::get('name'), 'student_id' => Input::get('sid'), 'email' => Input::get('email'), 'phone' => Phone::formatNumber(Input::get('phone')));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('User information updated!');
                } else {
                    Notifications::addError('Could not update user information.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_pass') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/set_password'), array('password_current' => array('name' => 'Current Password', 'required' => true, 'max' => 72))));
            if ($validation->passed()) {
                if (Hash::checkPassword(Input::get('password_current'), Users::currentData()->password)) {
                    if (Users::currentUser()->update(array('password' => Hash::hashPassword(Input::get('password'))))) {
                        Notifications::addSuccess('Password changed!');
                    } else {
                        Notifications::addError('Could not change password.');
                    }
                } else {
                    Notifications::addValidationFail('Invalid current password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_googleAuth') {
            $validation = new Validate();
            $validation->check($_POST, array('authcode' => array('name' => 'Authorisation Code', 'required' => true)));
            if ($validation->passed()) {
                if (Calendar::setCredentials(Input::get('authcode'))) {
                    Notifications::addSuccess('Google Calendar API authorized!');
                } else {
                    Notifications::addValidationFail('Could not authorize Google Calendar API.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_calendarAssignmentsId') {
            $validation = new Validate();
            $validation->check($_POST, array('calid-ass' => array('name' => 'Assignments Calendar ID', 'required' => false), 'calid-ex' => array('name' => 'Exams Calendar ID', 'required' => false)));
            if ($validation->passed()) {
                $data = array('calendar_assignments' => Input::get('calid-ass'), 'calendar_exams' => Input::get('calid-ex'));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('Calendar ID\'s updated!');
                } else {
                    Notifications::addValidationFail('Could not update calendar ID\'s.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'delete_googleAuth') {
            Calendar::deleteCredentials();
        }
        if (Input::get('action') === 'update_calendarAssignments' && Users::isEditor()) {
            $assignments = DB::instance()->get(Users::safeSid() . "_assignments")->results();
            foreach ($assignments as $assignment) {
                Calendar::updateAssignment($assignment->id);
            }
        }
        if (Input::get('action') === 'create_database') {
            if (!UserTables::hasTables()) {
                UserTables::createTables();
                if (Users::isGuest()) {
                    Users::currentUser()->update(array('permission_group' => '2'));
                }
            }
        }
    }
    if (!Calendar::isReady()) {
        $smarty->assign('authUrl', Calendar::getAuthUrl());
    }
    $smarty->assign('authCode', Input::get('authcode'));
    $smarty->assign('calid_ass', Users::currentData()->calendar_assignments);
    $smarty->assign('calid_ex', Users::currentData()->calendar_exams);
    $smarty->assign('name', Users::currentData()->name);
    $smarty->assign('sid', Users::currentData()->student_id);
    $smarty->assign('email', Users::currentData()->email);
    $smarty->assign('phone', Users::currentData()->phone);
    return $smarty;
}