在我的 L4 应用程序中,我使用子域来路由到不同的东西。
accounts.domain.com = where alle the Authentication stuff happens
dashboard.domain.com = The main frontpage for authenticated users
community.domain.com = Community stuff for authenticated users.
如果有人访问 community.domain.com/forum 并且没有被授权,他应该被发送到 accounts.domain.com,登录然后被重定向回论坛。
但现在我有两个问题。 1 和主要问题:登录后用户仅针对域进行验证:accounts.domain.com 对于所有其他域,他被重定向到登录名。 如果用户被授权并尝试访问 dashboard.domain.com,他将被重定向到登录页面。
2.问题是登录后的重定向。 Atm 我在登录后只有一个静态重定向,与用户来自哪里无关。我怎样才能改变它,以便他被重定向回他之前以未经身份验证的用户身份尝试访问的页面? 我的路线文件:
Route::get('login', function()
{
return Redirect::action('AccountsController@getLogin');
});
Route::group(array('domain' => 'accounts.domain.com'), function()
{
Route::get('/', function()
{
return Redirect::action('AccountsController@getLogin');
});
Route::get('users/sing_in', array('as' => 'login', 'uses' => 'AccountsController@getLogin'));
Route::post('users/sing_in', array('as' => 'login', 'uses' => 'AccountsController@doLogin'));
Route::get('users/sing_out', array('as' => 'logout', 'uses' => 'AccountsController@doLogout'));
Route::group(array('before' => 'auth'), function() {
Route::get('users/profile', array('as' => 'profile', 'uses' => 'AccountsController@getProfile'));
});
});
Route::group(array('domain' => 'dashboard.domain.com'), function()
{
Route::group(array('before' => 'auth'), function() {
Route::get('/', array('as' => 'dashhome', 'uses' => 'DashboardController@getIndex')); //If someone tries to access this, he get redirected to the login page, even if he just authenticated himself
});
});
还有我的登录 Controller :
public function getLogin()
{
if (Auth::check()) {
return Redirect::action('AccountsController@getProfile');
} else {
return View::make('login.index');
}
}
public function doLogin()
{
$rules = array(
'email' => 'required|email',
'password' => 'required|min:3'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::route('login')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata)) {
return Redirect::action('AccountsController@getProfile');
} else {
return Redirect::route('login')->withErros('Wrong E-mail address or Password');
}
}
}
public function doLogout()
{
Auth::logout(); // log the user out of our application
return Redirect::route('login'); // redirect the user to the login screen
}
感谢您的帮助。
最佳答案
设置domain在 app/config/session.php至 .domain.com , 因此 session 在子域之间共享。
要重定向用户,您可以返回 Redirect::back()或 Redirect::route(<wherever the user should land>) .
关于php - Laravel 4 身份验证不适用于子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284173/
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
当我使用has_one时,它工作得很好,但在has_many上却不行。在这里您可以看到object_id不同,因为它运行了另一个SQL来再次获取它。ruby-1.9.2-p290:001>e=Employee.create(name:'rafael',active:false)ruby-1.9.2-p290:002>b=Badge.create(number:1,employee:e)ruby-1.9.2-p290:003>a=Address.create(street:"123MarketSt",city:"SanDiego",employee:e)ruby-1.9.2-p290
我正在使用带有Rails的Devise,我想添加一个方法“getAllComments”,所以我这样写:classUser在我的Controller中:defdashboard@user=current_user@comments=@user.getAllComments();end当我访问我的url时,我得到了undefinedmethod`getAllComments'for#我做错了什么?谢谢 最佳答案 因为getAllComments是一个类方法,而您正试图将其作为实例方法访问。您要么需要访问它:User.getAllCom
我正在使用Rails3.2.3和Ruby1.9.3p0。我发现我经常需要确定某个字符串是否出现在选项列表中。看来我可以使用Ruby数组.includemethod:或正则表达式equals-tildematchshorthand用竖线分隔选项:就性能而言,一个比另一个好吗?还有更好的方法吗? 最佳答案 总结:Array#include?包含String元素,在接受和拒绝输入时均胜出,对于您的示例只有三个可接受的值。对于要检查的更大的集合,看起来Set#include?和String元素可能会获胜。如何测试我们应该根据经验对此进行测试
我正在尝试复制此GETcurl请求:curl-D--XGET-H"Authorization:BasicdGVzdEB0YXByZXNlYXJjaC5jb206NGMzMTg2Mjg4YWUyM2ZkOTY2MWNiNWRmY2NlMTkzMGU="-H"Content-Type:application/json"http://staging.example.com/api/v1/campaigns在Ruby中,通过电子邮件+apikey生成身份验证:auth="Basic"+Base64::encode64("test@example.com:4c3186288ae23fd9661c
Ruby初学者努力简单地将这个@@people散列的值打印到控制台classPerson#haveafirst_nameandlast_nameattributewithpublicaccessorsattr_accessor:first_nameattr_accessor:last_name#haveaclassattributecalled`people`thatholdsanarrayofobjects@@people=[]#havean`initialize`methodtoinitializeeachinstancedefinitialize(first_name,last_
我正在寻找用于Rails的优质管理插件。似乎大多数现有的插件/gem(例如“restful_authentication”、“acts_as_authenticated”)都围绕着self注册等展开。但是,我正在寻找一种功能齐全的基于管理/管理角色的解决方案——但不是简单地附加到另一个非基于角色的解决方案。如果我找不到,我想我会自己动手......只是不想重新发明轮子。 最佳答案 RyanBates最近做了两个关于授权的railscast(注意身份验证和授权之间的区别;身份验证检查用户是否如她所说的那样,授权检查用户是否有权访问资源
我需要在rail3中使用标准注册/登录/忘记密码功能进行身份验证。是否有大多数人为此使用的插件或其他东西? 最佳答案 我不确定最常用的方法是什么-但可以肯定的是,Plataformatec的“Devise”是一个非常流行的方法:http://github.com/plataformatec/devise我已经尝试了一些authgem,对我来说,它是最简单的设置和修改以满足我的需要。它内置了密码恢复、帐户确认(如果需要)和其他一些非常方便的功能。 关于ruby-on-rails-在Rail