D
D
Dmitry Kuznetsov2016-04-06 18:04:23
Laravel
Dmitry Kuznetsov, 2016-04-06 18:04:23

Work with authorization does not work correctly, what should I do?

I started making a site on L5 (just started) and got to authorization (I did it)).
Controller :

<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

## Модели
use App\Models\Forum\Forum; // Модель форума

use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Redirect;

class AuthController extends Controller{
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    protected $redirectTo = '/';

    public function __construct(){
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    protected function validator(array $data){
        return Validator::make($data, [
            'login_users' => 'required|min:4|max:60',
            'mail_users' => 'required|email|min:4|max:255|unique:users',
            'password' => 'required|min:6|confirmed:password_confirmation',
            'password_confirmation' => 'required|min:6',
            'iAgree' => 'accepted'
        ]);
    }

    ## Страница авторизация
    public function getLogin(){
        return view('Auth.getLogin');
    }

    public function postLogin(Request $request){
        $data = $request->all();
        $dataSave = $request->flashExcept('password');

        $v = $this->validator($data);

        if($v->fails()){
            // Если есть ошибки
            return redirect()->back()->withErrors($v->errors())->withInput($dataSave);
        }else{

        }
    }
}

Design :
<div class="control-group {{($errors->first('login_users') ? 'error' : '')}}">
    <label class="control-label" for="login_users">Логин:</label>
    <div class="controls">
        {{ Form::text('login_users', '', ['placeholder' => 'Введите ваш логин']) }}
        <span class="help-inline">{{($errors->first('login_users') ? $errors->first('login_users') : '')}}</span>
    </div>
</div>

<div class="control-group {{($errors->first('password') ? 'error' : '')}}">
    <label class="control-label" for="password">Пароль:</label>
    <div class="controls">
        {{ Form::password('password', ['placeholder' => 'Введите ваш пароль']) }}
        <span class="help-inline">{{($errors->first('password') ? $errors->first('password') : '')}}</span>
    </div>
</div>

<div class="control-group">
    <div class="controls">
        <button type="submit" class="btn btn-success">Войти</button>
    </div>
</div>

Everything seems to work, but an error is written to the password, they say the password does not match. What to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-04-07
@dima9595

In postLogin you check the validity of the authorization form with the rules for registration. so "Password not confirmed".

A
Andrzej Wielski, 2016-04-06
@wielski

What to do?

Do not fence the bike, and use the excellent built-in Auth

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question