public function index($error = null) { # If user is logged in but accidentally arrives to login page # redirect the user to home page if (HTTPSession::getInstance()->IsLoggedIn()) { header('Location: ' . SITE_URL); } # Get link for google auth (this is for the "Sign in using Google" button $link = GoogleAuth::getInstance()->getAuthLink(); # Display login page $this->view('login/index', ['error' => $error, 'link' => $link], false); }
# Define site URL constant, which is further used in controllers define('SITE_URL', $config->{'site_url'}); # Set time zone date_default_timezone_set($config->{'timezone'}); # Include essential classes require_once 'core/DatetimeConverter.php'; require_once 'core/App.php'; require_once 'core/Controller.php'; require_once 'core/GoogleAuth.php'; require_once 'models/DataBoundObject.php'; require_once 'models/ProjectFactory.php'; require_once 'models/HTTPSession.php'; require_once 'models/Notification.php'; require_once 'models/NotificationAP.php'; require_once 'models/NotificationMeeting.php'; require_once 'models/NotificationNote.php'; # Start a more secure session $objSession = HTTPSession::getInstance(); # Update the inactivity time on every reload of the page $objSession->Impress(); # Start up a GoogleAuth # TODO: This must be commented out for ssms.emilc.cz, because there's wrong redirect_uri GoogleAuth::getInstance(); # Check if user is NOT logged in if (!$objSession->IsLoggedIn()) { # Redirect to login page only if we're not already on login page # otherwise we would get a redirect loop if (isset($_GET['url']) && !(strpos($_GET['url'], 'login') !== false)) { header("Location: " . SITE_URL . "login"); } }
<?php # Initial steps performed before the application is started require_once 'app/init.php'; # Check whether code was passed back # This happens when user tries to login using GoogleAuth and # code is passed back, which is processed in the GoogleAuth class afterwards if (isset($_GET['code'])) { # If it was, pass it to the class GoogleAuth::getInstance()->checkCode($_GET['code']); } ### Start up the App class which takes care of routing ### $app = new App();
/** * A method to process POST request for editing an existing meeting * @param null $post the $_POST array */ public function editPost($post = null) { if (isset($post)) { # Create an object of existing meeting $meeting = $this->model('Meeting', $post['id']); # Check if we have access to editing $this->checkAuthIsApproved($meeting); $this->checkAuthCancelled($meeting); $this->checkAuthProjectScope($meeting->getProjectId()); # Set googleEventId to the value provided from database (if any) $googleEventId = $meeting->getGoogleEventId(); # Get details from post request $deadline = $post['deadline']; $deadline_time_hours = $post['deadline_time_hours']; $deadline_time_minutes = $post['deadline_time_minutes']; $isApproved = 0; if (isset($post['isApproved'])) { $isApproved = 1; } # If it's the supervisor who edits, it's automatically approved if (HTTPSession::getInstance()->USER_TYPE == User::USER_TYPE_SUPERVISOR) { $isApproved = 1; } $arrivedOnTime = 0; if (isset($post['arrivedOnTime'])) { $arrivedOnTime = 1; } $takenPlace = 0; if (isset($post['takenPlace'])) { $takenPlace = 1; } $isCancelled = 0; if (isset($post['isCancelled'])) { $isCancelled = 1; } # Set correct format of provided date $dateTime = DateTime::createFromFormat('d-m-Y H:i', $deadline . " " . $deadline_time_hours . ":" . $deadline_time_minutes); $date = $dateTime->format('Y-m-d H:i:s'); # Set meeting with provided details $meeting->setDatetime($date); $meeting->setIsApproved($isApproved); $meeting->setTakenPlace($takenPlace); $meeting->setArrivedOnTime($arrivedOnTime); $meeting->setIsCancelled($isCancelled); # Check if meeting is approved by a supervisor and user is logged in as google user # Also check if googleEventId exists for this meeting if ($isApproved && !empty(GoogleAuth::$auth) && !empty($googleEventId)) { # Get google auth format of datetime $datetimeGoogleStart = DatetimeConverter::getGoogleAuthDateTimeFormat($date); $datetimeGoogleEnd = $dateTime; $datetimeGoogleEnd->modify("+1 hour"); $datetimeGoogleEnd = DatetimeConverter::getGoogleAuthDateTimeFormat($datetimeGoogleEnd->format('Y-m-d H:i:s')); # In that case, we can add it to the google calendar and save the id of this event $googleEventId = GoogleAuth::getInstance()->editEventInCalendar($googleEventId, $datetimeGoogleStart, $datetimeGoogleEnd); } if (!empty($googleEventId)) { $meeting->setGoogleEventId($googleEventId); } # Save changes $meeting->Save(); # If meeting has taken place, create a notification if ($takenPlace) { new NotificationMeeting($meeting->getID(), NotificationMeeting::TAKEN_PLACE); } } # Redirect back to meetings header('Location: ' . SITE_URL . 'meetings/' . $post['id']); die; }