2017-10-26 1 views
0

Ich habe dieses hier Code, der Mitglied Login-InformationenValidate zeigt Warnmeldungen bei gleichzeitig isset Nachricht

Aus irgendeinem Grund bestätigen sollte $this->error['warning'] zur gleichen Zeit auf zeigt sich hält, auch wenn der Eingangspost Benutzername oder Passwort ist nicht eingestellt.

Frage Wie stelle ich sicher, dass, wenn das Passwort und der Benutzername nicht auf die zweite Prüfung eingestellt sind, bis beide abgeschlossen sind.

enter image description here

public function validate() { 

    /* First Checks */ 
    if (!$this->input->post('username')) { 
     $this->error['username'] = 'You have missed the username input!'; 
    } 

    if (!$this->input->post('password')) { 
     $this->error['password'] = 'You have missed password input!'; 
    } 

    /* Second Checks */ 
    if (($this->input->post('password') != '') && ($this->input->post('username') != '')) { 

     if (!$this->member->login($this->input->post('password'), $this->input->post('username'))) { 
      $this->error['warning'] = 'In correct username or password!'; 
     } 

     if (!$this->member->approved($this->input->post('username'))) { 
      $this->error['warning'] = 'Your account not approved yet!'; 
     } 

    } 

    return !$this->error; 
} 

Voll-Controller

<?php 

class Login extends CI_Controller { 

    private $error = array(); 

    public function __construct() { 
     parent::__construct(); 
    } 

    public function index() { 

     $this->data['title'] = 'Members Login'; 

     if ($this->member->getmemberid()) { 
      redirect(base_url('admin/members/dashboard')); 
     } 

     if (($this->input->server('REQUEST_METHOD') == 'POST') && $this->validate()) { 

      redirect(base_url('admin/members/dashboard')); 
     } 

     if (isset($this->error['warning'])) { 
      $this->data['error_warning'] = $this->error['warning']; 
     } else { 
      $this->data['error_warning'] = ''; 
     } 

     if (isset($this->error['username'])) { 
      $this->data['error_username'] = $this->error['username']; 
     } else { 
      $this->data['error_username'] = ''; 
     } 

     if (isset($this->error['password'])) { 
      $this->data['error_password'] = $this->error['password']; 
     } else { 
      $this->data['error_password'] = ''; 
     } 

     if ($this->input->post('username')) { 
      $this->data['username'] = $this->input->post('username'); 
     } else { 
      $this->data['username'] = ''; 
     } 

     if ($this->input->post('password')) { 
      $this->data['password'] = $this->input->post('password'); 
     } else { 
      $this->data['password'] = ''; 
     } 


     $this->load->view('admin/template/common/header', $this->data); 
     $this->load->view('admin/template/member/login', $this->data); 
     $this->load->view('admin/template/common/footer'); 
    } 

    public function validate() { 
     if (!$this->input->post('username')) { 
      $this->error['username'] = 'You have missed the username input!'; 
     } 

     if (!$this->input->post('password')) { 
      $this->error['password'] = 'You have missed password input!'; 
     } 

     if (($this->input->post('password') != '') && ($this->input->post('username') != '')) { 

      if (!$this->member->login($this->input->post('password'), $this->input->post('username'))) { 
       $this->error['warning'] = 'In correct username or password!'; 
      } 

      if (!$this->member->approved($this->input->post('username'))) { 
       $this->error['warning'] = 'Your account not approved yet!'; 
      } 

     } 

     return !$this->error; 
    } 
} 

Antwort

0

Lösung

Es war ein einfacher Fehler kaufen verursacht nicht setzen

public $data = array(); 

An der Spitze oben Konstrukt jetzt so weit funktioniert

Verwandte Themen