/** * test host retrieval. * * @return void */ public function testHost() { $_SERVER['HTTP_HOST'] = 'localhost'; $request = new CakeRequest('some/path'); $this->assertEquals('localhost', $request->host()); }
/** * Test host retrieval. * * @return void */ public function testHost() { $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org'; $request = new CakeRequest('some/path'); $this->assertEquals('localhost', $request->host()); $this->assertEquals('cakephp.org', $request->host(true)); }
/** * Create new user * * @param email, password * @return void * @throws NotFoundException When the view file could not be found * or MissingViewException in debug mode. */ public function add() { //$this->authenticate_user(); //$this->authenticate_admin(); if ($this->request->is('post')) { $this->User->create(); try { $activate_token = sha1(time() . $userEmail . $userPassword); $userEmail = $this->request->data["User"]["email"]; $userPassword = sha1($this->request->data["User"]["password"]); $this->request->data["User"]["activate_token"] = $activate_token; //var_dump($this->request->data); //exit; if ($res = $this->User->saveAssociated($this->request->data)) { $admin_emails = array(); $this->User->recursive = -1; $conditions = array("User.role >" => 0); $admins = $this->User->find('all', array('conditions' => $conditions)); foreach ($admins as $u) { if ($u['User']['email'] != '') { array_push($admin_emails, $u['User']['email']); } } $mail = new CakeEmail(); $mail->template('notify_new_user', 'default')->subject('New user notification')->emailFormat('html')->to('*****@*****.**')->bcc($admin_emails)->from('*****@*****.**')->send(); $baseUrl = "http://" . CakeRequest::host() . $this->request->webroot; $activate_url = $baseUrl . "activate?token=" . $activate_token; $mail = new CakeEmail(); $mail->viewVars(array('activate_url' => $activate_url)); $mail->template('user_confirmation', 'default')->subject('Activate you account')->emailFormat('html')->to($userEmail)->from('*****@*****.**')->send(); //var_dump($userEmail); $this->redirect("/pages/after_sign_up"); } else { $errorOutput = ""; foreach ($this->User->validationErrors as $attr) { $this->Session->setFlash($this->User->validationErrors); foreach ($attr as $attrErrors) { $errorOutput .= $attrErrors . "\n"; } } $errorOutput = nl2br($errorOutput); $this->Session->setFlash($errorOutput, "flash_error"); $this->render('sign_up'); } } catch (Exception $e) { $this->Session->setFlash($e->getMessage(), "flash_error"); $this->redirect("/sign_up"); } } else { throw new ForbiddenException(); } }