Apply fixes from StyleCI

This commit is contained in:
Manish Verma
2017-09-04 09:52:33 +00:00
committed by StyleCI Bot
parent 837c99db39
commit 7a78368037
39 changed files with 1023 additions and 1498 deletions

View File

@@ -38,17 +38,16 @@ use Socialite;
*/
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers;
/* to redirect after login */
// if auth is agent
protected $redirectTo = '/dashboard';
protected $redirectTo = '/dashboard';
// if auth is user
protected $redirectToUser = '/profile';
protected $redirectToUser = '/profile';
/* Direct After Logout */
protected $redirectAfterLogout = '/';
protected $loginPath = '/auth/login';
protected $loginPath = '/auth/login';
protected $social;
/**
@@ -69,8 +68,7 @@ class AuthController extends Controller
public function redirectToProvider($provider, $redirect = '')
{
if ($redirect !== '')
{
if ($redirect !== '') {
$this->setSession($provider, $redirect);
}
//dd(\Config::get('services'));
@@ -81,23 +79,19 @@ class AuthController extends Controller
public function handleProviderCallback($provider)
{
try
{
try {
//notice we are not doing any validation, you should do it
$this->changeRedirect();
$user = Socialite::driver($provider)->user();
if ($user)
{
if ($user) {
// stroing data to our use table and logging them in
$username = $user->getEmail();
$username = $user->getEmail();
$first_name = $user->getName();
if ($user->nickname)
{
if ($user->nickname) {
$username = $user->nickname;
}
if (!$first_name)
{
if (!$first_name) {
$first_name = $username;
}
$data = [
@@ -108,21 +102,17 @@ class AuthController extends Controller
'active' => 1,
];
$user = User::where('email', $data['email'])->first();
if (!$user)
{
if (!$user) {
$user = User::where('user_name', $data['user_name'])->first();
}
if (!$user)
{
if (!$user) {
$user = User::firstOrCreate($data);
}
Auth::login($user);
}
//after login redirecting to home page
return redirect('/');
}
catch (\Exception $ex)
{
} catch (\Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
@@ -135,23 +125,17 @@ class AuthController extends Controller
public function getRegister(CommonSettings $settings)
{
// Event for login
$settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first();
$settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first();
$email_mandatory = $settings->select('status')->where('option_name', '=', 'email_mandatory')->first();
//dd($settings->status);
\Event::fire(new \App\Events\FormRegisterEvent());
if (Auth::user())
{
if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent')
{
if (Auth::user()) {
if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') {
return \Redirect::route('dashboard');
}
elseif (Auth::user()->role == 'user')
{
} elseif (Auth::user()->role == 'user') {
// return view('auth.register');
}
}
else
{
} else {
return view('auth.register', compact('settings', 'email_mandatory'));
}
}
@@ -167,99 +151,71 @@ class AuthController extends Controller
public function postRegister(User $user, RegisterRequest $request, $api = false)
{
//dd($request->all());
try
{
$request_array = $request->input();
$password = Hash::make($request->input('password'));
$user->password = $password;
$name = $request->input('full_name');
try {
$request_array = $request->input();
$password = Hash::make($request->input('password'));
$user->password = $password;
$name = $request->input('full_name');
$user->first_name = $name;
if ($request_array['email'] == '')
{
if ($request_array['email'] == '') {
$user->email = null;
}
else
{
} else {
$user->email = $request->input('email');
}
if (!checkArray('mobile', $request_array))
{
if (!checkArray('mobile', $request_array)) {
$user->mobile = null;
}
else
{
} else {
$user->mobile = $request->input('mobile');
}
if (!checkArray('code', $request_array))
{
if (!checkArray('code', $request_array)) {
$user->country_code = 0;
}
else
{
} else {
$user->country_code = $request->input('code');
}
if (checkArray('username', $request_array))
{
if (checkArray('username', $request_array)) {
$user->user_name = checkArray('username', $request_array);
}
else
{
} else {
$user->user_name = $request->input('email');
}
$user->role = 'user';
$code = str_random(60);
$user->role = 'user';
$code = str_random(60);
$user->remember_token = $code;
$user->save();
$message12 = '';
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$sms = Plugin::select('status')->where('name', '=', 'SMS')->first();
$message12 = '';
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$sms = Plugin::select('status')->where('name', '=', 'SMS')->first();
// Event for login
\Event::fire(new \App\Events\LoginEvent($request));
if ($request->input('email') !== '')
{
$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)]);
if ($request->input('email') !== '') {
$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)]);
}
if ($settings->status == 1 || $settings->status == '1')
{
if (count($sms) > 0)
{
if ($sms->status == 1 || $sms->status == '1')
{
if ($settings->status == 1 || $settings->status == '1') {
if (count($sms) > 0) {
if ($sms->status == 1 || $sms->status == '1') {
$message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_and_moble');
}
else
{
} else {
$message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_sms_plugin_inactive_or_not_setup');
}
}
else
{
if ($request->input('email') !== '')
{
} else {
if ($request->input('email') !== '') {
$message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail');
}
else
{
} else {
$message12 = Lang::get('lang.account-created-contact-admin-as-we-were-not-able-to-send-opt');
}
}
}
else
{
} else {
$message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail');
}
if ($api == true)
{
if ($api == true) {
return ['message' => $message12, 'user' => $user->toArray()];
}
return redirect('home')->with('success', $message12);
}
catch (\Exception $e)
{
if ($api == true)
{
throw new \Exception($e->getMessage());
} catch (\Exception $e) {
if ($api == true) {
throw new \Exception($e->getMessage());
}
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -274,17 +230,14 @@ class AuthController extends Controller
public function accountActivate($token)
{
$user = User::where('remember_token', '=', $token)->first();
if ($user)
{
$user->active = 1;
if ($user) {
$user->active = 1;
$user->remember_token = null;
$user->save();
$this->openTicketAfterVerification($user->id);
return redirect('/auth/login')->with('status', 'Acount activated. Login to start');
}
else
{
} else {
return redirect('/auth/login')->with('fails', 'Invalid Token');
}
}
@@ -300,15 +253,12 @@ class AuthController extends Controller
public function getMail($token, User $user)
{
$user = $user->where('remember_token', $token)->where('active', 0)->first();
if ($user)
{
if ($user) {
$user->active = 1;
$user->save();
return redirect('auth/login');
}
else
{
} else {
return redirect('auth/login');
}
}
@@ -321,26 +271,17 @@ class AuthController extends Controller
public function getLogin()
{
$directory = base_path();
if (file_exists($directory . DIRECTORY_SEPARATOR . '.env'))
{
if (Auth::user())
{
if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent')
{
if (file_exists($directory.DIRECTORY_SEPARATOR.'.env')) {
if (Auth::user()) {
if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') {
return \Redirect::route('dashboard');
}
elseif (Auth::user()->role == 'user')
{
} elseif (Auth::user()->role == 'user') {
return \Redirect::route('home');
}
}
else
{
} else {
return view('auth.login');
}
}
else
{
} else {
return Redirect::route('licence');
}
}
@@ -354,153 +295,119 @@ class AuthController extends Controller
*/
public function postLogin(LoginRequest $request)
{
try
{
try {
// dd($request->input());
\Event::fire('auth.login.event', []); //added 5/5/2016
// Set login attempts and login time
$value = $_SERVER['REMOTE_ADDR'];
$value = $_SERVER['REMOTE_ADDR'];
$usernameinput = $request->input('email');
$password = $request->input('password');
if ($request->input('referer'))
{
$password = $request->input('password');
if ($request->input('referer')) {
$referer = 'form';
}
else
{
} else {
$referer = '/';
}
$field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
$field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
$result = $this->confirmIPAddress($value, $usernameinput);
// If attempts > 3 and time < 30 minutes
$security = Security::whereId('1')->first();
if ($result == 1)
{
if ($result == 1) {
return redirect()->back()->withErrors('email', 'Incorrect details')->with(['error' => $security->lockout_message, 'referer' => $referer]);
}
$check_active = User::where('email', '=', $request->input('email'))->orwhere('user_name', '=', $request->input('email'))->first();
if (!$check_active)
{ //check if user exists or not
if (!$check_active) { //check if user exists or not
//if user deos not exist then return back with error that user is not registered
return redirect()->back()
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
])->with(['error' => Lang::get('lang.not-registered'),
'referer' => $referer,]);
'referer' => $referer, ]);
}
//if user exists
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
if ($settings->status == '1' || $settings->status == 1)
{ // check for otp verification setting
if ($settings->status == '1' || $settings->status == 1) { // check for otp verification setting
// setting is enabled
$sms = Plugin::select('status')->where('name', '=', 'SMS')->first();
if ($sms)
{ //check sms plugin installed or not
if ($sms) { //check sms plugin installed or not
// plugin is installed
if ($sms->status == 1 || $sms->status === '1')
{ //check plugin is active or not
if ($sms->status == 1 || $sms->status === '1') { //check plugin is active or not
// plugin is active
if (!$check_active->active)
{ //check account is active or not
if (!$check_active->active) { //check account is active or not
// account is not active show verify otp window
if ($check_active->mobile)
{ //check user has mobile or not
if ($check_active->mobile) { //check user has mobile or not
// user has mobile number return verify OTP screen
return \Redirect::route('otp-verification')
->withInput($request->input())
->with(['values' => $request->input(),
'referer' => $referer,
'name' => $check_active->first_name,
'number' => $check_active->mobile,
'code' => $check_active->country_code,]);
}
else
{
'referer' => $referer,
'name' => $check_active->first_name,
'number' => $check_active->mobile,
'code' => $check_active->country_code, ]);
} else {
goto a; //attenmpt login (be careful while using goto statements)
}
}
else
{
} else {
goto a; //attenmpt login (be careful while using goto statements)
}
}
else
{
} else {
goto a; //attenmpt login (be careful while using goto statements)
}
}
else
{
} else {
goto a; //attenmpt login (be careful while using goto statements)
}
}
else
{
} else {
// setting is disabled
a: if (!$check_active->active)
{ //check account is active or not
a: if (!$check_active->active) { //check account is active or not
// if accoutn is not active return back with error message that account is inactive
return redirect()->back()
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
])->with(['error' => Lang::get('lang.this_account_is_currently_inactive'),
'referer' => $referer,]);
}
else
{
'referer' => $referer, ]);
} else {
// try login
$loginAttempts = 1;
// If session has login attempts, retrieve attempts counter and attempts time
if (\Session::has('loginAttempts'))
{
$loginAttempts = \Session::get('loginAttempts');
if (\Session::has('loginAttempts')) {
$loginAttempts = \Session::get('loginAttempts');
$loginAttemptTime = \Session::get('loginAttemptTime');
$this->addLoginAttempt($value, $usernameinput);
// $credentials = $request->only('email', 'password');
$usernameinput = $request->input('email');
$password = $request->input('password');
$field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
$usernameinput = $request->input('email');
$password = $request->input('password');
$field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
// If attempts > 3 and time < 10 minutes
if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60)))
{
if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) {
return redirect()->back()->withErrors('email', 'incorrect email')->with('error', $security->lockout_message);
}
// If time > 10 minutes, reset attempts counter and time in session
if (time() - $loginAttemptTime > ($security->lockout_period * 60))
{
if (time() - $loginAttemptTime > ($security->lockout_period * 60)) {
\Session::put('loginAttempts', 1);
\Session::put('loginAttemptTime', time());
}
}
else
{ // If no login attempts stored, init login attempts and time
} else { // If no login attempts stored, init login attempts and time
\Session::put('loginAttempts', $loginAttempts);
\Session::put('loginAttemptTime', time());
$this->clearLoginAttempts($value, $usernameinput);
}
// If auth ok, redirect to restricted area
\Session::put('loginAttempts', $loginAttempts + 1);
if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember')))
{
if (Auth::user()->role == 'user')
{
if ($request->input('referer'))
{
if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) {
if (Auth::user()->role == 'user') {
if ($request->input('referer')) {
return \Redirect::route($request->input('referer'));
}
return \Redirect::route('/');
}
else
{
} else {
return redirect()->intended($this->redirectPath());
}
}
@@ -510,14 +417,12 @@ class AuthController extends Controller
return redirect()->back()
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
'email' => $this->getFailedLoginMessage(),
'password' => $this->getFailedLoginMessage(),
])->with(['error' => Lang::get('lang.invalid'),
'referer' => $referer,]);
'referer' => $referer, ]);
// Increment login attempts
}
catch (\Exception $e)
{
} catch (\Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -531,26 +436,20 @@ class AuthController extends Controller
*/
public function addLoginAttempt($value, $field)
{
$result = DB::table('login_attempts')->where('IP', '=', $value)->first();
$data = $result;
$result = DB::table('login_attempts')->where('IP', '=', $value)->first();
$data = $result;
$security = Security::whereId('1')->first();
$apt = $security->backlist_threshold;
if ($data)
{
$apt = $security->backlist_threshold;
if ($data) {
$attempts = $data->Attempts + 1;
if ($attempts == $apt)
{
if ($attempts == $apt) {
// $result = DB::select('UPDATE login_attempts SET Attempts='.$attempts.", LastLogin=NOW() WHERE IP = '$value' OR User = '$field'");
$result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts, 'LastLogin' => date('Y-m-d H:i:s')]);
}
else
{
} else {
$result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts]);
// $result = DB::select("UPDATE login_attempts SET Attempts=".$attempts." WHERE IP = '$value' OR User = '$field'");
}
}
else
{
} else {
// $result = DB::select("INSERT INTO login_attempts (Attempts,User,IP,LastLogin) values (1,'$field','$value', NOW())");
$result = DB::table('login_attempts')->update(['Attempts' => 1, 'User' => $field, 'IP' => $value, 'LastLogin' => date('Y-m-d H:i:s')]);
}
@@ -579,26 +478,21 @@ class AuthController extends Controller
*/
public function confirmIPAddress($value, $field)
{
$security = Security::whereId('1')->first();
$time = $security->lockout_period;
$security = Security::whereId('1')->first();
$time = $security->lockout_period;
$max_attempts = $security->backlist_threshold;
$table = 'login_attempts';
$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 ' .
' FROM ' . $table . " WHERE IP = '$value' OR User = '$field'");
$data = $result;
$table = 'login_attempts';
$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 '.
' FROM '.$table." WHERE IP = '$value' OR User = '$field'");
$data = $result;
//Verify that at least one login attempt is in database
if (!$data)
{
if (!$data) {
return 0;
}
if ($data[0]->Attempts >= $max_attempts)
{
if ($data[0]->Denied == 1)
{
if ($data[0]->Attempts >= $max_attempts) {
if ($data[0]->Denied == 1) {
return 1;
}
else
{
} else {
$this->clearLoginAttempts($value, $field);
return 0;
@@ -627,12 +521,9 @@ class AuthController extends Controller
*/
public function getVerifyOTP()
{
if (\Session::has('values'))
{
if (\Session::has('values')) {
return view('auth.otp-verify');
}
else
{
} else {
return redirect('auth/login');
}
}
@@ -646,35 +537,26 @@ class AuthController extends Controller
*/
public function verifyOTP(LoginRequest $request)
{
$user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))
$user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))
->orWhere('user_name', '=', $request->input('email'))->first();
$otp_length = strlen($request->input('otp'));
if (!\Schema::hasTable('user_verification'))
{
if (!\Schema::hasTable('user_verification')) {
$message = Lang::get('lang.opt-can-not-be-verified');
}
else
{
} else {
$otp = Otp::select('otp', 'updated_at')->where('user_id', '=', $user->id)
->first();
if ($otp != null)
{
if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp'))))
{
$otp2 = Hash::make($request->input('otp'));
$date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
$date2 = date('Y-m-d h:i:sa');
$time1 = new DateTime($date2);
$time2 = new DateTime($date1);
if ($otp != null) {
if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp')))) {
$otp2 = Hash::make($request->input('otp'));
$date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
$date2 = date('Y-m-d h:i:sa');
$time1 = new DateTime($date2);
$time2 = new DateTime($date1);
$interval = $time1->diff($time2);
if ($interval->i > 30 || $interval->h > 0)
{
if ($interval->i > 30 || $interval->h > 0) {
$message = Lang::get('lang.otp-expired');
}
else
{
if (Hash::check($request->input('otp'), $otp->otp))
{
} else {
if (Hash::check($request->input('otp'), $otp->otp)) {
Otp::where('user_id', '=', $user->id)
->update(['otp' => '']);
User::where('id', '=', $user->id)
@@ -682,20 +564,14 @@ class AuthController extends Controller
$this->openTicketAfterVerification($user->id);
return $this->postLogin($request);
}
else
{
} else {
$message = Lang::get('lang.otp-not-matched');
}
}
}
else
{
} else {
$message = Lang::get('lang.otp-invalid');
}
}
else
{
} else {
$message = Lang::get('lang.otp-not-matched');
}
}
@@ -703,30 +579,24 @@ class AuthController extends Controller
return \Redirect::route('otp-verification')
->withInput($request->input())
->with(['values' => $request->input(),
'number' => $user->mobile,
'name' => $user->user_name,
'fails' => $message,]);
'number' => $user->mobile,
'name' => $user->user_name,
'fails' => $message, ]);
}
public function resendOTP(OtpVerifyRequest $request)
{
if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms'))
{
if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms')) {
$message = Lang::get('lang.opt-can-not-be-verified');
return $message;
}
else
{
} else {
$sms = DB::table('sms')->get();
if (count($sms) > 0)
{
if (count($sms) > 0) {
\Event::fire(new \App\Events\LoginEvent($request));
return 1;
}
else
{
} else {
$message = Lang::get('lang.opt-can-not-be-verified');
return $message;
@@ -751,10 +621,8 @@ class AuthController extends Controller
->get();
Tickets::where(['user_id' => $id, 'status' => 6])
->update(['status' => 1]);
if ($ticket != null)
{
foreach ($ticket as $value)
{
if ($ticket != null) {
foreach ($ticket as $value) {
$ticket_id = $value->id;
Ticket_Thread::where('ticket_id', '=', $ticket_id)
->update(['updated_at' => date('Y-m-d H:i:s')]);
@@ -765,7 +633,7 @@ class AuthController extends Controller
public function changeRedirect()
{
$provider = \Session::get('provider');
$url = \Session::get($provider . 'redirect');
$url = \Session::get($provider.'redirect');
\Config::set("services.$provider.redirect", $url);
}
@@ -773,8 +641,7 @@ class AuthController extends Controller
{
$url = url($redirect);
\Session::set('provider', $provider);
\Session::set($provider . 'redirect', $url);
\Session::set($provider.'redirect', $url);
$this->changeRedirect();
}
}

View File

@@ -57,12 +57,12 @@ class PasswordController extends Controller
$user = User::where('email', '=', $request->only('email'))->orWhere('mobile', '=', $request->only('email'))->first();
if (isset($user)) {
$user1 = $user->email;
//gen new code and pass
$code = str_random(60);
//gen new code and pass
$code = str_random(60);
$password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->first();
if (isset($password_reset_table)) {
$password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->update(['token' => $code, 'created_at' => $date]);
// $password_reset_table->token = $code;
// $password_reset_table->token = $code;
// $password_reset_table->update(['token' => $code]);
} else {
$create_password_reset = \DB::table('password_resets')->insert(['email' => $user->email, 'token' => $code, 'created_at' => $date]);
@@ -107,7 +107,7 @@ class PasswordController extends Controller
$this->getResetValidationCustomAttributes()
);
$credentials = $this->getResetCredentials($request);
// dd($credentials);
// dd($credentials);
$email = $credentials['email'];
$password = $credentials['password'];
$token = $credentials['token'];