Created
May 18, 2015 13:55
-
-
Save willianmano/9cfdff68624472cdde70 to your computer and use it in GitHub Desktop.
App\Http\Controllers\Auth\AuthController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Contracts\Auth\Guard; | |
use Illuminate\Contracts\Auth\Registrar; | |
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; | |
use Illuminate\Http\Request; | |
class AuthController extends Controller { | |
/* | |
|-------------------------------------------------------------------------- | |
| Registration & Login Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles the registration of new users, as well as the | |
| authentication of existing users. By default, this controller uses | |
| a simple trait to add these behaviors. Why don't you explore it? | |
| | |
*/ | |
// use AuthenticatesAndRegistersUsers; | |
protected $auth; | |
/** | |
* Create a new authentication controller instance. | |
* | |
* @param \Illuminate\Contracts\Auth\Guard $auth | |
* @param \Illuminate\Contracts\Auth\Registrar $registrar | |
* @return void | |
*/ | |
public function __construct(Guard $auth, Registrar $registrar) | |
{ | |
$this->auth = $auth; | |
$this->registrar = $registrar; | |
$this->middleware('guest', ['except' => 'getLogout']); | |
} | |
/** | |
* Show the application login form. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function getLogin() | |
{ | |
return view('auth.login'); | |
} | |
/** | |
* Handle a login request to the application. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function postLogin(Request $request) | |
{ | |
$this->validate($request, [ | |
'lgn_usuario' => 'required|min:3|alpha_dash', 'lgn_senha' => 'required|min:6', | |
]); | |
$credentials = [ | |
'lgn_usuario' => $request->input('lgn_usuario'), | |
'password' => $request->input('lgn_senha'), | |
'lgn_ativo' => 1 | |
]; | |
if ($this->auth->attempt($credentials, $request->has('remember'))) | |
{ | |
return redirect()->intended('/admin'); | |
} | |
return redirect('/auth/login') | |
->withInput($request->only('lgn_usuario', 'remember')) | |
->withErrors([ | |
'Usuário e/ou senha inválidos.', | |
]); | |
} | |
/** | |
* Log the user out of the application. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function getLogout() | |
{ | |
$this->auth->logout(); | |
return redirect('/'); | |
} | |
} |
Author
willianmano
commented
May 25, 2015
'required|email',
'lgn_usuario' => 'required|min:3|unique:login|alpha_dash',
'lgn_senha' => 'required|min:6',
);
/**
* Relacionamento 1x1 com a tabela assessor
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function assessor()
{
return $this->hasOne('App\Models\Assessor', 'ass_lgn_id');
}
/**
* Get the e-mail address where password reset links are sent.
*
* @return string
*/
public function getEmailForPasswordReset()
{
return $this->lgn_email;
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->lgn_senha;
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
return $this->lgn_remember_token;
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
* @return void
*/
public function setRememberToken($value)
{
$this->{$this->getRememberTokenName()} = $value;
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
return 'lgn_remember_token';
}
```
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment