我的网站有多种身份验证用于不同目的。这里的授权不是正确的,因为对于每种认证都需要不同的数据,因此对于各种认证,单独的数据库表使用。
电子。 G。所有管理员都需要的是电子邮件和密码:电子邮件用作身份验证的ID。现在,要查看他们当前属于我自己网站的开发中的网站,客户还需要订单ID,客户名称,网站名称和别名数据。例如:
stivenson-gym.com
www.webmaster-example.com/orders/stivenson-gym/index.html
stivenson-gym
与管理员身份验证不同,此处订单ID (非客户名称)用于登录。
我已经意识到了:
现在我需要在浏览他的网站时让客户登录。
为什么Auth::attempt(['orderID' => $orderID, 'password' => $password])
不会使用?因为此方法引用Users
表,但我需要Orders
表。我无法更改Auth
的全局表格,因为管理员需要不同的表进行身份验证。
在理论上,解决方案将是:
我将在未经授权的情况下添加我当前的代码:
class LoginToSitesInDevelopmentZoneController extends Controller {
const SITE_IN_DEVELOPMENT_TABLE_NAME = 'site_in_dev';
const ORDER_ID_FIELD_NAME = 'order_id';
const PASSWORD_FIELD_NAME = 'password';
const SITENAME_FIELD_NAME = 'sitename';
const CUSTOMER_NAME_FIELD_NAME = 'customer_name';
const ALIAS_FIELD_NAME = 'alias';
public function login(Request $request) {
$inputtedOrderId = $request->input('order_id'); // from login form
// manual check is this order exists
$orderIdInDB = DB::table(self::SITE_IN_DEVELOPMENT_TABLE_NAME)
->where(self::ORDER_ID_FIELD_NAME, $inputtedOrderId)->first();
if (is_null($orderIdInDB)) {
return Redirect::route('loginToSitesInDevelopmentZonePage')->withErrors(['wrongOrderId' => true])->withInput();
}
// from login form
$inputtedPassword = $request->input('password');
// manual check the order id and password compilance
$bcryptedPasswordFromDB = DB::table(self::SITE_IN_DEVELOPMENT_TABLE_NAME)
->where(self::ORDER_ID_FIELD_NAME, $inputtedOrderId)->value(self::PASSWORD_FIELD_NAME);
if (!Hash::check($inputtedPassword,$bcryptedPasswordFromDB)) {
return Redirect::route('loginToSitesInDevelopmentZonePage')->withErrors(['wrongPassword' => true]);
}
// get respective alias
$alias = DB::table(self::SITE_IN_DEVELOPMENT_TABLE_NAME)
->where(self::ORDER_ID_FIELD_NAME, $inputtedOrderId)->value(self::ALIAS_FIELD_NAME);
// here I need to provide acess of the customer to all pages above 'sites_in_development_zone/'.$alias
return redirect('sites_in_development_zone/'.$alias.'/index.html');
}
}
提前感谢您的帮助。