CakePHP Wersja 1.2.5Komponent CakePHP Auth przy użyciu 2 tabel
Chciałbym, aby pojedynczy użytkownik miał wiele adresów e-mail.
Chciałbym, aby pojedynczy użytkownik miał jedno hasło.
Chciałbym, aby użytkownicy logowali się przy użyciu dowolnego z ich wielu adresów e-mail i ich pojedynczego hasła.
Utworzyłem tabelę użytkowników z polem id i hasłem.
Utworzyłem tabelę user_email_addresses z polem id a pole user_id i pole email_address.
Pytanie:
Jak zmodyfikować komponentu minimalnie auth szukać „username” w tym przypadku „email_address”, w tabeli user_email_addresses i „hasło” w tabeli użytkowników?
Wydaje się, że można to zrobić, modyfikując metodę identyfikacji w komponencie auth. Ale myślę, że modyfikowanie komponentu auth bezpośrednio jest złym pomysłem - wszelkie pomysły na to, jak rozszerzyć i ewentualnie zmodyfikować metodę identyfikacji? http://cakebaker.42dh.com/2009/09/08/extending-cakephps-core-components/ lub ewentualnie wyznaczyć inny obiekt uwierzytelniający?
linii startu 774:
function identify($user = null, $conditions = null) {
if ($conditions === false) {
$conditions = null;
} elseif (is_array($conditions)) {
$conditions = array_merge((array)$this->userScope, $conditions);
} else {
$conditions = $this->userScope;
}
if (empty($user)) {
$user = $this->user();
if (empty($user)) {
return null;
}
} elseif (is_object($user) && is_a($user, 'Model')) {
if (!$user->exists()) {
return null;
}
$user = $user->read();
$user = $user[$this->userModel];
} elseif (is_array($user) && isset($user[$this->userModel])) {
$user = $user[$this->userModel];
}
if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$this->userModel . '.' . $this->fields['username']]))) {
if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) {
if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') {
return false;
}
$find = array(
$this->userModel.'.'.$this->fields['username'] => $user[$this->fields['username']],
$this->userModel.'.'.$this->fields['password'] => $user[$this->fields['password']]
);
} elseif (isset($user[$this->userModel . '.' . $this->fields['username']]) && !empty($user[$this->userModel . '.' . $this->fields['username']])) {
if (trim($user[$this->userModel . '.' . $this->fields['username']]) == '=' || trim($user[$this->userModel . '.' . $this->fields['password']]) == '=') {
return false;
}
$find = array(
$this->userModel.'.'.$this->fields['username'] => $user[$this->userModel . '.' . $this->fields['username']],
$this->userModel.'.'.$this->fields['password'] => $user[$this->userModel . '.' . $this->fields['password']]
);
} else {
return false;
}
$model =& $this->getModel();
$data = $model->find(array_merge($find, $conditions), null, null, 0);
if (empty($data) || empty($data[$this->userModel])) {
return null;
}
} elseif (!empty($user) && is_string($user)) {
$model =& $this->getModel();
$data = $model->find(array_merge(array($model->escapeField() => $user), $conditions));
if (empty($data) || empty($data[$this->userModel])) {
return null;
}
}
if (!empty($data)) {
if (!empty($data[$this->userModel][$this->fields['password']])) {
unset($data[$this->userModel][$this->fields['password']]);
}
return $data[$this->userModel];
}
return null;
}
Dziękuję deizel - dokładnie to, czego szukałem! – BWelfel