<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description"
          content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">

    <meta property="og:locale" content="en_US">
    <meta property="og:url" content="https://{{$currentDomain}}/settings">
    <meta property="og:type" content="website">
    <meta property="og:title" content="Editing {{ $user->username }} - Doxbin">
    <meta property="og:description"
          content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="Editing {{ $user->username }} - Doxbin">
    <meta name="twitter:description"
          content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">
    <meta name="twitter:url" content="https://{{$currentDomain}}/settings">
    <meta name="twitter:image" content="">
    <meta name="twitter:site" content="Doxbin">
    <meta name="twitter:creator" content="Doxbin">

    <title>Editing {{ $user->username }} - Doxbin (Admin)</title>

    <script src="{{ asset('/legacy/jquery.min.js') }}"></script>
    <script src="{{ asset('/legacy/jquery-ui-1.10.3.custom.min.js') }}"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="{{ asset('/legacy/logout.js') }}"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="{{ asset('/legacy/modal.js?r=47433') }}"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <style>
        .info-cont {
            font-size: 16px;
            color: #bfbfbf;
            margin: 0 auto;
            text-align: left;
        }

        .info-cont p {
            margin: 0;
        }

        .info-cont p b {
            margin-right: 6px;
        }

        .admin-text {
            color: red;
            font-weight: bold;
        }

        .profile-cont {
            margin-bottom: 50px;
            margin-top: 60px;
            padding-top: 1px;
        }

        .gray {
            color: #bfbfbf;
            margin-top: 5px;
        }

        .dropbtn {
            color: white;
            padding-top: 15px;
            border: none;
            cursor: pointer;
            color: #888888;
        }

        .dropdown {
            position: relative;
            display: inline-block;
            float: right;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            background-color: #303030;
            min-width: 110px;
            box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
            z-index: 1;
            border-radius: 3px;
            right: 0;
        }

        .dropdown-content a {
            color: white;
            padding: 4px 10px;
            text-decoration: none;
            display: block;
        }

        .dropdown-content a:hover {
            color: gray;
            text-decoration: none;
        }

        .dropdown:hover .dropdown-content {
            display: block;
        }

        .dropbtn:hover {
            color: white;
        }

        .admin-text {
            color: red;
            font-weight: bold;
        }

        .profile-img {
            width: 120px;
            height: 120px;
            background-color: gray;
            left: 0;
            right: 0;
            margin: 0 auto;
            -webkit-box-shadow: inset 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
            -moz-box-shadow: inset 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
            box-shadow: inset 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
            border-radius: 2px;
        }

        #profile-image {
            display: block;
            width: 120px;
            height: 120px;
            background-color: black;
            opacity: 0;
            transition: opacity .1s ease-in-out;
            -moz-transition: opacity .1s ease-in-out;
            -webkit-transition: opacity .1s ease-in-out;
            left: 0;
            right: 0;
            position: absolute;
            cursor: pointer;
            margin: 0px auto 0px auto;
        }

        #profile-image:hover {
            opacity: 0.7;
        }

        #file-upload-banner {
            height: 0px;
            padding: 0;
        }

        #profile-image p {
            padding-top: 45px;
            text-align: center;
            font-size: 18px;
            color: white;
        }

        input, textarea {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
            width: 100%;
            font-size: 100%;
            margin-bottom: 30px;
        }

        input::placeholder, textarea::placeholder {
            color: rgb(167, 167, 167);
        }

        input[type=submit] {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
            width: 90%;
            margin: 15px auto 50px auto;
        }

        input[type=submit]:hover {
            color: white;
            background: #3d3d3d;
            text-decoration: none;
        }

        .username-change {
            width: 100%;
        }

        .username-change a {
            position: absolute;
            padding-top: 8px;
            right: 25px;
            display: block;
            font-size: 15px;
        }

        input:disabled, textarea:disabled {
            color: #757575;
        }

        textarea {
            max-height: 58px;
            max-width: 100%;
            resize: none;
        }

        input[type="file"] {
            opacity: 0;
            cursor: pointer;
        }

        #file-upload {
            height: 0px;
            padding: 0;
        }

        .button {
            line-height: 1.2;
            color: white;
            background: #b21c1c;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 5px 5px 3px 5px;
            vertical-align: top;
            margin-top: 8px;
        }
		
        .button-green {
            line-height: 1.2;
            color: white;
            background: #0c4a18;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 5px 5px 3px 5px;
            vertical-align: top;
            margin-top: 8px;
        }

        .button:hover {
            text-decoration: none;
            color: white;
            background: #8c1c1c;
        }

        @-webkit-keyframes fadeIn {
            0% {
                opacity: 0;
                transform: scale(0.6);
            }

            100% {
                opacity: 100%;
                transform: scale(1);
            }
        }

        @keyframes fadeIn {
            0% {
                opacity: 0;
            }
            100% {
                opacity: 100%;
            }
        }

        .modalContainer {
            display: none;
        }

        .modalContainer .modal-background {
            background-color: rgba(0, 0, 0, 0.4);
            position: fixed;
            width: 100%;
            height: 100vh;
            left: 0;
            top: 0;
        }

        .modalContainer .modal-container {
            height: 180px;
            width: 380px;
            position: fixed;
            background-color: #383838;
            top: 50%;
            left: 50%;
            margin-top: -140px;
            margin-left: -190px;
            border-radius: 5px;
            color: #cecece;
            padding: 25px 20px;
            font-size: 15px;
            box-shadow: 0 0 30px #0d0e14;
        }

        .modalContainer .modal-container .confirm, .confirm {
            background-color: green;
            color: white;
            font-size: 15px;
            font-weight: bold;
            padding: 7px 10px;
        }

        .modalContainer .modal-container .confirm:hover, .confirm:hover {
            background-color: #1b6610;
        }

        .modalContainer .modal-container .cancel {
            background-color: gray;
            font-size: 15px;
            font-weight: bold;
            padding: 7px 10px;
        }

        select, option {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
            width: 200px;
        }

        select, option {
            font-size: 100%;
        }

        .wcon {
            background-color: #1f1f1f;
            width: 100%;
            border-radius: 5px;
            margin: 0 0 20px;
            box-shadow: 0 1px 3px #0a0b0d;
            padding: 10px 20px;
            position: relative;
            display: inline-block;
            -webkit-box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, 0.75);
            -moz-box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, 0.75);
            box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, 0.75);
            text-align: right;
        }

        .wcon p {
            margin-bottom: 3px;
        }

        div.tfa-actions {
            width: 100%;
            margin-bottom: 20px;
            position: relative;
            display: flex;
            flex-wrap: wrap;
        }

        .tfa-actions .tfa-col {
            width: 30%;
            margin: 0 auto;
            display: inline-block;
            text-align: center;
            color: #bfbfbf;
            padding: 4px;
            position: relative;
            font-size: 13px;
            border-bottom: 1px solid #282828;
            border-top: 1px solid #282828;
        }

        span.tfa-btn {
            font-size: 16px;
            display: inline-block;
            vertical-align: center;
            position: absolute;
            margin: 1px 0 0 5px;
            cursor: pointer;
            color: white;
            user-select: none;
        }

        .tfa-col h5 {
            font-size: 15px;
            margin: 2px 0;
        }

        .tb {
            width: 100%;
            border: solid 1px rgb(70, 70, 70);
        }

        .tb .tb-row {
            border-top: solid 1px rgb(70, 70, 70);
            width: 100%;
        }

        .tb .tb-row td {
            font-size: 13px;
            padding: 1px 0;
            color: rgb(199, 199, 199)
        }

        .tb > .tb-row:last-of-type {
            border-bottom: solid 1px gray;
        }

        .tb .tb-row p {
            margin-top: 0;
        }

        .tb .tb-row .product-name {
            font-size: 15px;
            font-weight: bold;
        }

        .tb th {
            font-size: 14px;
        }

        .tb .smaller {
            width: 1%;
            white-space: nowrap;
        }

        .tb .tb-row td:first-of-type, .tb th:first-of-type {
            padding-left: 4px;
        }

        .tb .tb-row td:last-of-type, .tb th:last-of-type {
            padding-right: 4px;
        }

        .tb .tb-row:hover {
            background-color: rgb(61, 61, 61);
        }
    </style>
    <link rel="stylesheet" href="/legacy/index.css">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
    <script>
        var uid = {{ $user->id }};
    </script>
</head>

<body class="bin" style="height: 100%; margin: 0 auto;">
{!! csrf_field() !!}
@include('_nav')
<div class="container"
     style="background-color: #111111; text-align: center; min-height: 100%; -webkit-box-shadow: 0px 0px 7px 0px rgba(31,31,31,1);-moz-box-shadow: 0px 0px 7px 0px rgba(31,31,31,1);box-shadow: 0px 0px 7px 0px rgba(31,31,31,1);">

    <div class="profile-cont">
        @if(!$canEditUser)
            <h5>You can't edit this user.</h5>
        @else
            <h5 class="gray" style="font-size: 20px;"><a href="/user/{{ $user->username}}">{{ $user->username }}</a>
            </h5>
            <label id="profile-image" for="file-upload">
                <p>Change</p>
            </label>


            <form id="pfp-form" action="" method="POST">
                <input id="file-upload" name="image" type="file" accept="image/*"/>
                {!! csrf_field() !!}
                <input type="hidden" name="type" value="image">
                {{-- 
                Reiko - Mar 14th 2024
                Added this to allow for $photokey in AdminController.php to change PFP's
                --}}
                <input type="hidden" name="modal" value="profile_pic">
            </form>
            <div class="profile-img" style="overflow-y: hidden;">
                <img class="profile-img-src" style="width: 120px;"
                     src="https://{{env('CDN_DOMAIN')}}/profile_pic/{{ $user->profile_pic != null ? $user->profile_pic : 'default.jpg'}}">
            </div>


            <a href="#" id="profile-pic-edit"
               style="font-weight: bold; font-size: 15x; @if($user->profile_pic == null) display: none; @endif">Remove</a>

            <p id="image-err-msg" style="color: red;"></p>


            <div class="col-md-5" style="float: none; margin: 10px auto 0;">
                <div class="wcon">
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">User ID</b></p>
                    <p>{{ $user->id }}</p>
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Created</b></p>
                    <p>{{ age($user->joindate) }}</p>
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Last seen</b></p>
                    <p>{{ $user->last_seen != null ? age($user->last_seen) : 'No records' }}</p>
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Pastes</b></p>
                    <p>{{ DB::table('pastes')->where('created_by', $user->id)->count() }}</p>
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Comments</b></p>
                    <p style="margin:0">{{ DB::table('comments')->where('created_by', $user->id)->count() }}</p>
                    <hr style="margin: 5px 0; border-color: #6f2121;">
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Found in breach?</b></p>
                    <p style="margin:0">{{ $affectedInBreach ? 'Yes' : 'No' }}</p>
                    <p style="margin: 0; float: left"><b style="margin-right: 10px">Requires password reset?</b></p>
                    <p style="margin:0">{{ $requiresPasswordReset ? 'Yes' : 'No' }}</p>
                    <hr style="margin: 5px 0; border-color: #6f2121;">
                    @if($user->role == RoleId::COUNCIL)
                        @php
                            $flags = DB::table('flags')->where('uid', $user->id)->get();
                            $totalflags = $flags->count();
                            $acceptedflags = $flags->where('status', 1)->count();
                            $deniedflags = $flags->where('status', 2)->count();
                        @endphp
                        <br>
                        <p style="margin: 0; float: left"><b style="margin-right: 10px">Total Flags</b></p><p
                                style="margin:0">{{ $totalflags }}</p>
                        <p style="margin: 0; float: left"><b style="margin-right: 10px">Accepted Flags</b></p><p
                                style="margin:0">{{ $acceptedflags }}</p>
                        <p style="margin: 0; float: left"><b style="margin-right: 10px">Denied Flags</b></p><p
                                style="margin:0">{{ $deniedflags }}</p>

                    @endif
                </div>
            </div>

            <h5 class="gray" style="font-size: 24px;"></h5>
            <div class="col-md-6 info-cont" style="float: none;">
                <div class="username-change">
                    <p><b>Username</b></p>
                    <a id="change-username" href="#">Change</a>
                    <input id="setting-username" type="text" value="{{$user->username}}" style="margin-bottom: 20px;"
                           disabled>
                </div>
                <div class="username-change">
                    <p><b>Bio</b></p>
                    <a id="change-bio" href="#">Edit</a>
                    <textarea id="setting-bio" style="margin-bottom: 20px; height: 70px"
                              disabled>{{$user->bio}}</textarea>
                </div>
                <div class="username-change">
                    <p><b>Email</b></p>
                    <a id="change-email" href="#">Change</a>
                    @php
                        if (!$myUser->isManager(true)) {
                            $user->email = "No permission to view, please contact Demeter or Pierce.";
                        }
                    @endphp
                    <input id="setting-email" type="text" value="{{$user->email}}" style="margin-bottom: 20px;"
                           disabled>
                </div>
                <hr style="margin-bottom: 10px;">
                @if ($myUser->isManager(true))
                    <h5 style="font-size: 18px;">Role</h5>
                    Change the user's role.<br>
                    @php
                        $role = 0;
                        if (!$user->isCouncil(true)) {
                            $role = $user->role;
                        } else if ($user->admin) {
                            $role = RoleId::ADMIN;
                        } else if ($user->is_manager) {
                            $role = RoleId::MANAGER;
                        } else if ($user->mod) {
                            $role = RoleId::MOD;
                        } else if ($user->is_developer) {
                            $role = RoleId::DEVELOPER;
                        } else if ($user->council) {
                            $role = RoleId::COUNCIL;
                        }
                    @endphp
                    <label style="margin-bottom: 10px;">Roles</label><br>
                    <select style="margin-right: 10px;" name="role">
                        <option {{ ($role == 0 ? 'selected' : '') }} value="0">Member</option>
                        @foreach($roles as $rank)
                            <option {{ ($role == $rank->id ? 'selected' : '') }} value="{{ $rank->id }}">{{ $rank->name }}</option>
                        @endforeach
                        <option disabled>========</option>
                        <option {{ $role == RoleId::COUNCIL ? 'selected' : '' }} value="{{ RoleId::COUNCIL }}">Council</option>
                        <option {{ $role == RoleId::MOD ? 'selected' : '' }} value="{{ RoleId::MOD }}">Mod</option>
                        <option {{ $role == RoleId::DEVELOPER ? 'selected' : '' }} value="{{ RoleId::DEVELOPER }}">Developer</option>
                        <option {{ !$myUser->isAdmin(true) ? 'disabled' : '' }} {{ $role == RoleId::MANAGER ? 'selected' : '' }} value="{{ RoleId::MANAGER }}">Manager</option>
                    </select>
                    <a id="update-rank" class="button confirm" href="#" style="padding: 8px 5px 7px; margin-top: 0px;">Update</a>
                @endif

                <hr style="margin-bottom: 10px;">
                <h5 style="font-size: 18px;">Upgrade User</h5>
                <span>Add/remove upgrades to user.</span><br><br>
                <label style="margin-bottom: 00px;">Upgrades</label><br>
                <input type="checkbox" name="notifyUser" id="notifyUser" style="width: auto;width: 15px;"
                       checked="checked"> <label for="notifyUser" style="font-size: 15px;">Notify user?</label><br>
                <select style="margin-right: 10px;" name="product">
                    <option selected="selected" value="0">[None]</option>
                    @foreach($products as $product)
                        <option value="{{ $product->id }}">{{ ($product->id == 1 ? ($user->has_name_color ? '[Owned] ' : '') : ($user->role == $product->id - 1 ? '[Owned] ' : '')) . $product->title }}</option>
                    @endforeach
                </select>
                <a id="update-upgrade" class="button confirm" href="#" style="padding: 8px 5px 7px; margin-top: 0px;">Save</a>


                <hr style="margin-bottom: 10px;">
                <h5 style="font-size: 18px;">Order History</h5>
                <span>Order history of the user. (Limited to 10)</span><br><br>
                <label style="margin-bottom: 0;">Orders <a href="/admin/logs/orders?search=1&userid={{ $user->id }}">(View
                        All)</a></label>
                @php
                    $products = [1 => 'Change name color', 2 => 'VIP rank', 3 => 'Criminal rank', 4 => 'Rich rank'];
                @endphp
                @if(count($orderHistory) > 0)
                    <table class="tb">
                        <tr>
                            <th>Product</th>
                            <th class="text-center">Price</th>
                            <th class="text-center">Status</th>
                            <th class="text-center">Created</th>
                            <th class="text-right">View</th>
                        </tr>
                        @foreach($orderHistory as $order)

                            <tr class="tb-row">
                                <td>{{ $products[$order->product_id] }}</td>
                                <td class="smaller">${{ empty($order->price) ? '-' : $order->price }}</td>
                                <td class="smaller text-center"
                                    style="padding: 0 10px;">{{ str_replace('Invoice', '', $order->status) }}</td>
                                <td class="smaller text-center">{{ Carbon\Carbon::parse($order->created_at)->format('Y-m-d H:i') }}</td>
                                <td class="smaller text-center" style="padding-left: 10px;"><a
                                            href="/admin/logs/orders?search=1&orderid={{$order->order_id}}&limit=50"
                                            style="color: #2a9fd6;">[View]</a></td>
                            </tr>
                        @endforeach
                    </table>
                @else
                    <p>No orders found</p>
                @endif
                <hr style="margin-bottom: 10px;">


                <h5 style="font-size: 18px;">Username History</h5>
                <span>History of name changes</span><br><br>
                <label style="margin-bottom: 0;">Username Changes <a
                            href="/admin/logs/usernames?search=1&userid={{ $user->id }}">(View All)</a></label>
                @if(count($usernameHistory) > 0)
                    <table class="tb">
                        <tr>
                            <th style="max-width: 50%;">From</th>
                            <th>To</th>
                            <th class="text-center">Changed</th>
                        </tr>
                        @foreach($usernameHistory as $usernameInfo)

                            <tr class="tb-row">
                                <td>{{ $usernameInfo->username_before }}</td>
                                <td>{{ $usernameInfo->username_after }}</td>
                                <td class="smaller text-center">{{ Carbon\Carbon::parse($usernameInfo->changed_at)->format('Y-m-d H:i') }}</td>
                            </tr>
                        @endforeach
                    </table>
                @else
                    <p>No previous usernames</p>
                @endif

                <hr style="margin-bottom: 10px;">
                <h5 style="font-size: 18px;">Password Reset</h5>
                <p id="password-error" style="color: red;"></p>
                <p>Generates a link that {{ $user->username }} can use to reset their password. All links expire after a
                    week if not used.</p><br>
                <p style="font-size: 14px;"><b>Current Link</b></p>
                @if($reset == null)
                    <div id="password-reset-link">
                        <p style="font-size: 14px; color: red;">None</p>
                    </div>
                    <a id="password-reset" href="#" style="text-align: left;">Generate Password Reset Link</a>
                    <a id="password-reset-delete" style="display: none;" href="#">Delete Link</a>
                @else
                    <div id="password-reset-link">
                        <input onclick="this.focus();this.select()" style="font-size: 12px; color: green;"
                               value="https://{{$currentDomain}}/password-reset/{{ $reset[0]->link }}" readonly>
                    </div>
                    <a id="password-reset" href="#" style="display: none; text-align: left;">Generate Password Reset
                        Link</a>
                    <a id="password-reset-delete" href="#">Delete Link</a>
                @endif
                <hr style="margin-bottom: 10px;">
                @if ($myUser->isManager(true))
                    <h5 style="font-size: 18px;">Two Factor Authentication</h5>
                    <h6 style="margin-bottom: 3px; text-align: center;">Information</h6>
                    <div class="tfa-actions">
                        <div class="tfa-col">
                            @if ($user->tfa_enabled)
                                <h5>Enabled</h5><span id="tfa-enabled">Yes</span> <span class="material-icons tfa-btn"
                                                                                        id="tfa-enabled-btn"
                                                                                        onclick="modal('Disable 2FA ({{ $user->username }})', 'Are you sure you want to disable 2FA?', '', 'Confirm', 'Cancel', 'disable2FA')">create</span>
                            @else
                                <h5>Enabled</h5><span id="tfa-enabled">No</span>
                            @endif
                        </div>
                        <div class="tfa-col">
                            <h5>Forced</h5><span
                                    id="tfa-forced">{!! ($user->tfa_forced || $user->role >= RoleId::COUNCIL ? 'Yes' : 'No') !!}</span>@if($user->role < RoleId::COUNCIL)
                                <span class="material-icons tfa-btn" id="tfa-forced-btn">create</span>
                            @endif
                        </div>
                        <div class="tfa-col">
                            <h5>Authed</h5><span
                                    id="tfa-authed">{!! ($user->tfa_auth ? 'Yes' : 'No') !!}</span> @if($user->tfa_enabled || $user->tfa_forced || $user->role >= RoleId::COUNCIL)
                                <span class="material-icons tfa-btn" id="tfa-authed-btn"
                                      onclick="modal('2FA ({{ $user->username }})', 'Are you sure you want to (de)authorise this user?', '', 'Confirm', 'Cancel', 'auth2FA')">create</span>
                            @endif
                        </div>
                    </div>
                    <hr style="margin-bottom: 10px;">
                @endif
                <h5 style="font-size: 18px;">Session</h5>
                {{-- Frontend view of the delete session button --}}
                @if($user->session != null)
                    <p>Active session - Expires in {{ in($user->sess_end) }}</p>

                    <span style="cursor: pointer;" class="button"
                        onclick="modal('Delete Session', 'Are you sure you want to delete {{ $user->username }}\'s session?', '', 'Confirm', 'Cancel', 'sessionDelConfirm')">Delete Session</span>
                @else
                    No active session.
                @endif
                @if ($myUser->isManager(true))
                    <hr style="margin-bottom: 10px;">
                    <h5 style="font-size: 18px;">Delete Account</h5>
                    <p>Permanently delete account</p>
                    <span style="cursor: pointer;" class="button"
                          onclick="modal('Delete Account', 'Are you sure you want to delete {{ $user->username }}\'s account?', '', 'Confirm', 'Cancel', 'deleteConfirm')">Delete Account</span>
                @endif
                {{-- Frontend view of the lock account button --}}
                @if ($myUser->isDeveloper() || $myUser->isManager(true))
                    <hr style="margin-bottom: 10px;">
                    <h5 style="font-size: 18px;">Lock Account</h5>
                    @if($user->locked == 0)
                        <p>Would you like to lock this user's account?</p>
                        <span style="cursor: pointer;" class="button"
                          onclick="modal('Lock Account', 'Are you sure you want to lock {{ $user->username }}\'s account?', '', 'Confirm', 'Cancel', 'lockAccConfirm')">Lock Account</span>
                    @else
                    <p>Account is locked. Would you like to unlock?</p>
                    <span style="cursor: pointer;" class="button-green"
                          onclick="modal('Unlock Account', 'Are you sure you want to unlock {{ $user->username }}\'s account?', '', 'Confirm', 'Cancel', 'unlockAccConfirm')">Unlock Account</span>
                    @endif
                @endif
                @endif

            </div>
    </div>
</div>
<script>
    var file = "none";
    var tfaforced = {{ (int)($user->tfa_forced || $user->role >= RoleId::COUNCIL) }};
    var tfaauthed = {{ (int)$user->tfa_auth }};

    function auth2FA() {
        $('#tfa-authed').text('...');
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'auth-2fa',
            value: (tfaauthed ? 1 : 0)
        }, function (resp) {
            if (resp.status == "done") {
                $('#tfa-authed').text(tfaauthed ? 'No' : 'Yes');
                tfaauthed = !tfaauthed;
                $('#tfa-authed').css('color', '#00FF00').animate({color: "#bfbfbf"}, 3000);
            } else {
                alert(resp.msg);
            }
        });
    }

    $('#tfa-forced-btn').on('click', function (e) {
        $('#tfa-forced').text('...');
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'force-2fa',
            value: (tfaforced ? 1 : 0)
        }, function (resp) {
            if (resp.status == "done") {
                $('#tfa-forced').text(tfaforced ? 'No' : 'Yes');
                tfaforced = !tfaforced;
                $('#tfa-forced').css('color', '#00FF00').animate({color: "#bfbfbf"}, 3000);
            } else {
                alert(resp.msg);
            }
        });
    });

    function disable2FA() {
        $('#tfa-enabled').text('...');
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'disable-2fa',
        }, function (resp) {
            if (resp.status == "done") {
                $('#tfa-enabled').text('No');
                $('#tfa-enabled-btn').remove();
                $('#tfa-enabled').css('color', '#00FF00').animate({color: "#bfbfbf"}, 3000);
            } else {
                alert(resp.msg);
            }
        });
    }

    function deleteConfirm() {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'delete',
        }, function (resp) {
            if (resp.status == "done") {
                alert("Successfully deleted account.");
                window.location = '/admin/users';
            } else if (resp.msg == "You have no permission, contact Operator.") {
                alert("You have no permission, contact Operator.");
            } else {
                alert(resp.msg);
            }
        });
    }

    function sessionDelConfirm() {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'deletesession',
        }, function (resp) {
            if (resp.status == "done") {
                alert("Successfully deleted session.");
                window.location.reload(); // This will reload back onto the user page
            } else if (resp.msg == "You have no permission, contact Operator.") {
                alert("You have no permission, contact Operator.");
            } else {
                alert(resp.msg);
            }
        });
    }
    function lockAccConfirm() {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'lockaccount',
        }, function (resp) {
            if (resp.status == "done") {
                alert("Successfully locked account.");
                window.location.reload(); // This will reload back onto the user page
            } else if (resp.msg == "Nice try, nigga.") {
                alert("NOT HAPPENING G");
            } else {
                alert(resp.msg);
            }
        });
    }

    function unlockAccConfirm() {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'unlockaccount',
        }, function (resp) {
            if (resp.status == "done") {
                alert("Successfully unlocked account.");
                window.location.reload(); // This will reload back onto the user page
            } else if (resp.msg == "Nice try, nigga.") {
                alert("NOT HAPPENING G");
            } else {
                alert(resp.msg);
            }
        });
    }
	
    $('#update-rank').on('click', function (e) {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'role',
            role: $('select[name=role]').children('option:selected').val()
        }, function (resp) {
            document.location.reload();
        });
        e.preventDefault();
    });

    $('#update-upgrade').on('click', function (e) {
        $.post('/user/{{ $user->username }}/edit', {
            _token: $('input[name=_token]').val(),
            type: 'upgrade',
            product: $('select[name=product]').children('option:selected').val(),
            notify: $('input[name=notifyUser]').is(':checked') ? 1 : 0
        }, function (resp) {
            document.location.reload();
        });
        e.preventDefault();
    });

    $(document).ready(function () {

        $('#delete-user').on('click', function (e) {
            $(".modalContainer").fadeIn();
            e.preventDefault();
        });

        $('#change-username').on('click', function (e) {
            if ($('#change-username').text() == "Change") {
                $('#setting-username').prop('disabled', false).focus();
                $('#change-username').text('Save');
            } else {
                $('#change-username').text('...');
                $.post('/user/{{ $user->username }}/edit', {
                    _token: $('input[name=_token]').val(),
                    type: 'username',
                    value: $('#setting-username').val()
                }, function (resp) {
                    if (resp.status == "done") {
                        window.location = '/user/' + $('#setting-username').val() + '/edit';
                    } else {
                        alert(resp.msg);
                        $('#change-username').text('Save');
                    }
                });
            }
            e.preventDefault();
        });
        $('#change-bio').on('click', function (e) {
            if ($('#change-bio').text() == "Edit") {
                $('#setting-bio').prop('disabled', false).focus();
                $('#change-bio').text('Save');
            } else {
                $('#change-bio').text('...');
                $.post('/user/{{ $user->username }}/edit', {
                    _token: $('input[name=_token]').val(),
                    type: 'bio',
                    value: $('#setting-bio').val()
                }, function (resp) {
                    if (resp.status == "done") {
                        $('#setting-bio').prop('disabled', true);
                        $('#change-bio').text('Edit');
                    } else {
                        alert(resp.msg);
                        $('#change-bio').text('Save');
                    }
                });
            }
            e.preventDefault();
        });
        $('#change-email').on('click', function (e) {
            if ($('#change-email').text() == "Change") {
                $('#setting-email').prop('disabled', false).focus();
                $('#change-email').text('Save');
            } else {
                $('#change-email').text('...');
                $.post('/user/{{ $user->username }}/edit', {
                    _token: $('input[name=_token]').val(),
                    type: 'email',
                    value: $('#setting-email').val()
                }, function (resp) {
                    if (resp.status == "done") {
                        $('#setting-email').prop('disabled', true);
                        $('#change-email').text('Change');
                    } else {
                        alert(resp.msg);
                        $('#change-email').text('Save');
                    }
                });
            }
            e.preventDefault();
        });


        $('#password-reset').on('click', function (e) {
            $.post('/user/{{ $user->username }}/edit', {
                _token: $('input[name=_token]').val(),
                type: 'password',
                action: 'generate'
            }, function (resp) {
                if (resp.status == "done") {
                    $('#password-reset-link').html('<input id="password-reset-link" onclick="this.focus();this.select()" style="font-size: 12px; color: green;" value="https://{{$currentDomain}}/password-reset/' + resp.link + '" readonly>').css({'color': 'green'});
                    $('#password-reset').hide();
                    $('#password-reset-delete').show();
                }
            });
            e.preventDefault();
        });

        $('#password-reset-delete').on('click', function (e) {
            $.post('/user/{{ $user->username }}/edit', {
                _token: $('input[name=_token]').val(),
                type: 'password',
                action: 'cancel'
            }, function (resp) {
                if (resp.status == "done") {
                    $('#password-reset-link').html('<p style="font-size: 14px; color: red;">None</p>');
                    $('#password-reset').show();
                    $('#password-reset-delete').hide();
                }
            });
            e.preventDefault();
        });


        $('#profile-pic-edit').on('click', function (e) {
            if ($('#profile-pic-edit').text() == "Save") {
                $('#profile-pic-edit').text('Saving...');
                if (file.size > 2097152) {
                    $('#image-err-msg').text("File size is too big. Resize it and try again.");
                } else {
                    $.ajax({
                        url: '/user/{{ $user->username }}/edit',
                        type: 'POST',
                        data: new FormData($('#pfp-form')[0]),
                        cache: false,
                        contentType: false,
                        processData: false,
                        xhr: function () {
                            var myXhr = $.ajaxSettings.xhr();
                            return myXhr;
                        },
                        success: function (resp) {
                            if (resp.status != 'err') {
                                $('#profile-pic-edit').text('Remove');
                            } else {
                                $('#profile-pic-edit').text('Save');
                                $('#image-err-msg').text(resp.msg);
                            }
                        },
                        error: function (e) {
                            console.log(e);
                        }

                    });
                }
            } else {
                $.post('/user/{{ $user->username }}/edit', {
                    _token: $('input[name=_token]').val(),
                    type: 'remove-image',
                }, function (resp) {
                    if (resp.status == "done") {
                        $('.profile-img-src').removeAttr('src');
                        $('#profile-pic-edit').text('');
                    }
                });
            }
            e.preventDefault();
        })


        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    $('.profile-img-src').attr('src', e.target.result);
                }
                reader.readAsDataURL(input.files[0]);
                $('#profile-pic-edit').show().text('Save');
            }
        }

        $("#file-upload").change(function () {
            readURL(this);
            file = this.files[0];
        });
    });
</script>
</body>
</html>