2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-05-24 14:44:41 +02:00
|
|
|
use App\TwoFAccount;
|
2019-05-20 07:37:41 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2019-05-24 14:44:41 +02:00
|
|
|
class TwoFAccountController extends Controller
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2019-05-24 14:44:41 +02:00
|
|
|
return response()->json(TwoFAccount::all()->toArray());
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2019-05-24 14:44:41 +02:00
|
|
|
$twofaccount = TwoFAccount::create([
|
2019-05-20 07:37:41 +02:00
|
|
|
'name' => $request->name,
|
|
|
|
'secret' => $request->secret
|
|
|
|
]);
|
|
|
|
|
|
|
|
$data = [
|
2019-05-24 14:44:41 +02:00
|
|
|
'data' => $twofaccount,
|
|
|
|
'status' => (bool) $twofaccount,
|
|
|
|
'message' => $twofaccount ? 'Account Created' : 'Error Creating Account',
|
2019-05-20 07:37:41 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return response()->json($data);
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:44:41 +02:00
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-05-24 14:44:41 +02:00
|
|
|
* @param \App\TwoFAccount $twofaccount
|
2019-05-20 07:37:41 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-05-24 14:44:41 +02:00
|
|
|
public function show(TwoFAccount $twofaccount)
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-05-24 14:44:41 +02:00
|
|
|
return response()->json($twofaccount);
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-05-24 14:44:41 +02:00
|
|
|
* @param \App\TwoFAccount $twofaccount
|
2019-05-20 07:37:41 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-05-24 14:44:41 +02:00
|
|
|
public function update(Request $request, TwoFAccount $twofaccount)
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-05-24 14:44:41 +02:00
|
|
|
$status = $twofaccount->update($request->all());
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'status' => $status,
|
2019-05-22 00:49:27 +02:00
|
|
|
'message' => $status ? 'Account Updated' : 'Error Updating Account'
|
2019-05-20 07:37:41 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
//return response()->json($request, 200);
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:44:41 +02:00
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2019-05-24 14:44:41 +02:00
|
|
|
* @param \App\TwoFAccount $twofaccount
|
2019-05-20 07:37:41 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-05-24 14:44:41 +02:00
|
|
|
public function destroy(TwoFAccount $twofaccount)
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2019-05-24 14:44:41 +02:00
|
|
|
$status = $twofaccount->delete();
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'status' => $status,
|
2019-05-22 00:49:27 +02:00
|
|
|
'message' => $status ? 'Account Deleted' : 'Error Deleting Account'
|
2019-05-20 07:37:41 +02:00
|
|
|
]);
|
|
|
|
}
|
2019-05-22 00:49:27 +02:00
|
|
|
|
2019-05-24 14:44:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified soft deleted resource from storage.
|
|
|
|
*
|
|
|
|
* @param \App\TwoFAccount $twofaccount
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function forceDestroy($id)
|
|
|
|
{
|
|
|
|
$twofaccount = TwoFAccount::onlyTrashed()->findOrFail($id);
|
|
|
|
|
|
|
|
$status = $twofaccount->forceDelete();
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'status' => $status,
|
|
|
|
'message' => $status ? 'Account Deleted permanently' : 'Error Deleting Account'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|