From 96c44bea1e01547dc04e64617905395ab47695ae Mon Sep 17 00:00:00 2001 From: Manish Verma Date: Mon, 6 Aug 2018 10:57:02 +0530 Subject: [PATCH] updates --- CONTRIBUTING.md | 10 + app/Http/Controllers/Auth/AuthController.php | 259 +++++++++--------- app/Model/helpdesk/Utility/Priority.php | 2 +- .../default1/agent/layout/agent.blade.php | 2 +- .../default1/client/layout/client.blade.php | 1 + .../installer/helpdesk/view2.blade.php | 2 +- 6 files changed, 150 insertions(+), 126 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..078a469d1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +## Contributing +Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests. + +* Please follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) and [PHP-FIG Naming Conventions](https://github.com/php-fig/fig-standards/blob/master/bylaws/007-psr-naming-conventions.md). +* Remember to follow [SemVer](http://semver.org/). If you are changing the behavior, or the public api, you may need to update the docs. +* Make sure that the current tests pass, and if you have added something new, add the tests where relevant. +* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History) them before submitting. +* You may also need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts. + +NOTE: StyleCI is set up to automatically check and fix any code style issues. diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index bbb8acb5b..61cc14b67 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -58,9 +58,10 @@ class AuthController extends Controller * * @return void */ - public function __construct(PhpMailController $PhpMailController, SocialMediaController $social) + public function __construct() { - $this->PhpMailController = $PhpMailController; + $this->PhpMailController = new PhpMailController(); + $social = new SocialMediaController(); $social->configService(); $this->middleware('guest', ['except' => ['getLogout', 'verifyOTP', 'redirectToProvider']]); } @@ -147,8 +148,9 @@ class AuthController extends Controller * * @return type Response */ - public function postRegister(User $user, RegisterRequest $request) + public function postRegister(User $user, RegisterRequest $request, $api = false) { + //dd($request->all()); try { $request_array = $request->input(); $password = Hash::make($request->input('password')); @@ -160,20 +162,20 @@ class AuthController extends Controller } else { $user->email = $request->input('email'); } - if ($request_array['mobile'] == '') { + if (!checkArray('mobile', $request_array)) { $user->mobile = null; } else { $user->mobile = $request->input('mobile'); } - if ($request_array['code'] == '') { + if (!checkArray('code', $request_array)) { $user->country_code = 0; } else { $user->country_code = $request->input('code'); } - if ($request_array['email'] != '') { - $user->user_name = $request->input('email'); + if (checkArray('username', $request_array)) { + $user->user_name = checkArray('username', $request_array); } else { - $user->user_name = $request->input('mobile'); + $user->user_name = $request->input('email'); } $user->role = 'user'; $code = str_random(60); @@ -204,9 +206,16 @@ class AuthController extends Controller } else { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail'); } + 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()); + } + return redirect()->back()->with('fails', $e->getMessage()); } } @@ -286,59 +295,63 @@ class AuthController extends Controller */ public function postLogin(LoginRequest $request) { - // dd($request->input()); - \Event::fire('auth.login.event', []); //added 5/5/2016 - // Set login attempts and login time - $value = $_SERVER['REMOTE_ADDR']; - $usernameinput = $request->input('email'); - $password = $request->input('password'); - if ($request->input('referer')) { - $referer = 'form'; - } else { - $referer = '/'; - } - $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; - $result = $this->confirmIPAddress($value, $usernameinput); + try { + // dd($request->input()); + \Event::fire('auth.login.event', []); //added 5/5/2016 + // Set login attempts and login time + $value = $_SERVER['REMOTE_ADDR']; + $usernameinput = $request->input('email'); + $password = $request->input('password'); + if ($request->input('referer')) { + $referer = 'form'; + } else { + $referer = '/'; + } + $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) { - return redirect()->back()->withErrors('email', 'Incorrect details')->with(['error' => $security->lockout_message, 'referer' => $referer]); - } + // If attempts > 3 and time < 30 minutes + $security = Security::whereId('1')->first(); + 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 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(), - ])->with(['error' => Lang::get('lang.not-registered'), - '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 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(), + ])->with(['error' => Lang::get('lang.not-registered'), + 'referer' => $referer, ]); + } - //if user exists - $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); + //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 - // setting is enabled - $sms = Plugin::select('status')->where('name', '=', 'SMS')->first(); - if ($sms) { //check sms plugin installed or not - // plugin is installed - 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 - // account is not active show verify otp window - 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, ]); + 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 + // plugin is installed + 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 + // account is not active show verify otp window + 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 { + goto a; //attenmpt login (be careful while using goto statements) + } } else { goto a; //attenmpt login (be careful while using goto statements) } @@ -349,69 +362,69 @@ class AuthController extends Controller goto a; //attenmpt login (be careful while using goto statements) } } else { - goto a; //attenmpt login (be careful while using goto statements) - } - } else { - // setting is disabled - 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(), - ])->with(['error' => Lang::get('lang.this_account_is_currently_inactive'), - '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'); - $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'; - // If attempts > 3 and time < 10 minutes - 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)) { - \Session::put('loginAttempts', 1); - \Session::put('loginAttemptTime', 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')) { - return \Redirect::route($request->input('referer')); + // setting is disabled + 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(), + ])->with(['error' => Lang::get('lang.this_account_is_currently_inactive'), + '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'); + $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'; + // If attempts > 3 and time < 10 minutes + 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)) { + \Session::put('loginAttempts', 1); + \Session::put('loginAttemptTime', 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')) { + return \Redirect::route($request->input('referer')); + } - return \Redirect::route('/'); - } else { - return redirect()->intended($this->redirectPath()); + return \Redirect::route('/'); + } else { + return redirect()->intended($this->redirectPath()); + } } } } - } - return redirect()->back() - ->withInput($request->only('email', 'remember')) - ->withErrors([ - 'email' => $this->getFailedLoginMessage(), - 'password' => $this->getFailedLoginMessage(), - ])->with(['error' => Lang::get('lang.invalid'), - 'referer' => $referer, ]); - // Increment login attempts + return redirect()->back() + ->withInput($request->only('email', 'remember')) + ->withErrors([ + 'email' => $this->getFailedLoginMessage(), + 'password' => $this->getFailedLoginMessage(), + ])->with(['error' => Lang::get('lang.invalid'), + 'referer' => $referer, ]); + // Increment login attempts + } catch (\Exception $e) { + return redirect()->back()->with('fails', $e->getMessage()); + } } /** @@ -500,11 +513,11 @@ class AuthController extends Controller } /** - *@category function to show verify OTP page + * @category function to show verify OTP page * - *@param null + * @param null * - *@return response|view + * @return response|view */ public function getVerifyOTP() { @@ -516,22 +529,22 @@ class AuthController extends Controller } /** - *@category function to verify OTP + * @category function to verify OTP * - *@param $request + * @param $request * - *@return int|string + * @return int|string */ public function verifyOTP(LoginRequest $request) { $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email')) - ->orWhere('user_name', '=', $request->input('email'))->first(); + ->orWhere('user_name', '=', $request->input('email'))->first(); $otp_length = strlen($request->input('otp')); if (!\Schema::hasTable('user_verification')) { $message = Lang::get('lang.opt-can-not-be-verified'); } else { $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', $user->id) - ->first(); + ->first(); if ($otp != null) { if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp')))) { $otp2 = Hash::make($request->input('otp')); @@ -612,7 +625,7 @@ class AuthController extends Controller 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')]); + ->update(['updated_at' => date('Y-m-d H:i:s')]); } } } diff --git a/app/Model/helpdesk/Utility/Priority.php b/app/Model/helpdesk/Utility/Priority.php index 051b6460a..92bb54ccb 100644 --- a/app/Model/helpdesk/Utility/Priority.php +++ b/app/Model/helpdesk/Utility/Priority.php @@ -7,7 +7,7 @@ use App\BaseModel; class Priority extends BaseModel { public $timestamps = false; - protected $table = 'priority'; + protected $table = 'ticket_priority'; protected $fillable = [ 'id', 'name', ]; diff --git a/resources/views/themes/default1/agent/layout/agent.blade.php b/resources/views/themes/default1/agent/layout/agent.blade.php index 6f032b588..338787375 100644 --- a/resources/views/themes/default1/agent/layout/agent.blade.php +++ b/resources/views/themes/default1/agent/layout/agent.blade.php @@ -310,7 +310,7 @@ @endforeach - + @else @endif diff --git a/resources/views/themes/default1/client/layout/client.blade.php b/resources/views/themes/default1/client/layout/client.blade.php index e97cbb7ad..e5bf16bd1 100644 --- a/resources/views/themes/default1/client/layout/client.blade.php +++ b/resources/views/themes/default1/client/layout/client.blade.php @@ -166,6 +166,7 @@
{!! Form::password('password',['placeholder'=>Lang::get('lang.password'),'class' => 'form-control']) !!} + {!! Lang::get('lang.forgot_password') !!}
diff --git a/resources/views/themes/default1/installer/helpdesk/view2.blade.php b/resources/views/themes/default1/installer/helpdesk/view2.blade.php index 4d4ec1f51..7f5f87a26 100644 --- a/resources/views/themes/default1/installer/helpdesk/view2.blade.php +++ b/resources/views/themes/default1/installer/helpdesk/view2.blade.php @@ -202,7 +202,7 @@ function validate_extensions(&$results) { } // if $recommended_extensions = array( - + 'imap' => 'IMAP extension is used for connecting to mail server using IMAP settings to fetch emails in the system.' // 'gd' => 'GD is used for image manipulation. Without it, system is not able to create thumbnails for files or manage avatars, logos and project icons. Please refer to this page for installation instructions', // 'mbstring' => 'MultiByte String is used for work with Unicode. Without it, system may not split words and string properly and you can have weird question mark characters in Recent Activities for example. Please refer to this page for installation instructions', // 'curl' => 'cURL is used to support various network tasks. Please refer to this page for installation instructions',