public function zajemceFormSucceeded($button) { $values = $button->getForm()->getValues(true); $id = (int) $this->getParameter('id'); if ($id) { try { $new_user = $this->users->update($id, $values); if ($new_user) { $this->flashMessage('Účet zájemce byl upraven.'); } } catch (\PDOException $e) { if ($e->getCode() == 23000) { $this->flashMessage('Zájemce s tímto aliasem už je zaregistrován, zvolte prosím jiný.'); } else { throw $e; } } } else { // registrace noveho zajemce try { $new_user = $this->users->register($values); if ($new_user) { $this->flashMessage('Účet zájemce byl vytvořen. Nyní se může přihlásit.'); } } catch (\PDOException $e) { if ($e->getCode() == 23000) { $this->flashMessage('Zájemce s tímto aliasem už je zaregistrován, zvolte prosím jiný.'); } else { throw $e; } } } $this->redirect('zajemci'); }
public function editFormSucceeded($form, $values) { $id = $values->id; unset($values->id); try { $this->model->update($id, $values); $this->flashMessage("Nastavení uživatele bylo uloženo.", "success"); } catch (Exception $e) { $this->flashMessage("Během ukládání dat uživatele došlo k chybě.", "danger"); } $this->redirect("id", $id); }
public function verificationFormSucceeded($form, $values) { $username = $values->username; $token = $values->token; $userData = $this->model->getBy(array("email" => $username)); if ($userData) { $id = $userData->id; try { $this->model->update($id, array("enabled" => 1)); $this->userModel->removeToken($id); $this->userModel->setValidated($id); $this->flashMessage("Registrace je dokončena.", "success"); $this->redirect("in"); } catch (Nette\Security\AuthenticationException $e) { $this->flashMessage("Během dokončení registrace došlo k chybě.", "danger"); } } $this->redirect("verification", array("username" => $username, "token" => $token)); }
public function facebookRegistrationFormSucceeded($form, $values) { $fbUserId = $values->id; unset($values->id); try { if ($this->facebookUserModel->exists($fbUserId)) { $this->flashMessage("Uživatel s tímto FacebookID již je v systému zaregistrován.", "danger"); $this->redirect("in"); } else { $id = $this->model->insert($values); $this->model->update($id, array("enabled" => 1, "active" => 1)); $this->flashMessage("Uživatel byl úspěšně zaregistrován.", "success"); $this->facebookUserModel->add(array("user_id" => $id, "facebook_id" => $fbUserId, "username" => $values->firstname . " " . $values->lastname, "email" => $values->email)); $this->facebookUserModel->authenticate(array($this->facebook->getUser())); $this->facebookUserModel->updateToken($this->facebook->getUser(), $this->facebook->getAccessToken()); } } catch (Exception $e) { $this->flashMessage("Registrace uživatele se nepodařila.", "danger"); } $this->redirect(":Front:Homepage:default"); }
public function actionImportStudents() { $result = $this->model->importStudents(); $messages = $result->messages; $data = $result->data; $reports = array(); $this->studentsModel->invalidate(); $classConversionTable = array(); $classData = $this->classesModel->query("SELECT id, bakalari_code FROM sch_class")->fetchAll(); foreach ($classData as $classRecord) { $classConversionTable[$classRecord["bakalari_code"]] = $classRecord["id"]; } foreach ($data as $record) { $id = $this->studentsModel->existsBakalari($record->bakalari_code); if (!$id) { $newid = $this->usersModel->insert(array("firstname" => $record->firstname, "lastname" => $record->lastname, "title" => $record->title, "title_after" => $record->title_after, "gender" => $record->gender, "birthdate" => $record->birthdate, "phone" => $record->mobile_phone, "personal_identification_number" => $record->personal_identification_number, "email" => $record->email, "enabled" => 1, "active" => 1)); $this->studentsModel->dumbInsert(array("user_id" => $newid, "catalog_number" => $record->catalog_number, "class_id" => $classConversionTable[$record->class_code], "network_login" => $record->login, "bakalari_code" => $record->bakalari_code)); $this->studentsModel->query("INSERT INTO login_imap VALUES (\"{$newid}\",\"{$record->login}\")"); $reports[] = "ADD: Student " . $record->firstname . " " . $record->lastname . " byl přidán. ({$newid})"; } else { $recid = $id->user_id; $this->usersModel->update($recid, array("firstname" => $record->firstname, "lastname" => $record->lastname, "title" => $record->title, "title_after" => $record->title_after, "gender" => $record->gender, "birthdate" => $record->birthdate, "phone" => $record->mobile_phone, "personal_identification_number" => $record->personal_identification_number, "email" => $record->email, "enabled" => 1, "active" => 1)); $this->studentsModel->update($recid, array("catalog_number" => $record->catalog_number, "class_id" => $classConversionTable[$record->class_code], "network_login" => $record->login, "bakalari_code" => $record->bakalari_code, "invalidated" => 0)); $this->studentsModel->query("INSERT INTO login_imap (user_id,username) VALUES (\"{$recid}\",\"{$record->login}\") ON DUPLICATE KEY UPDATE username = \"{$record->login}\""); $reports[] = "UPDATE: Student " . $record->firstname . " " . $record->lastname . " byl aktualizován. ({$recid})"; } } $this->studentsModel->query("DELETE FROM login_local WHERE user_id IN(SELECT user_id FROM sch_student WHERE invalidated = 1)"); $studentsGroupId = $this->membershipModel->getIdfromRole("student"); if ($studentsGroupId) { $this->membershipModel->emptyGroup($studentsGroupId); $reports[] = "Skupina {$studentsGroupId} byla vyprázdněna."; $this->membershipModel->query("INSERT INTO membership (`user_id`,`group_id`) SELECT user_id,{$studentsGroupId} FROM `sch_student`"); $reports[] = "Skupina {$studentsGroupId} byla naplněna aktuálními studenty."; } $this->studentsModel->removeUnused(); $this->template->reports = $reports; $this->template->messages = $messages; $this->setView("result"); }
public function userFormSucceeded($form, $values) { $id = $this->user->id; unset($values->id); $data = $this->model->get($this->user->id); if ($data) { $student = $this->model->getStudentData($this->user->id); $teacher = $this->model->getTeacherData($this->user->id); if (!($student || $teacher)) { try { $this->model->update($id, $values); $this->flashMessage("Změny informací byly uloženy.", "success"); } catch (Exception $e) { $this->flashMessage("Uložení změn se nepodařilo.", "danger"); } } else { $this->flashMessage("Data uživatele jsou spravována z externího zdroje. Není možné je upravovat.", "danger"); } } else { $this->flashMessage("Takový účet neexistuje.", "warning"); } $this->redirect("default"); }