AuthController::postRegister()   F
last analyzed

Complexity

Conditions 13
Paths 697

Size

Total Lines 63
Code Lines 49

Duplication

Lines 15
Ratio 23.81 %

Importance

Changes 0
Metric Value
cc 13
eloc 49
nc 697
nop 2
dl 15
loc 63
rs 3.1746
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
// controllers
6
use App\Http\Controllers\Admin\helpdesk\SocialMedia\SocialMediaController;
7
use App\Http\Controllers\Common\PhpMailController;
8
// requests
9
use App\Http\Controllers\Controller;
10
use App\Http\Requests\helpdesk\LoginRequest;
11
use App\Http\Requests\helpdesk\OtpVerifyRequest;
12
use App\Http\Requests\helpdesk\RegisterRequest;
13
use App\Model\helpdesk\Settings\CommonSettings;
14
use App\Model\helpdesk\Settings\Plugin;
15
use App\Model\helpdesk\Settings\Security;
16
use App\Model\helpdesk\Ticket\Ticket_Thread;
17
// classes
18
use App\Model\helpdesk\Ticket\Tickets;
19
use App\Model\helpdesk\Utility\Otp;
20
use App\User;
21
use Auth;
22
use DateTime;
23
use DB;
24
use Hash;
25
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
26
use Input;
27
use Lang;
28
use Socialite;
29
30
/**
31
 * ---------------------------------------------------
32
 * AuthController
33
 * ---------------------------------------------------
34
 * This controller handles the registration of new users, as well as the
35
 * authentication of existing users. By default, this controller uses
36
 * a simple trait to add these behaviors. Why don't you explore it?
37
 *
38
 * @author      Ladybird <[email protected]>
39
 */
40
class AuthController extends Controller
41
{
42
    use AuthenticatesAndRegistersUsers;
43
    /* to redirect after login */
44
45
    // if auth is agent
46
    protected $redirectTo = '/dashboard';
47
    // if auth is user
48
    protected $redirectToUser = '/profile';
49
    /* Direct After Logout */
50
    protected $redirectAfterLogout = '/';
51
    protected $loginPath = '/auth/login';
52
    protected $social;
53
54
    /**
55
     * Create a new authentication controller instance.
56
     *
57
     * @param \Illuminate\Contracts\Auth\Guard     $auth
0 ignored issues
show
Bug introduced by
There is no parameter named $auth. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
58
     * @param \Illuminate\Contracts\Auth\Registrar $registrar
0 ignored issues
show
Bug introduced by
There is no parameter named $registrar. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
59
     *
60
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
61
     */
62
    public function __construct(PhpMailController $PhpMailController, SocialMediaController $social)
63
    {
64
        $this->PhpMailController = $PhpMailController;
0 ignored issues
show
Bug introduced by
The property PhpMailController does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
65
        $social->configService();
66
        $this->middleware('guest', ['except' => ['getLogout', 'verifyOTP', 'redirectToProvider']]);
67
    }
68
69
    public function redirectToProvider($provider, $redirect = '')
70
    {
71
        if ($redirect !== '') {
72
            $this->setSession($provider, $redirect);
73
        }
74
        //dd(\Config::get('services'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
        $s = Socialite::driver($provider)->redirect();
76
        //dd('dscd');
77
        return $s;
78
    }
79
80
    public function handleProviderCallback($provider)
81
    {
82
        try {
83
            //notice we are not doing any validation, you should do it
84
            $this->changeRedirect();
85
86
            $user = Socialite::driver($provider)->user();
87
            if ($user) {
88
                // stroing data to our use table and logging them in
89
                $username = $user->getEmail();
90
                $first_name = $user->getName();
91
                if ($user->nickname) {
92
                    $username = $user->nickname;
93
                }
94
                if (!$first_name) {
95
                    $first_name = $username;
96
                }
97
                $data = [
98
                    'first_name' => $first_name,
99
                    'email'      => $user->getEmail(),
100
                    'user_name'  => $username,
101
                    'role'       => 'user',
102
                    'active'     => 1,
103
                ];
104
                $user = User::where('email', $data['email'])->first();
105
                if (!$user) {
106
                    $user = User::where('user_name', $data['user_name'])->first();
107
                }
108
                if (!$user) {
109
                    $user = User::firstOrCreate($data);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on App\User. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
110
                }
111
                Auth::login($user);
112
            }
113
            //after login redirecting to home page
114
            return redirect('/');
115
        } catch (\Exception $ex) {
116
            return redirect()->back()->with('fails', $ex->getMessage());
117
        }
118
    }
119
120
    /**
121
     * Get the form for registration.
122
     *
123
     * @return type Response
124
     */
125
    public function getRegister(CommonSettings $settings)
126
    {
127
        // Event for login
128
        $settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdes...ettings\CommonSettings>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
129
        $email_mandatory = $settings->select('status')->where('option_name', '=', 'email_mandatory')->first();
130
        //dd($settings->status);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
131
        \Event::fire(new \App\Events\FormRegisterEvent());
132 View Code Duplication
        if (Auth::user()) {
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...
133
            if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') {
134
                return \Redirect::route('dashboard');
135
            } elseif (Auth::user()->role == 'user') {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
136
                // return view('auth.register');
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
137
            }
138
        } else {
139
            return view('auth.register', compact('settings', 'email_mandatory'));
140
        }
141
    }
142
143
    /**
144
     * Post registration form.
145
     *
146
     * @param type User            $user
147
     * @param type RegisterRequest $request
148
     *
149
     * @return type Response
150
     */
151
    public function postRegister(User $user, RegisterRequest $request)
152
    {
153
        try {
154
            $request_array = $request->input();
155
            $password = Hash::make($request->input('password'));
156
            $user->password = $password;
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
157
            $name = $request->input('full_name');
158
            $user->first_name = $name;
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
159 View Code Duplication
            if ($request_array['email'] == '') {
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...
160
                $user->email = null;
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
            } else {
162
                $user->email = $request->input('email');
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
            }
164 View Code Duplication
            if ($request_array['mobile'] == '') {
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...
165
                $user->mobile = null;
0 ignored issues
show
Documentation introduced by
The property mobile does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
166
            } else {
167
                $user->mobile = $request->input('mobile');
0 ignored issues
show
Documentation introduced by
The property mobile does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168
            }
169
            if ($request_array['code'] == '') {
170
                $user->country_code = 0;
0 ignored issues
show
Documentation introduced by
The property country_code does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
171
            } else {
172
                $user->country_code = $request->input('code');
0 ignored issues
show
Documentation introduced by
The property country_code does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
173
            }
174 View Code Duplication
            if ($request_array['email'] != '') {
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...
175
                $user->user_name = $request->input('email');
0 ignored issues
show
Documentation introduced by
The property user_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
176
            } else {
177
                $user->user_name = $request->input('mobile');
0 ignored issues
show
Documentation introduced by
The property user_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
178
            }
179
            $user->role = 'user';
0 ignored issues
show
Documentation introduced by
The property role does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
180
            $code = str_random(60);
181
            $user->remember_token = $code;
0 ignored issues
show
Documentation introduced by
The property remember_token does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
182
            $user->save();
183
            $message12 = '';
184
            $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
185
            $sms = Plugin::select('status')->where('name', '=', 'SMS')->first();
186
            // Event for login
187
            \Event::fire(new \App\Events\LoginEvent($request));
188
            if ($request->input('email') !== '') {
189
                $var = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $request->input('email')], $message = ['subject' => null, 'scenario' => 'registration'], $template_variables = ['user' => $name, 'email_address' => $request->input('email'), 'password_reset_link' => url('account/activate/'.$code)]);
0 ignored issues
show
Unused Code introduced by
$var is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
            }
191
            if ($settings->status == 1 || $settings->status == '1') {
192
                if (count($sms) > 0) {
193
                    if ($sms->status == 1 || $sms->status == '1') {
194
                        $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_and_moble');
195
                    } else {
196
                        $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_sms_plugin_inactive_or_not_setup');
197
                    }
198
                } else {
199
                    if ($request->input('email') !== '') {
200
                        $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail');
201
                    } else {
202
                        $message12 = Lang::get('lang.account-created-contact-admin-as-we-were-not-able-to-send-opt');
203
                    }
204
                }
205
            } else {
206
                $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail');
207
            }
208
209
            return redirect('home')->with('success', $message12);
210
        } catch (\Exception $e) {
211
            return redirect()->back()->with('fails', $e->getMessage());
212
        }
213
    }
214
215
    /**
216
     * Function to activate account.
217
     *
218
     * @param type $token
219
     *
220
     * @return type redirect
221
     */
222
    public function accountActivate($token)
223
    {
224
        $user = User::where('remember_token', '=', $token)->first();
225
        if ($user) {
226
            $user->active = 1;
227
            $user->remember_token = null;
228
            $user->save();
229
            $this->openTicketAfterVerification($user->id);
230
231
            return redirect('/auth/login')->with('status', 'Acount activated. Login to start');
232
        } else {
233
            return redirect('/auth/login')->with('fails', 'Invalid Token');
234
        }
235
    }
236
237
    /**
238
     * Get mail function.
239
     *
240
     * @param type      $token
241
     * @param type User $user
242
     *
243
     * @return type Response
244
     */
245
    public function getMail($token, User $user)
246
    {
247
        $user = $user->where('remember_token', $token)->where('active', 0)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
248
        if ($user) {
249
            $user->active = 1;
250
            $user->save();
251
252
            return redirect('auth/login');
253
        } else {
254
            return redirect('auth/login');
255
        }
256
    }
257
258
    /**
259
     * Get login page.
260
     *
261
     * @return type Response
262
     */
263
    public function getLogin()
264
    {
265
        $directory = base_path();
266
        if (file_exists($directory.DIRECTORY_SEPARATOR.'.env')) {
267 View Code Duplication
            if (Auth::user()) {
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...
268
                if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') {
269
                    return \Redirect::route('dashboard');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Redirect::route('dashboard'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Auth\AuthController::getLogin of type App\Http\Controllers\Auth\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
270
                } elseif (Auth::user()->role == 'user') {
271
                    return \Redirect::route('home');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Redirect::route('home'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Auth\AuthController::getLogin of type App\Http\Controllers\Auth\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
272
                }
273
            } else {
274
                return view('auth.login');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('auth.login'); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by App\Http\Controllers\Auth\AuthController::getLogin of type App\Http\Controllers\Auth\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
275
            }
276
        } else {
277
            return Redirect::route('licence');
278
        }
279
    }
280
281
    /**
282
     * Post of login page.
283
     *
284
     * @param type LoginRequest $request
285
     *
286
     * @return type Response
287
     */
288
    public function postLogin(LoginRequest $request)
289
    {
290
        // dd($request->input());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
291
        \Event::fire('auth.login.event', []); //added 5/5/2016
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
292
        // Set login attempts and login time
293
        $value = $_SERVER['REMOTE_ADDR'];
294
        $usernameinput = $request->input('email');
295
        $password = $request->input('password');
296
        if ($request->input('referer')) {
297
            $referer = 'form';
298
        } else {
299
            $referer = '/';
300
        }
301
        $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
302
        $result = $this->confirmIPAddress($value, $usernameinput);
303
304
        // If attempts > 3 and time < 30 minutes
305
        $security = Security::whereId('1')->first();
306
        if ($result == 1) {
307
            return redirect()->back()->withErrors('email', 'Incorrect details')->with(['error' => $security->lockout_message, 'referer' => $referer]);
308
        }
309
310
        $check_active = User::where('email', '=', $request->input('email'))->orwhere('user_name', '=', $request->input('email'))->first();
311
        if (!$check_active) { //check if user exists or not
312
            //if user deos not exist then return back with error that user is not registered
313
            return redirect()->back()
314
                            ->withInput($request->only('email', 'remember'))
315
                            ->withErrors([
316
                                'email'                     => $this->getFailedLoginMessage(),
317
                                'password'                  => $this->getFailedLoginMessage(),
318
                            ])->with(['error'               => Lang::get('lang.not-registered'),
319
                                      'referer'             => $referer, ]);
320
        }
321
322
        //if user exists
323
        $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
324
325
        if ($settings->status == '1' || $settings->status == 1) { // check for otp verification setting
326
            // setting is enabled
327
            $sms = Plugin::select('status')->where('name', '=', 'SMS')->first();
328
            if ($sms) { //check sms plugin installed or not
329
                // plugin is installed
330
                if ($sms->status == 1 || $sms->status === '1') { //check plugin is active or not
331
                    // plugin is active
332
                    if (!$check_active->active) { //check account is active or not
333
                        // account is not active show verify otp window
334
                        if ($check_active->mobile) { //check user has mobile or not
335
                        // user has mobile number return verify OTP screen
336
                            return \Redirect::route('otp-verification')
337
                                ->withInput($request->input())
0 ignored issues
show
Bug introduced by
It seems like $request->input() targeting Illuminate\Http\Request::input() can also be of type string; however, Illuminate\Http\RedirectResponse::withInput() does only seem to accept null|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
338
                                ->with(['values' => $request->input(),
339
                                    'referer'    => $referer,
340
                                    'name'       => $check_active->first_name,
341
                                    'number'     => $check_active->mobile,
342
                                    'code'       => $check_active->country_code, ]);
343
                        } else {
344
                            goto a; //attenmpt login  (be careful while using goto statements)
345
                        }
346
                    } else {
347
                        goto a; //attenmpt login  (be careful while using goto statements)
348
                    }
349
                } else {
350
                    goto a; //attenmpt login  (be careful while using goto statements)
351
                }
352
            } else {
353
                goto a; //attenmpt login  (be careful while using goto statements)
354
            }
355
        } else {
356
            // setting is disabled
357
            a: if (!$check_active->active) { //check account is active or not
358
                // if accoutn is not active return back with error message that account is inactive
359
                return redirect()->back()
360
                                ->withInput($request->only('email', 'remember'))
361
                                ->withErrors([
362
                                    'email'       => $this->getFailedLoginMessage(),
363
                                    'password'    => $this->getFailedLoginMessage(),
364
                                ])->with(['error' => Lang::get('lang.this_account_is_currently_inactive'),
365
                            'referer'             => $referer, ]);
366
            } else {
367
                // try login
368
                $loginAttempts = 1;
369
                // If session has login attempts, retrieve attempts counter and attempts time
370
                if (\Session::has('loginAttempts')) {
371
                    $loginAttempts = \Session::get('loginAttempts');
372
                    $loginAttemptTime = \Session::get('loginAttemptTime');
373
                    $this->addLoginAttempt($value, $usernameinput);
374
                    // $credentials = $request->only('email', 'password');
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
375
                    $usernameinput = $request->input('email');
376
                    $password = $request->input('password');
377
                    $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
378
                    // If attempts > 3 and time < 10 minutes
379
                    if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) {
380
                        return redirect()->back()->withErrors('email', 'incorrect email')->with('error', $security->lockout_message);
381
                    }
382
                    // If time > 10 minutes, reset attempts counter and time in session
383
                    if (time() - $loginAttemptTime > ($security->lockout_period * 60)) {
384
                        \Session::put('loginAttempts', 1);
385
                        \Session::put('loginAttemptTime', time());
386
                    }
387
                } else { // If no login attempts stored, init login attempts and time
388
                    \Session::put('loginAttempts', $loginAttempts);
389
                    \Session::put('loginAttemptTime', time());
390
                    $this->clearLoginAttempts($value, $usernameinput);
391
                }
392
                // If auth ok, redirect to restricted area
393
                \Session::put('loginAttempts', $loginAttempts + 1);
394
                if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) {
395
                    if (Auth::user()->role == 'user') {
396
                        if ($request->input('referer')) {
397
                            return \Redirect::route($request->input('referer'));
0 ignored issues
show
Bug introduced by
It seems like $request->input('referer') targeting Illuminate\Http\Request::input() can also be of type array; however, Illuminate\Routing\Redirector::route() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
398
                        }
399
400
                        return \Redirect::route('/');
401
                    } else {
402
                        return redirect()->intended($this->redirectPath());
403
                    }
404
                }
405
            }
406
        }
407
408
        return redirect()->back()
409
                        ->withInput($request->only('email', 'remember'))
410
                        ->withErrors([
411
                            'email'       => $this->getFailedLoginMessage(),
412
                            'password'    => $this->getFailedLoginMessage(),
413
                        ])->with(['error' => Lang::get('lang.invalid'),
414
                    'referer'             => $referer, ]);
415
        // Increment login attempts
416
    }
417
418
    /**
419
     * Add login attempt.
420
     *
421
     * @param type IPaddress $value
422
     *
423
     * @return type Response
424
     */
425
    public function addLoginAttempt($value, $field)
426
    {
427
        $result = DB::table('login_attempts')->where('IP', '=', $value)->first();
428
        $data = $result;
429
        $security = Security::whereId('1')->first();
430
        $apt = $security->backlist_threshold;
431
        if ($data) {
432
            $attempts = $data->Attempts + 1;
433
            if ($attempts == $apt) {
434
                //                $result = DB::select('UPDATE login_attempts SET Attempts='.$attempts.", LastLogin=NOW() WHERE IP = '$value' OR User = '$field'");
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
435
                $result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts, 'LastLogin' => date('Y-m-d H:i:s')]);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
436
            } else {
437
                $result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts]);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
438
                // $result = DB::select("UPDATE login_attempts SET Attempts=".$attempts." WHERE IP = '$value' OR User = '$field'");
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
439
            }
440
        } else {
441
            //            $result = DB::select("INSERT INTO login_attempts (Attempts,User,IP,LastLogin) values (1,'$field','$value', NOW())");
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
442
            $result = DB::table('login_attempts')->update(['Attempts' => 1, 'User' => $field, 'IP' => $value, 'LastLogin' => date('Y-m-d H:i:s')]);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
443
        }
444
    }
445
446
    /**
447
     * Clear login attempt.
448
     *
449
     * @param type IPaddress $value
450
     *
451
     * @return type Response
452
     */
453
    public function clearLoginAttempts($value, $field)
454
    {
455
        $data = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['attempts' => '0']);
456
457
        return $data;
458
    }
459
460
    /**
461
     * Confiem IP.
462
     *
463
     * @param type IPaddress $value
464
     *
465
     * @return type Response
466
     */
467
    public function confirmIPAddress($value, $field)
468
    {
469
        $security = Security::whereId('1')->first();
470
        $time = $security->lockout_period;
471
        $max_attempts = $security->backlist_threshold;
472
        $table = 'login_attempts';
473
        $result = DB::select('SELECT Attempts, (CASE when LastLogin is not NULL and DATE_ADD(LastLogin, INTERVAL '.$time.' MINUTE)>NOW() then 1 else 0 end) as Denied '.
474
                        ' FROM '.$table." WHERE IP = '$value' OR User = '$field'");
475
        $data = $result;
476
        //Verify that at least one login attempt is in database
477
        if (!$data) {
478
            return 0;
479
        }
480
        if ($data[0]->Attempts >= $max_attempts) {
481
            if ($data[0]->Denied == 1) {
482
                return 1;
483
            } else {
484
                $this->clearLoginAttempts($value, $field);
485
486
                return 0;
487
            }
488
        }
489
490
        return 0;
491
    }
492
493
    /**
494
     * Get Failed login message.
495
     *
496
     * @return type string
497
     */
498
    protected function getFailedLoginMessage()
499
    {
500
        return Lang::get('lang.this_field_do_not_match_our_records');
501
    }
502
503
    /**
504
     *@category function to show verify OTP page
505
     *
506
     *@param null
507
     *
508
     *@return response|view
509
     */
510
    public function getVerifyOTP()
511
    {
512
        if (\Session::has('values')) {
513
            return view('auth.otp-verify');
514
        } else {
515
            return redirect('auth/login');
516
        }
517
    }
518
519
    /**
520
     *@category function to verify OTP
521
     *
522
     *@param $request
523
     *
524
     *@return int|string
525
     */
526
    public function verifyOTP(LoginRequest $request)
527
    {
528
        $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))
529
            ->orWhere('user_name', '=', $request->input('email'))->first();
530
        $otp_length = strlen($request->input('otp'));
531
        if (!\Schema::hasTable('user_verification')) {
532
            $message = Lang::get('lang.opt-can-not-be-verified');
533
        } else {
534
            $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', $user->id)
535
                        ->first();
536
            if ($otp != null) {
537
                if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp')))) {
538
                    $otp2 = Hash::make($request->input('otp'));
0 ignored issues
show
Unused Code introduced by
$otp2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
539
                    $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
540
                    $date2 = date('Y-m-d h:i:sa');
541
                    $time1 = new DateTime($date2);
542
                    $time2 = new DateTime($date1);
543
                    $interval = $time1->diff($time2);
544
                    if ($interval->i > 30 || $interval->h > 0) {
545
                        $message = Lang::get('lang.otp-expired');
546
                    } else {
547
                        if (Hash::check($request->input('otp'), $otp->otp)) {
548
                            Otp::where('user_id', '=', $user->id)
549
                                    ->update(['otp' => '']);
550
                            User::where('id', '=', $user->id)
551
                                    ->update(['active' => 1]);
552
                            $this->openTicketAfterVerification($user->id);
553
554
                            return $this->postLogin($request);
555
                        } else {
556
                            $message = Lang::get('lang.otp-not-matched');
557
                        }
558
                    }
559
                } else {
560
                    $message = Lang::get('lang.otp-invalid');
561
                }
562
            } else {
563
                $message = Lang::get('lang.otp-not-matched');
564
            }
565
        }
566
567
        return \Redirect::route('otp-verification')
568
                        ->withInput($request->input())
0 ignored issues
show
Bug introduced by
It seems like $request->input() targeting Illuminate\Http\Request::input() can also be of type string; however, Illuminate\Http\RedirectResponse::withInput() does only seem to accept null|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
569
                        ->with(['values' => $request->input(),
570
                            'number'     => $user->mobile,
571
                            'name'       => $user->user_name,
572
                            'fails'      => $message, ]);
573
    }
574
575
    public function resendOTP(OtpVerifyRequest $request)
576
    {
577
        if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms')) {
578
            $message = Lang::get('lang.opt-can-not-be-verified');
579
580
            return $message;
581
        } else {
582
            $sms = DB::table('sms')->get();
583
            if (count($sms) > 0) {
584
                \Event::fire(new \App\Events\LoginEvent($request));
585
586
                return 1;
587
            } else {
588
                $message = Lang::get('lang.opt-can-not-be-verified');
589
590
                return $message;
591
            }
592
        }
593
    }
594
595
    /**
596
     * @category function to change ticket status when user verifies his account
597
     *
598
     * @param int $id => user_id
599
     *
600
     * @return null
601
     *
602
     * @author [email protected]
603
     */
604
    public function openTicketAfterVerification($id)
605
    {
606
        // dd($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
607
        $ticket = Tickets::select('id')
608
                ->where(['user_id' => $id, 'status' => 6])
609
                ->get();
610
        Tickets::where(['user_id' => $id, 'status' => 6])
611
                ->update(['status' => 1]);
612
        if ($ticket != null) {
613
            foreach ($ticket as $value) {
614
                $ticket_id = $value->id;
615
                Ticket_Thread::where('ticket_id', '=', $ticket_id)
616
                    ->update(['updated_at' => date('Y-m-d H:i:s')]);
617
            }
618
        }
619
    }
620
621
    public function changeRedirect()
622
    {
623
        $provider = \Session::get('provider');
624
        $url = \Session::get($provider.'redirect');
625
        \Config::set("services.$provider.redirect", $url);
626
    }
627
628
    public function setSession($provider, $redirect)
629
    {
630
        $url = url($redirect);
631
        \Session::set('provider', $provider);
632
        \Session::set($provider.'redirect', $url);
633
        $this->changeRedirect();
634
    }
635
}
636