vendredi 29 juillet 2016

MD5 Password login is not working laravel 5

I want to change my password field bcrypt to md5. In database i am storing password in md5 but login is not working

myController:

 public function postLogin(Request $request)
 {
   $this->validate($request, array('username' => 'required', 'password' => 'required'));
$credentials = $request->only('email', 'password');

if (Auth::validate($credentials)) 
{
    $user = Auth::getLastAttempted();
    Auth::login($user, $request->has('remember'));
    return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())
->withInput($request->only('email', 'remember'))
->withErrors([
    'email' => $this->getFailedLoginMessage(),
]);

}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2aiNtB0
via IFTTT

How to properly add external php files in Laravel 5

I have a small websockets chat written, the php part is just 2 files, server.php and Chat.php, they are both inside a bin folder and depend on ratchet and some other libraries which I downloaded to the laravel installation via composer.

server.php

require __DIR__.'/../vendor/autoload.php';
require 'Chat.php';

use Ratchet\Server\IoServer;
use Ratchet\http\HttpServer;
use Ratchet\WebSocket\WsServer;

$server = IoServer::factory(new HttpServer(new WsServer(new Chat)), 8080);

$server->run();

Chat.php

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {

    protected $clients;

    function __construct() {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) 
    {
        $this->clients->attach($conn);
    }

    public function onMessage(ConnectionInterface $conn, $msg) 
    {
        foreach ($this->clients as $client) 
        {
            if ($client !== $conn ) {
                $client->send($msg); 
            }
        }
    }

    public function onClose(ConnectionInterface $conn) 
    {
        $this->clients->detach($conn);
    }

    public function onError(ConnectionInterface $conn, \Exception $e) 
    {
        echo 'the following error occured: ' . $e->getMessage();
        $conn->close();
    }

}

Now, I have that bin folder inside the laravel root, and so I am able to start the server since the server.php is looking for dependencies in vendor one level up, but what I wanna do is use all the laravel goodies within these files, especially within Chat.php.

So now for example if I write use DB in Chat.php it gives an error (which I understand, it has no way of knowing laravel), so my question is how do I include this bin folder and its files so that I can use all the laravel goodies within them?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2anamnM
via IFTTT

Laravel Conditional Statement: is when() efficient?

I would like to know about the efficiency / performance of using Laravel's new Conditional Statements when() that comes in the Query Builder functions.

Are they more efficient than a simple variable condition?

Example: i am filtering results with some radio and checkboxes, and they will provide many conditionals, i would like to know the most efficient way of applying them:

Simple conditional:

if($request->has('sale')) $query = $query->sale();

Laravel Conditional statement:

 query->when($request->has('sale'), function ($query){
     return $query->sale();
 })

Thanks in advance, cheers.

Docs: http://ift.tt/1rTRTqH



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2an6938
via IFTTT

how to pass variables from database to custom error page in laravel

I want to pass variables to my custom error page but i can't do it so can anyone help me , that's my handler.php :

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        AuthorizationException::class,
        HttpException::class,
        ModelNotFoundException::class,
        ValidationException::class,
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(Exception $e)
    {
        parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if($e instanceof NotFoundHttpException)
    {
        return response()->view('errors.404', [], 404);
    }
    return parent::render($request, $e);
    }
}

so can anyone help me please to pass data to this page from database into the page ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2an5xus
via IFTTT

Laravel angular2-jwt template requests

I've an interesting question. I have setup a project using Laravel 5 and Angular2 with angular2-jwt. Laravel uses a JWT authentication library (http://ift.tt/1GFm4Yr) and produces tokens upon login, which are then sent over the vast Internet and saved to localStorage.setItem('id_token', response.token) the local machine.

Everything is working fine, but my Laravel controllers use jwt.auth, which requires my Angular2 component template requests to send with them the token. I'm a little lost here, since I seemingly cannot integrate the angular2-jwt library into my @component: templateUrl requests.

This means that I cannot request templates that should only be visible to logged in users, because the template request doesn't contain the token and thus is not authenticated to request those templates.

Can anybody advise or give me directions?

example component that I need to request a template for from Laravel with the jwt token attached to.

@Component ({
    selector: 'app-page',
    templateUrl: '/templates/Main.base',
    directives: [
        ROUTER_DIRECTIVES,
        HeaderComponent,
        UsersComponent,
        ProductsComponent
    ]
})



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2atW8Fk
via IFTTT

Storing validation rules alongside entries in the database in Laravel 5

I have a Setting model, and a SettingController. They are used for storing application-wide settings as a JSON string into the database.

Problem

Because of the diversity of setting types (checkboxes, inputs, email fields, etc), it is impossible to define the universal validation rules for each setting.

Possible Solution

To solve the problem of having "variable" validation rules, I'm considering storing them as a JSON string in the same table with settings.

Question

My question is, am I heading into the right direction, or am I making some major design flaws that can cause me pain in the future? And is it a good idea to store model's validations in the database?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2atWiMU
via IFTTT

How to display selected values from database to graphs

Actually i wanted to display 5 largest values from a column numberofclick in my database and create graphs for these top 5 data and also when howered shows id from id column so far i have done this....... im using laravel 5.2 and chart.js this is my controller

$click = Click::select(DB::raw("(numberofclick) as count"))

    ->orderBy("numberofclick")

    ->groupBy(DB::raw("(numberofclick)"))

    ->get()->toArray(); 

$click = array_column($click, 'count');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ahnKtF
via IFTTT