本文整理汇总了PHP中App\Http\Controllers\Auth\Auth::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::validate方法的具体用法?PHP Auth::validate怎么用?PHP Auth::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Auth\Auth
的用法示例。
在下文中一共展示了Auth::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLogin
function postLogin(Request $request)
{
$email = $request->input('email');
$password = $request->input('password');
$userdata = array('email' => $email, 'password' => Hash::make($password));
// return Redirect::to('/basic');
if (Auth::validate($userdata)) {
if (Auth::attempt($userdata)) {
return Redirect::to('/basic');
}
} else {
// if any error send back with message.
Session::flash('error', 'Something went wrong');
return Redirect::to('login');
}
}
示例2: postChangePassword
public function postChangePassword(Request $request)
{
if (!\Auth::validate(['email' => \Auth::user()->email, 'password' => $request->input('old_password')])) {
\Alert::error(trans('auth.wrong_password'))->flash();
return redirect()->back();
}
// validation
$validator = \Validator::make($request->all(), ['old_password' => 'required', 'new_password' => 'required|confirmed|min:6']);
if ($validator->fails()) {
// The given data did not pass validation
return redirect()->back()->withInput()->withErrors($validator->errors());
}
// change the password
$user = User::findOrFail(\Auth::user()->id);
$user->password = $request->input('new_password');
$user->save();
// set a success/error message
\Alert::success(trans('auth.password_updated'))->flash();
// redirect to the change password page
return redirect()->back();
}
示例3: login
public function login()
{
// Getting all post data
$data = \Input::all();
// Applying validation rules.
$rules = array('email' => 'required|email', 'password' => 'required|min:6');
$validator = Validator::make($data, $rules);
if ($validator->fails()) {
// If validation falis redirect back to login.
return \Redirect::to('admin/login')->withInput(\Input::except('password'))->withErrors($validator);
} else {
$userdata = array('email' => \Input::get('email'), 'password' => \Input::get('password'));
// doing login.
if (\Auth::validate($userdata)) {
if (\Auth::attempt($userdata)) {
return \Redirect::intended('/categories');
}
} else {
// if any error send back with message.
\Session::flash('error', 'Something went wrong');
return \Redirect::to('admin/login');
}
}
}