PDA

View Full Version : شخصی سازی سیستم اهراز هویت لاراول



tuytoosh
پنج شنبه 10 اردیبهشت 1394, 00:27 صبح
سلام به همگی
من میخوام در لاراول با نام کاربری و پسورد وارد سیستم شم و برای ثبت نام هم از نام ، نام کاربری و پسورد استفاده کنم.
برای این کار App\Http\Services\Registrar.php رو بصورت زیر اصلاح کردم :



<?php namespace App\Services;


use App\User;
use Validator;
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;


class Registrar implements RegistrarContract {


/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'username' => 'required|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}


/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'password' => bcrypt($data['password']),
]);
}


}



و Illuminate\Foundation\Auth\AuthenticatesAndRegiste rsUsers.php رو هم بصورت زیر اصلاح کردم


<?php namespace Illuminate\Foundation\Auth;


use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;


trait AuthenticatesAndRegistersUsers {


/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;


/**
* The registrar implementation.
*
* @var Registrar
*/
protected $registrar;


/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function getRegister()
{
return view('auth.register');
}


/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postRegister(Request $request)
{
$validator = $this->registrar->validator($request->all());


if ($validator->fails())
{
$this->throwValidationException(
$request, $validator
);
}


$this->auth->login($this->registrar->create($request->all()));


return redirect($this->redirectPath());
}


/**
* 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, [
'username' => 'required', 'password' => 'required',
]);


$credentials = $request->only('username', 'password');


if ($this->auth->attempt($credentials, $request->has('remember')))
{
return redirect()->intended($this->redirectPath());
}


return redirect($this->loginPath())
->withInput($request->only('username', 'remember'))
->withErrors([
'username' => $this->getFailedLoginMessage(),
]);
}


/**
* Get the failed login message.
*
* @return string
*/
protected function getFailedLoginMessage()
{
return 'These credentials do not match our records.';
}


/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function getLogout()
{
$this->auth->logout();


return redirect('/');
}


/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
{
if (property_exists($this, 'redirectPath'))
{
return $this->redirectPath;
}


return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}


/**
* Get the path to the login route.
*
* @return string
*/
public function loginPath()
{
return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login';
}


}



و توی دیتابیسمم فیلد username رو اضافه کردم و view هارو هم تغییر دادم...

ثبت نام کاربران به خوبی داره کار میکنه با همون نام ، نام کاربری و پسورد...

ولی برای ورود این اررور رو میده : The email field is required.

به نظر میرسه یه validation وجود داره که ملزم کنه کاربر رو به وارد کردن ایمیل... ولی من هیچ جا اونو پیدا نکردم...

به نظرتون مشکل کجاست؟

hamedarian2009
پنج شنبه 10 اردیبهشت 1394, 12:29 عصر
سلام خط ۸۹ رو به این صورت تغییر بدین ببینید درست میشه


$credentials = ['username' => $request->input('username'), 'password' => $request->input('password')];

tuytoosh
پنج شنبه 10 اردیبهشت 1394, 19:17 عصر
ربطی به اون نداره من کل تابع postLogin رو پاک کردم و یک پیام رو return کردم باز هم همین اررو رو میده...

public function postLogin(Request $request){
return "it is working";
}


انگار یه Request یه جایی وجود داره که ورودی های این درخواست رو چک میکنه قبلا... ولی نمیدونم این Request کجاست...

hamedarian2009
پنج شنبه 10 اردیبهشت 1394, 21:45 عصر
احتمالا فرم شما به یک اکشن دیگه فرستاده میشه در ضمن نیاز نبود اون کلاس رو تغییر بدین داخل کلاس کنترلر AuthController هم متد postLogin و سایر متدهارو میتونستید از دوباره بازنویسی کنید
به هرحال امکان این وجود نداره که جایی دیگه اعتبارسنجی بشه

Mahdi-563
پنج شنبه 17 اردیبهشت 1394, 08:55 صبح
شما باید تابع has لاراول را overwrite کنی من قبلا توی لاراول 4 کردم جواب داد