/** * Performs an authentication * @param array * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { $user = $this->users->where('email', $credentials['email'])->fetch(); if (!$user) { $data = array("username" => $credentials['username'], "email" => $credentials['email'], "name" => $credentials['first_name'], "surname" => $credentials['last_name'], "sex" => strtoupper((string) $credentials['gender'][0]), "facebook_id" => $credentials['id'], "role" => "member", "password" => hash("sha512", strftime('%a%b%y') . str_repeat('mooow', 10)), "generated_password" => 1, "active" => 1); $user = $this->users->insert($data); } else { if ($user->facebook_id !== $credentials['id']) { $this->users->update(array('facebook_id' => $credentials['id'])); } } $this->users->update(array('last_login' => new DibiDateTime(), 'last_ip' => $_SERVER['REMOTE_ADDR'])); return new NS\Identity($user->id, $user->role, $user->toArray()); }
public function albumFormSubmitted(Form $form) { if ($form['save']->isSubmittedBy()) { $id = (int) $this->getParam('id'); if ($id > 0) { $this->albums->find($id)->update($form->values); $this->flashMessage('The album has been updated.'); } else { $this->albums->insert($form->values); $this->flashMessage('The album has been added.'); } } $this->redirect('default'); }
public function pageFormSubmitted(Form $form) { $values = $form->values; $values->slug = Strings::webalize($values->title); // z title udelame url adresu-slug $this->existingSlug = $this->getModel('PagesModel')->countAllWithSlug($values->slug); // Spocita pocet zaznamu, ktery maji slug stejny jak nadpis z formulare if ($form['save']->isSubmittedBy()) { if (($this->existingSlug == 0) AND ($values->slug !== "admin")) { // Pokud neni v databazi zaznam se stejnym slugem a pokud se slug nerovna hodnote admin $id = (int) $this->getParam('id'); if ($id > 0) { $this->pages->find($id)->update($values); $this->flashMessage('Stránka byla upravena.'); } else { $this->pages->insert($values); $this->flashMessage('Stránka byla přidána.'); } } else { // pokud se snazime ulozit existujici slug nebo admin slug $this->flashMessage('Nemůžete přidat existující stránku.'); $this->redirect('default'); } } $this->redirect('default'); }