|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aitor24\Laralang\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Aitor24\Laralang\Models\DB_Translation; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
use Crypt; |
|
9
|
|
|
|
|
10
|
|
|
class LaralangController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public function showLogin() |
|
14
|
|
|
{ |
|
15
|
|
|
if (session('laralang.password') && Crypt::decrypt(session('laralang.password')) == config('laralang.default.password')) { |
|
16
|
|
|
return redirect(Route('laralang::translations')); |
|
17
|
|
|
} |
|
18
|
|
|
return view('laralang::login'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function login(Request $request) |
|
22
|
|
|
{ |
|
23
|
|
|
session(['laralang.password' => Crypt::encrypt($request->input('password'))]); |
|
24
|
|
View Code Duplication |
if (Crypt::decrypt(session('laralang.password')) != config('laralang.default.password')) { |
|
|
|
|
|
|
25
|
|
|
return redirect(Route('laralang::login')) |
|
26
|
|
|
->with('status','Invalid password'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return redirect(Route('laralang::translations')); |
|
30
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function logout(Request $request) |
|
34
|
|
|
{ |
|
35
|
|
|
$request->session()->forget('laralang.password'); |
|
36
|
|
|
|
|
37
|
|
|
return redirect(Route('laralang::translations')); |
|
38
|
|
|
} |
|
39
|
|
|
public function showTranslations() |
|
40
|
|
|
{ |
|
41
|
|
|
return view('laralang::translations'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function api() |
|
45
|
|
|
{ |
|
46
|
|
|
return DB_Translation::all(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function deleteTrans($id) |
|
50
|
|
|
{ |
|
51
|
|
|
$trans = DB_Translation::findOrFail($id); |
|
52
|
|
|
$trans->delete(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function editTrans($id, $translation) |
|
56
|
|
|
{ |
|
57
|
|
|
$trans = DB_Translation::findOrFail($id); |
|
58
|
|
|
$trans->translation = $translation; |
|
59
|
|
|
$trans->touch(); |
|
60
|
|
|
$trans->save(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.