HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers85/equichecker.com/app/KommaApp/Auth/AuthService.php
<?php

namespace KommaApp\Auth;

use KommaApp\Customers\Models\Customer;
use KommaApp\Users\Models\User;

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */
class AuthService
{
    /**
     * This method loads an account.
     * Based in the type it will select the correct table
     *
     * @param $type
     * @param $field
     * @param $value
     * @return mixed
     */
    public function getAccountBy($type, $field, $value)
    {
        switch ($type) {
            case 'user':
                $account = $this->getUserBy($field, $value);
                break;
            case 'customer' :
                $account = $this->getCustomerBy($field, $value);
                break;
        }

        return $account;

    }

    /**
     * This method loads an user.
     * Based on the field and value
     *
     * @param $field
     * @param $value
     * @return mixed
     */
    private function getUserBy($field, $value)
    {
        if (!$user = User::where($field, $value)->first()) {
            return false;
        }
        return $user;
    }


    /**
     * This method loads an Customer.
     * Based on the field and value
     *
     * @param $field
     * @param $value
     * @return mixed
     */
    private function getCustomerBy($field, $value)
    {
        if (!$user = Customer::where($field, $value)->first()) {
            return false;
        }
        return $user;
    }



    /**
     * Get an passwordReset from the db
     *
     * @param $type
     * @param $token
     * @return mixed
     */
    public function getPasswordResets($type, $token)
    {
        if (!$reset = \DB::table('password_resets')
            ->where('type', $type)
            ->where('token', $token)->first()
        ) {
            return false;
        }
        return $reset;
    }
    
    public function checkActive($type, $account){
        //Check if account is not active
        if ($account->active == 0) return false;


        //Type specific tests
        switch ($type){
            case 'customer':
                //If the account is not active yet
                if ($account->active_from >=  \Carbon\Carbon::now() ) return false;
                //If the account is not active anymore
                if ($account->active_until <=  \Carbon\Carbon::now() ) return false;
                break;
        }
        return true;
    }

}