cakePHP说服务器暂时无法为您的请求提供服务...登录后

时间:2014-08-26 09:07:20

标签: cakephp error-handling

我在cakephp中创建了一个简单的登录。起初一切正常,我能够登录和退出用户。然后我尝试使用电子邮件而不是用户名登录用户。请参阅以下文件:

login.ctp

<div class="col-md-8 col-md-offset-2">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><?php echo __('Login'); ?></h3>
        </div>
        <div class="panel-body">

                    <?php echo $this->Form->create('User'); ?>
                    <div class="form-group">
                        <label for="email"><?php echo __('E-Mail Adresse'); ?></label>
                    <?php 
                    echo $this->Form->input('email',array(
                        'label' => false,
                        'class' => 'form-control',
                        'placeholder' => 'E-Mail Adresse',
                        'required' => 'required',
                    )); 
                    ?>
                    </div>
                    <div class="form-group">
                        <label for="password"><?php echo __('Passwort'); ?></label>
                    <?php 
                    echo $this->Form->input('password',array(
                    'label' => false,
                    'class' => 'form-control',
                    'placeholder' => 'Passwort',
                    'required' => 'required',
                )); 
                    ?>
                    </div>
                    <?php 
                    echo $this->Form->end(array(
                        'label' => __('Einloggen'),
                        'class' => 'btn btn-block btn-lg btn-1'
                    ));
                    ?>

        </div>
    </div>
                <?php echo $this->html->link(
                    __('Du bist noch nicht dabei? Registriere dich hier.'),
                    array(
                    'controller' => 'users',
                    'action' => 'register',
                    'full_base' => true
                    )
                    ); 
                ?>
</div>

User.php(Model)

<?php
App::uses('AppModel', 'Model');
App::uses('SimplePasswordHasher', 'Controller/Component/Auth');

class User extends AppModel {

    public $validate = array(
        'email' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'An email is required'
            )
        ),
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            )
        ),
    );

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $passwordHasher = new SimplePasswordHasher();
            $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
        }
        return true;
    }
}
?>

UsersController.php

class UsersController extends AppController {

    public $components = array(
        'Session',
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        )
    );

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('register','logout','login');
        //$this->layout = 'auth';
    }

    public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {                
                $this->Session->setFlash(__('Willkommen').', <strong> '.$this->Auth->user('username').'</strong>','flash_alert_success');
                return $this->Auth->redirectUrl();
            }
            $this->Session->setFlash(__('Benutzername oder Passwort falsch. Bitte versuche es erneut.'),'flash_alert_error');
        }
    }

如果我现在尝试以testuser身份登录,cakephp会完全关闭,我只会看到: “服务暂时不可用

由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。请稍后再试。“

在白页上。

出了什么问题?为什么cakephp完全关闭?我甚至无法在我的error.log中找到任何内容...

有什么想法吗?

提前谢谢大家,

oligen

0 个答案:

没有答案