Completed
Push — master ( c715fc...482a25 )
by Aitor Riba
01:56
created

LaralangController::deleteAllTranslations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Aitor24\Laralang\Controllers;
4
5
use Aitor24\Laralang\Models\DB_Translation;
6
use App\Http\Controllers\Controller;
7
use Crypt;
8
use Illuminate\Http\Request;
9
use Response;
10
11
class LaralangController extends Controller
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
19
        return view('laralang::login');
20
    }
21
22
    public function login(Request $request)
23
    {
24
        session(['laralang.password' => Crypt::encrypt($request->input('password'))]);
25 View Code Duplication
        if (Crypt::decrypt(session('laralang.password')) != config('laralang.default.password')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
26
            return redirect(Route('laralang::login'))
27
            ->with('status', 'Invalid password');
28
        }
29
30
        return redirect(Route('laralang::translations'));
31
    }
32
33
    public function logout(Request $request)
34
    {
35
        $request->session()->forget('laralang.password');
36
37
        return redirect(Route('laralang::login'));
38
    }
39
40
    public function showTranslations()
41
    {
42
        return view('laralang::translations');
43
    }
44
45
    public function api()
46
    {
47
        return DB_Translation::all();
48
    }
49
50
    public function deleteTranslation(Request $request)
51
    {
52
        $trans = DB_Translation::findOrFail($request->id);
53
        $trans->delete();
54
    }
55
56
    public function deleteAllTranslations()
57
    {
58
        $trans = DB_Translation::all();
59
        foreach ($trans as $tran){
60
            $tran->delete();
61
        }
62
    }
63
    
64
    public function editTranslation(Request $request)
65
    {
66
        $trans = DB_Translation::findOrFail($request->id);
67
        $trans->string = $request->string;
68
        $trans->to_lang = $request->to;
69
        $trans->from_lang = $request->from;
70
        $trans->translation = $request->translation;
71
        $trans->touch();
72
        $trans->save();
73
    }
74
}
75