Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
Server IP : 13.235.167.51  /  Your IP : 216.73.217.116
Web Server : Apache
System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64
User : root ( 0)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/app.machinox.in/app/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/app.machinox.in/app/Models/AdminUser.php
<?php

namespace App\Models;

use App\Helpers\UtilityHelper;
use App\Traits\UploadTrait;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Laravel\Sanctum\HasApiTokens;
use Ramsey\Uuid\Uuid;
use stdClass;

class AdminUser extends Model
{
    use HasApiTokens, HasFactory, Notifiable, SoftDeletes, UploadTrait;

    protected $fillable = [
        'uuid',
        'name',
        'mobile_number',
        'dial_code',
        'country_code',
        'email',
        'password',
        'is_admin',
        'profile_image',
        'status'
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
        'deleted_at',
        'updated_at',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];

    protected $appends = ['display_number'];

    public function getDisplayNumberAttribute()
    {
        if (strpos($this->dial_code, '+') === false) {
            $dialCode = '+' . $this->dial_code;
        } else {
            $dialCode = $this->dial_code;
        }

        return $dialCode . $this->mobile_number;
    }

    public function getProfileImageAttribute($value)
    {
        $folder = config('constants.PROFILE');
        return $this->getURL($folder, $value);
    }



    public function role()
    {
        return $this->hasOneThrough(
            Role::class,
            AdminRole::class,
            'user_id',
            'id',
            'id',
            'role_id'
        )->select("role_name", "roles.role_name as role", "roles.is_editable", "admin_roles.user_id", "admin_roles.role_id as id");
    }



    public static function GetInfoByUuid($id)
    {
        return self::where('uuid', $id)->with(['role'])->first();
    }

    public const PerPageRecord = 10;


    public static function FindById($id)
    {
        return self::where('id', $id)->first();
    }

    public static function GetInfoById($id)
    {
        return self::where('id', $id)->with(['role'])->first();
    }

    public static function ValidateEmail($email, $id = null)
    {
        return self::where('email', trim(strtolower($email)))
            ->when($id, function ($q) use ($id) {
                $q->where('id', '<>', $id);
            })
            ->first();
    }

    public static function ValidateEmailAddress($email, $uuid = null)
    {
        return self::where("email", $email)
            ->when(!is_null($uuid), function ($query) use ($uuid) {
                $query->where("uuid", "<>", $uuid);
            })
            ->first();
    }
    public static function ValidateMobileNumber($phoneNumber, $dial_code, $uuid = null)
    {
        return self::where("mobile_number", $phoneNumber)
            ->where("dial_code", $dial_code)
            ->when(!is_null($uuid), function ($query) use ($uuid) {
                $query->where("uuid", "<>", $uuid);
            })
            ->first();
    }

    public static function SetInfo($request, $id = null)
    {
        $email = getValue($request->input("email"));
        $mobile = getValue($request->input("mobile_number"));
        $dial_code = getValue($request->input("dial_code"));
        $checkUserEmail = self::ValidateEmailAddress($email, $id);

        if ($checkUserEmail) {
            throw new Exception(trans("messages.EMAIL_ALREADY_TAKEN"));
        }

        $checkUserMobile = self::ValidateMobileNumber($mobile, $dial_code, $id);
        if ($checkUserMobile) {
            throw new Exception(trans("messages.MOBILE_NUMBER_ALREADY_TAKEN"));
        }
        if ($id) {
            $data = self::where('uuid', $id)->first();
            if (!$data) {
                throw new Exception(trans("messages.USER_INFO_NOT_FOUND"));
            }
        } else {
            $data = new self;
            $data->uuid = Uuid::uuid4();
        }
        $data->status = getValue($request->input("status"), "ACTIVE");
        $data->name = getValue($request->input("name"));
        if($request->filled('password')){
            $data->password = Hash::make(getValue($request->input("password")));
        }
        $data->email = getValue($request->input("email"));
        $data->dial_code = getValue($request->input("dial_code"));
        $data->country_code = getValue($request->input("country_code"));
        $data->mobile_number = getValue($request->input("mobile_number"));
        $data->save();

        if ($request->has("role_id")) {
            AdminRole::where("user_id", $data->id)->delete();
            AdminRole::create(["user_id" => $data->id, "role_id" => getValue($request->input('role_id'))]);
        }


        $response = new stdClass;
        $response->id = $data->id;
        $response->uuid = $data->uuid;
        $response->message = trans("messages.RECORDS_SAVED_SUCCESSFULLY");
        return $response;
    }

    public static function ChangePassword($request, $id)
    {
        $data = self::where("uuid", $id)->first();
        if (!$data) {
            throw new Exception(trans("messages.USER_INFO_NOT_FOUND"));
        }
        $old_password = $request->input('old_password');
        if (Hash::check($old_password, $data->password)) {
            $password = $request->input('new_password');
            $data->password = Hash::make($password);
            $data->save();
        } else {
            throw new Exception("Sorry, Old Password is not matched");
        }
        $response = new stdClass;
        $response->message = "Password has been updated successfully.";

        return $response;
    }

    public static function GetAdminUsers($request)
    {
        $keyword = getValue($request->input('keyword'));
        $status = getValue($request->input('status'), "ALL");
        $offset = getValue($request->input('offset'), 0);
        $sort_by = getValue($request->input('sort_by'), 'created_at');
        $order_by = getValue($request->input('order_by'), 'DESC');

        $query = self::query()->with("role")->where("is_admin", "<>", 1)
            ->when($status != "ALL", function ($q) use ($status) {
                $q->where("status", $status);
            })

            ->when($keyword, function ($query) use ($keyword) {
                $query->Where('name', 'LIKE', '%' . $keyword . '%');
                $query->orWhere('email', 'LIKE', '%' . $keyword . '%');
                $query->orWhere('mobile_number', 'LIKE', '%' . $keyword . '%');
            })
            ->where("id", "<>", ADMIN_USER_ID())
            ->orderBy($sort_by, $order_by);

        $countQuery = (clone $query);
        $total = $countQuery->count();

        $perPage = self::PerPageRecord;
        $currentPage = max(1, (int)$offset + 1); // since your offset is page-indexed (0-based)
        $totalPages = $perPage > 0 ? (int) ceil($total / $perPage) : 0;

        $query->orderBy($sort_by, $order_by)
            ->offset($offset * $perPage)
            ->limit($perPage);

        $list = $query->get();
        $nextOffset = ($list->count() === $perPage && $currentPage < $totalPages) ? ($offset + 1) : -1;

        $data = [
            'count' => $total,
            'list' => $list,
            'current_page' => $currentPage,
            'next_offset' => $nextOffset,
            'per_page' => $perPage,
            'total_pages' => $totalPages,
        ];

        return $data;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit