PHP code example of hwacom / eip-login

1. Go to this page and download the library: Download hwacom/eip-login library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hwacom / eip-login example snippets


\Hwacom\EIPLogin\EIPLoginServiceProvider::class,

'eip_auth' => env('EIP_AUTH', false),
'eip_url' => env('EIP_URL'),
'JWT_EXP' => env('JWT_EXP', 900),
'CLIENT_SECRET' => env('EIP_CLIENT_SECRET'),
'COOKIE_DOMAIN' => env('COOKIE_DOMAIN'),

'model' => App\Models\User::class,

EIP_AUTH          = true
EIP_URL           = 
EIP_CLIENT_SECRET =
COOKIE_DOMAIN     =

php artisan breeze:install

php artisan migrate
bash
php artisan vendor:publish

class LoginController extends Controller
{
    use AuthenticatesUsers;

    public function __construct()
    {
        $this->loginService = new EIPLoginService();
    }

public function username()
{
    return 'enumber'; //帳號欄位名
}

/**
 * 進入login前function 判斷走login/loginEIP
 *
 */
public function store()
{
    if (config('eip.eip_auth')) { //EIP登入
            $data = [
                'ip'             => $request->ip(),
                'username'       => $request->enumber,
                'password'       => $request->password,
            ];
            $this->loginService->loginEIP($data);
            $path = Session::get('redirect) ?? '/';
            $request->session()->regenerate();
            return redirect($path);    
    } else {
        $this->login($request); //一般登入
    
        $request->session()->regenerate();
    
        return redirect()->intended(RouteServiceProvider::HOME);
    }
    
}

/**
 * 登出用需自行寫入LoginController中
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
 */
public function destroy(Request $request)
{
    if (config('sso.sso_enable') === true) {
        setcookie("token", "", time() - 3600, '/', '.hwacom.com');
    }

    Auth::guard('web')->logout();

    $request->session()->invalidate();

    $request->session()->regenerateToken();
    
    setcookie("token", "", time() - 3600, '/', config('eip.COOKIE_DOMAIN'));

    return redirect(config("sso.sso_host"));
}

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if (!config('eip.eip_auth')) {
            return [
                'enumber'  => '