Skip to content

Instantly share code, notes, and snippets.

@fearrr
Created January 6, 2016 11:01
Show Gist options
  • Save fearrr/b95f0e3b3a73532b36a3 to your computer and use it in GitHub Desktop.
Save fearrr/b95f0e3b3a73532b36a3 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers\Auth;
use App\Models\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Http\Request;
use Auth;
class AuthController extends Controller
{
//Переопределяем маршрут переадресации после авторизации со стандартного /home
protected $redirectTo = '/personal/dashboard';
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
public function login(Request $request){
$v = Validator::make($request->all(), [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'user_type' => 'required|min:1|max:1|numeric',
'refer' => 'alpha_dash',
]);
if ($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
$email = $request->input('email');
$password = $request->input('password');
if($request->ajax()){
if (Auth::attempt(array('email' => $email, 'password' => $password))){
return 'success';
}
return 'failed';
}
else{
if (Auth::attempt(array('email' => $email, 'password' => $password))){
return redirect()->intended('personal/dashboard');
}
}
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'user_type' => 'required|min:1|max:1|numeric',
'refer' => 'alpha_dash',
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'refer' => $data['refer'],
'user_type' => $data['user_type'],
'email' => $data['email'],
'password' => $data['password'],
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment