Ich kann mich nicht mit der E-Mail-Adresse einloggen. Die Anmeldung erfolgt nur über den Benutzernamen. Wenn ich versuche, mich per E-Mail einzuloggen, leite ich mich zur Anmeldeseite um. Bitte helfen Sie mir, damit ich mich auch mit Email einloggen kann. Ich habe viele Online-Quellen überprüft, aber nicht hilfreich für mich.Einloggen mit Benutzername oder E-Mail in Code-Nummer
Meine Controller:
STORE_ACCOUNTS_CONTROLLER Funktion get_with_double_condition ($ col1, $ value1, $ col2, $ value2)
{
$this->load->model('mdl_store_accounts');
$query = $this->mdl_store_accounts->get_with_double_condition($col1, $value1, $col2, $value2);
return $query;
}
YOURACCOUNTS_CONTROLLER Funktion submit_login()
{
$this->load->module('site_security');
$this->load->module('store_accounts');
$submit = $this->input->post('submit',TRUE);
if ($submit=="Submit") {
//process the form
$this->load->library('form_validation');
$this->form_validation->set_rules('username','Username','required|min_length[5]|max_length[60]|callback_username_check');
$this->form_validation->set_rules('pword','Password','required|min_length[7]|max_length[35]');
if ($this->form_validation->run()==TRUE) {
//figure out user_id
$col1 = 'username';
$value1 = $this->input->post('username', TRUE);
$col2 = 'email';
$value2 = $this->input->post('email', TRUE);
$query = $this->store_accounts->get_with_double_condition($col1, $value1, $col2, $value2);
foreach ($query->result() as $row) {
$user_id = $row->id;
}
//send them to the private page
$this->_in_you_go($user_id, $login_type);
$remember = $this->input->post('remember', TRUE);
if ($remember=="remember-me") {
$login_type = "longterm";
}
else
{
$login_type = "shortterm";
}
}
else
{
echo validation_errors();
}
}
}
Funktion username_check ($ str)
{
$this->load->module('site_security');
$this->load->module('store_accounts');
$error_msg = "You did not enter a correct username and/or password.";
$col1 = 'username';
$value1 = $str;
$col2 = 'email';
$value2 = $str;
$query = $this->store_accounts->get_with_double_condition($col1, $value1, $col2, $value2);
$num_rows = $query->num_rows();
if ($num_rows<1) {
$this->form_validation->set_message('username_check', $error_msg);
return FALSE;
}
foreach ($query->result() as $row) {
$pword_on_table = $row->pword;
}
$pword = $this->input->post('pword', TRUE);
$result = $this->site_security->_verify_hash($pword, $pword_on_table);
if ($result==TRUE) {
return TRUE;
}
else
{
$this->form_validation->set_message('username_check', $error_msg);
return FALSE;
}
}
My Model:
STORE_ACCOUNTS_MODEL
Funktion get_with_double_condition ($ col1, $ value1, $ col2, $ value2)
{
$table = $this->get_table();
$this->db->where($col1, $value1);
$this->db->or_where($col2, $value2);
$query=$this->db->get($table);
return $query;
}
Meine Ansicht:
login_page
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form class="form-signin" action="<?= $form_location ?>" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputText" class="sr-only">Username or Email address</label>
<input type="text" name="username" value="<?= $username?>" id="inputEmail" class="form-control" placeholder="Username or Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="pword" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" name="remember" value="remember-me"> Remember me
</label>
</div>
<button name="submit" value="Submit" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
</div>
</div> <!-- /container -->
Ich versuche, E-Mail-Adresse und Benutzername nur durch den Benutzernamen post, deshalb habe ich doppelte Bedingung Modell. –
Das ist in Ordnung, aber dann können Sie nicht diese $ this-> input-> post ('E-Mail', TRUE); 'E-Mail nicht senden. –
Sie sollten dies sowohl für $ value1 als auch $ value2 verwenden '$ value2 = $ this-> input-> post ('Benutzername', TRUE);' –