wuifdesign / laravel-multiauth

MultiAuth for Laravel 5.0, 5.1
MIT License
7 stars 3 forks source link

Sample Pages #8

Closed masterpowers closed 9 years ago

masterpowers commented 9 years ago

Hi Can You Share A Working Login ,Logout , Password Reset , Register Views , Controller and Models?

Thanks

wuifdesign commented 9 years ago

there is a wiki about this: https://github.com/wuifdesign/laravel-multiauth/wiki/setup-information

and laraval already includes a working login/auth/passwordreset/register

masterpowers commented 9 years ago

Ive been testing out your Packages and Implementing Database Session but I got Somehow the users session being stored in sessions table except for the admins session its not being stored in the session table. Dont know if im doing wrong , or it is simple impossbile or im just lacking something.

You can view the whole Sample of Code at the link below I already posted in laracast for others help. https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5?page=1#

masterpowers commented 9 years ago

Here is a Sample when i Get a Session with Users Table

Route::get('/user', function(){
    $user = Auth::type('user')->LoginUsingId(1);
    return $user->name;

});

But when i Hit My Router to Login as Admin it Wont Return me a Session of that Admin

Route::get('/admin', function(){
    $admin = Auth::type('admin')->LoginUsingId(1);

    return $admin->name;

});

Here is my DatabaseSessionHandler

public function write($sessionId, $data)
    {
        $type = Auth::currentType();

        $user_id = (Auth::type($type)->check()) ? Auth::type($type)->id() : null;

        if ($this->exists) {
            $this->getQuery()->where('id', $sessionId)->update([
                'payload' => base64_encode($data), 'last_activity' => time(), 'user_id' => $user_id, 'user_type' => $type,
            ]);
        } else {
            $this->getQuery()->insert([
                'id' => $sessionId, 'payload' => base64_encode($data), 'last_activity' => time(), 'user_id' => $user_id, 'user_type' => $type,
            ]);
        }

        $this->exists = true;
    }

This is What my auth.php look like

<?php

return array(

    'default' => 'user',
    'multi' => array(
        'admin' => array(
            'driver' => 'eloquent', // either use eloquent or database here
            'model'  => App\Admin::class,
            'password' => [
                'email' => 'emails.admins.password', 
                // If you want to change the view for password reset for each auth type you can add this
                //If you dont add this line, Laravel will automatically use 
                // the default path for emails.password like its defined in the password array.
                // resources/views/emails/admins/password.blade.php
                // 
                // this piece of code is connected to CanResetPassword
            ]

        ),
        'user' => array(
            'driver' => 'eloquent',
            'model'  => App\User::class,
            'password' => [
                'email' => 'emails.users.password',
                // resources/views/emails/users/password.blade.php
            ]
        )
    ),

    'password' => array(
        'email' => 'emails.password',
        // this is the default path for password reset view
        // resources/views/emails/password.blade.php
        'table' => 'password_resets',
        'expire' => 60,
    ),
);
masterpowers commented 9 years ago

anyway might as well close this thread coz there is no error from my code from the very beginning it is working like a charm with your multi-auth :)

wuifdesign commented 9 years ago

ok, so i will close this :)