trim($this->_getParam('name')), 'email'=>$this->_getParam('email')); if (!$this->_hasParam('name') || strlen(trim($this->_getParam('name'))) < 2) { $errors[] = 'Naam is verplicht'; $error = true; } if (!$this->_hasParam('email') || !$validator->isValid($this->_getParam('email'))) { $errors[] = 'Ongeldig e-mailadres'; $error = true; } if (!$this->_hasParam('password') || strlen(trim($this->_getParam('password'))) < 5) { $errors[] = 'Uw wachtwoord moet minstens 5 tekens lang zijn'; $error = true; } if ($validator->isValid($this->_getParam('email'))) { $author = Application_Model_Author::getByEmail($this->_getParam('email')); if (isset($author['id'])) { $errors[] = 'Er bestaat al een account met dit e-mailadres.
Klik hier om een nieuw wachtwoord aan te vragen.'; $error = true; } } if ($error === false) { $result = Application_Model_Author::newAuthor('paard', array('name'=>$this->_getParam('name'), 'email'=>$this->_getParam('email'), 'password'=>$this->_getParam('password'))); if ($result) echo json_encode(array('success'=>true)); else echo json_encode(array('success'=>false, 'errors'=>array('Er is iets mis gegaan.'))); } else { echo json_encode(array('success'=>false, 'errors'=>$errors)); } exit(); } public function confirmAction() { if (!$this->_hasParam('email') || $this->_getParam('email' == '')) throw new Exception('Invalid link (1)'); if (!$this->_hasParam('id') || $this->_getParam('id' == '')) throw new Exception('Invalid link (2)'); $validator = new Zend_Validate_EmailAddress(); if (stripos($this->_getParam('email'), '%40')) { $email = urldecode($this->_getParam('email')); } elseif (stripos($this->_getParam('email'), '@')) { $email = $this->_getParam('email'); } else throw new Exception('Invalid link (3)'); if (!$validator->isValid($this->_getParam('email'))) throw new Exception('Invalid link (4)'); $author = Application_Model_Author::getByMd5Id($this->_getParam('id')); if (!$author) throw new Exception('Invalid link (5)'); if ($author['email'] != $this->_getParam('email')) throw new Exception('Invalid link (6)'); $author = Application_Model_Author::confirm($author['id']); $this->_redirect('http:'.$this->view->base.'/#login'); exit(); } public function resetAction() { $db_local = Zend_Db_Table::getDefaultAdapter(); if (isset($_GET['email'])){ $sql = "SELECT * FROM paard40_author WHERE email = ".$db_local->quote($_GET['email']); var_dump(count($db_local->fetchAll($sql))); if (count($db_local->fetchAll($sql)) > 0){ $salt = "fmGZqTnVKxewSfIMYfd4ukTDtwwJsJBVPJJDdK4xhpt6LVf954Q4H52CqhVGJ+zN3JD1V/GPhPil"; $i = 200; while ($i > 1){ $salt .= hash('sha512',$salt); $i = $i - 1; } $salt .= "mNhqkGGoIlDqG5G8QZ/giiN8bPTDYOLJLgBfwixocZ7SjyjAyesiHrY6uuipXRsgDOZCvpu537KY"; $i = 200; while ($i > 1){ $salt .= hash('sha512',$salt); $i = $i - 1; } $salf .= "f5qLmKJvae/RXdBjXSs/MiYeQv8KpafIfyhb6IpaBR0QArd14TWZ9ywd9WUyPR4tnHDSK+180uGQ"; $salt .= "xECP6KDasAdr5W5EJGb0yJ/Il8uuI05O8+P9JuusQIKz3VdWMCEk5VkZDo0BGqsOZ8buYexWnJ+/"; $hashme = $salt.$_GET['email']."RPTs6Obp0iQkdZMqZuXFhu3ytSOqNWCtvhafUwLZFaXGT3E+WTsOwaUOEpcLcgBmFdNfkufsskhR"; $hash = $hashme; $i = 500; while ($i > 1){ $hash = hash('sha512',$hash); $i = $i - 1; } var_dump($hashme); var_dump($hash);die(); } } die('geen email'); } public function confirmresetAction() { $db_local = Zend_Db_Table::getDefaultAdapter(); if (isset($_GET['email']) && isset($_GET['hash'])) { $sql = "SELECT * FROM paard40_author WHERE email = ".$db_local->quote($_GET['email']); if (count($db_local->fetchAll($sql)) > 0){ $salt = "fmGZqTnVKxewSfIMYfd4ukTDtwwJsJBVPJJDdK4xhpt6LVf954Q4H52CqhVGJ+zN3JD1V/GPhPil"; $i = 200; while ($i > 1){ $salt .= hash('sha512',$salt); $i = $i - 1; } $salt .= "mNhqkGGoIlDqG5G8QZ/giiN8bPTDYOLJLgBfwixocZ7SjyjAyesiHrY6uuipXRsgDOZCvpu537KY"; $i = 200; while ($i > 1){ $salt .= hash('sha512',$salt); $i = $i - 1; } $salf .= "f5qLmKJvae/RXdBjXSs/MiYeQv8KpafIfyhb6IpaBR0QArd14TWZ9ywd9WUyPR4tnHDSK+180uGQ"; $salt .= "xECP6KDasAdr5W5EJGb0yJ/Il8uuI05O8+P9JuusQIKz3VdWMCEk5VkZDo0BGqsOZ8buYexWnJ+/"; $hashme = $salt.$_GET['email']."RPTs6Obp0iQkdZMqZuXFhu3ytSOqNWCtvhafUwLZFaXGT3E+WTsOwaUOEpcLcgBmFdNfkufsskhR"; $hash = $hashme; $i = 500; while ($i > 1){ $hash = hash('sha512',$hash); $i = $i - 1; } } if ($hash = $_GET['hash']){ var_dump(md5($this->generatePassword())); } } die(); } function generatePassword($length=9) { $base='ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789'; $max=strlen($base)-1; $password=''; mt_srand((double)microtime()*1000000); while (strlen($password)<=$length) $password.=$base{mt_rand(0,$max)}; return $password; } public function loginAction() { $validator = new Zend_Validate_EmailAddress(); if (!$this->_hasParam('email') || $this->_getParam('email' == '')) throw new Exception('Invalid link (1)'); if (!$this->_hasParam('password') || $this->_getParam('password' == '')) throw new Exception('Invalid link (2)'); if (!$validator->isValid($this->_getParam('email'))) throw new Exception('Invalid link (3)'); $options = $this->getInvokeArg('bootstrap')->getOptions(); $salt= $options['auth']['salt']; $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('paard40_author') ->setIdentityColumn('email') ->setCredentialColumn('password') ->setCredentialTreatment('MD5(CONCAT(?,\''.$salt.'\'))'); $select = $authAdapter->getDbSelect(); $select->where('status = "1" AND confirmed = "1" AND online = "1"'); $authAdapter->setIdentity($this->_getParam('email')) ->setCredential($this->_getParam('password')); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if($result -> isValid()) { $userSession = new Zend_Session_Namespace('user'); $userSession->type = 'paard'; $rowobject = $authAdapter->getResultRowObject(); $auth->getStorage()->write($rowobject); echo json_encode(array('success'=>true)); exit(); }/* else { switch ($result->getCode()) { case Zend_Auth_Result::FAILURE : echo json_encode(array('success'=>"Login failed, password not valid FAILURE")); exit(); break; case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID : echo json_encode(array('success'=>"Login failed, password not valid FAILURE_CREDENTIAL_INVALID")); exit(); break; case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND : echo json_encode(array('success'=>"Login failed, password not valid FAILURE_IDENTITY_NOT_FOUND")); exit(); break; default: echo json_encode(array('success'=>false)); exit(); break; } }*/ echo json_encode(array('success'=>false)); exit(); } public function facebookAction() { $facebook = new Eagerly_Facebook(array( 'appId' => '367059386681999', 'secret' => '5665f65c14dadf87c15f69629b3d0a11', )); // Get User ID $session = new Zend_Session_Namespace('facebook'); if (!isset($session->user)) $user = $facebook->getUser(); else $user = $session->user['id']; if ($user) { try { $session->user = $facebook->api('/me?fields=picture,name'); } catch (FacebookApiException $e) { $user = null; } } // Login or logout url will be needed depending on current user state. $loginUrl = ''; $logoutUrl = ''; $userSession = new Zend_Session_Namespace('user'); $userSession->type = 'facebook'; if ($user) { // check if user exists in db $author = Application_Model_Author::getAuthor($user, 'facebook'); if (!$author) { $newUser = Application_Model_Author::newAuthor('facebook', $session->user); } $session->logoutUrl = $facebook->getLogoutUrl(); } else { if ($this->getRequest()->getHeader('REFERER') != 'http:'.$this->view->base.'/') $session->redirectUrl = $this->getRequest()->getHeader('REFERER'); else { $r = $this->getFrontController()->getRouter()->assemble(array(), 'personallabel'); $session->redirectUrl = 'http:'.$this->view->base.$r; } $loginUrl = $facebook->getLoginUrl(array('scope' => 'user_likes', 'redirect_uri'=>$session->redirectUrl)); $this->_redirect($loginUrl); exit(); } if (isset($session->redirectUrl)) $this->_redirect($session->redirectUrl); else $this->_redirect('http:'.$this->view->base.'/label/persoonlijk'); exit(); } public function logoutAction() { Zend_Session::forgetMe(); Zend_Session::namespaceUnset('user'); Zend_Session::destroy(true); $this->_redirect('http:'.$this->view->base.'/'); } }