<?php

namespace App\Http\Controllers;

use App\Models\Users;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AuthController extends Controller
{
    //

    public function activate(Request $request) {
        $codeActivate = $request->post("codeActivate");
        $user = Users::query()->where("code_activate", "$codeActivate")->first();
        if ($user) {
            $hash = md5($codeActivate);
            $user->code_session = $hash;
            $updateUser = DB::update("update users set code_session = '$hash' where id = $user->id");
            return response()->json($user, 200);
        } else {
            return response()->json([], 401);
        }

    }
}
