2015-11-05 23:34:43 +01:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
2016-10-01 04:10:58 +02:00
|
|
|
use Yajra\Datatables\Facades\Datatables;
|
2015-12-28 22:38:31 +01:00
|
|
|
use Hash;
|
|
|
|
|
2015-11-14 05:51:01 +01:00
|
|
|
use App\Models\Link;
|
|
|
|
use App\Models\User;
|
2015-12-28 22:33:17 +01:00
|
|
|
use App\Helpers\UserHelper;
|
2015-11-05 23:34:43 +01:00
|
|
|
|
2015-11-09 00:13:35 +01:00
|
|
|
class AdminController extends Controller {
|
2015-11-05 23:34:43 +01:00
|
|
|
/**
|
2016-10-02 02:38:35 +02:00
|
|
|
* Show the admin panel, and process setting changes.
|
2015-11-05 23:34:43 +01:00
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
2016-10-01 04:10:58 +02:00
|
|
|
|
2015-11-05 23:34:43 +01:00
|
|
|
public function displayAdminPage(Request $request) {
|
2015-12-12 18:26:25 +01:00
|
|
|
if (!$this->isLoggedIn()) {
|
2016-04-16 23:23:46 +02:00
|
|
|
return redirect(route('login'))->with('error', 'Please login to access your dashboard.');
|
2015-12-12 18:26:25 +01:00
|
|
|
}
|
|
|
|
|
2015-11-14 05:51:01 +01:00
|
|
|
$username = session('username');
|
2015-12-12 18:26:25 +01:00
|
|
|
$role = session('role');
|
2015-11-14 05:51:01 +01:00
|
|
|
|
2016-02-20 01:13:50 +01:00
|
|
|
$user = UserHelper::getUserByUsername($username);
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
return redirect(route('index'))->with('error', 'Invalid or disabled account.');
|
|
|
|
}
|
|
|
|
|
2015-11-09 01:49:45 +01:00
|
|
|
return view('admin', [
|
2015-11-14 05:51:01 +01:00
|
|
|
'role' => $role,
|
2016-12-02 23:07:59 +01:00
|
|
|
'admin_role' => UserHelper::canonicalUserRole('admin'),
|
|
|
|
'user_roles' => UserHelper::USER_ROLES,
|
2016-02-20 01:13:50 +01:00
|
|
|
'api_key' => $user->api_key,
|
|
|
|
'api_active' => $user->api_active,
|
2016-04-02 03:46:12 +02:00
|
|
|
'api_quota' => $user->api_quota,
|
|
|
|
'user_id' => $user->id
|
2015-11-09 01:49:45 +01:00
|
|
|
]);
|
2015-11-05 23:34:43 +01:00
|
|
|
}
|
2015-12-28 22:33:17 +01:00
|
|
|
|
|
|
|
public function changePassword(Request $request) {
|
|
|
|
if (!$this->isLoggedIn()) {
|
2016-01-19 00:23:33 +01:00
|
|
|
return abort(404);
|
2015-12-28 22:33:17 +01:00
|
|
|
}
|
2016-12-02 23:07:59 +01:00
|
|
|
|
2015-12-28 22:33:17 +01:00
|
|
|
$username = session('username');
|
|
|
|
$old_password = $request->input('current_password');
|
|
|
|
$new_password = $request->input('new_password');
|
|
|
|
|
|
|
|
if (UserHelper::checkCredentials($username, $old_password) == false) {
|
|
|
|
// Invalid credentials
|
2015-12-28 22:38:31 +01:00
|
|
|
return redirect('admin')->with('error', 'Current password invalid. Try again.');
|
2015-12-28 22:33:17 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Credentials are correct
|
|
|
|
$user = UserHelper::getUserByUsername($username);
|
2015-12-28 22:38:31 +01:00
|
|
|
$user->password = Hash::make($new_password);
|
|
|
|
$user->save();
|
|
|
|
|
2015-12-28 22:33:17 +01:00
|
|
|
$request->session()->flash('success', "Password changed successfully.");
|
2016-01-19 00:15:35 +01:00
|
|
|
return redirect(route('admin'));
|
2015-12-28 22:33:17 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 23:34:43 +01:00
|
|
|
}
|