<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ActiveAccountController extends Controller
{
    //
    public function activeAccount($token)
    {
        $check = User::where('token_active', $token)->first();
        if($check)
        {
            $check->status = User::ACTIVE;
            $check->status_email = 1;
            $check->token_active = null;
            $check->save();

            return redirect()->to(url('/'))->with('success', 'Tài khoản của bạn đã được kích hoạt thành công. Vui lòng đăng nhập.');
        }

        return redirect()->to(url('/'))->with('error', 'Dữ liệu không hợp lệ');
    }
}
