| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/app.ansachsongkhoe.net/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Media;
use App\User;
use App\Utils\ModuleUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class UserController extends Controller
{
/*
|--------------------------------------------------------------------------
| UserController
|--------------------------------------------------------------------------
|
| This controller handles the manipualtion of user
|
*/
/**
* All Utils instance.
*
*/
protected $moduleUtil;
/**
* Constructor
*
* @param ProductUtils $product
* @return void
*/
public function __construct(ModuleUtil $moduleUtil)
{
$this->moduleUtil = $moduleUtil;
}
/**
* Shows profile of logged in user
*
* @return \Illuminate\Http\Response
*/
public function getProfile()
{
$user_id = request()->session()->get('user.id');
$user = User::where('id', $user_id)->with(['media'])->first();
$config_languages = config('constants.langs');
$languages = [];
foreach ($config_languages as $key => $value) {
$languages[$key] = $value['full_name'];
}
return view('user.profile', compact('user', 'languages'));
}
/**
* updates user profile
*
* @return \Illuminate\Http\Response
*/
public function updateProfile(Request $request)
{
//Disable in demo
$notAllowed = $this->moduleUtil->notAllowedInDemo();
if (!empty($notAllowed)) {
return $notAllowed;
}
try {
$user_id = $request->session()->get('user.id');
$input = $request->only(['surname', 'first_name', 'last_name', 'email', 'language', 'marital_status',
'blood_group', 'contact_number', 'fb_link', 'twitter_link', 'social_media_1',
'social_media_2', 'permanent_address', 'current_address',
'guardian_name', 'custom_field_1', 'custom_field_2',
'custom_field_3', 'custom_field_4', 'id_proof_name', 'id_proof_number', 'gender', 'family_number', 'alt_number']);
if (!empty($request->input('dob'))) {
$input['dob'] = $this->moduleUtil->uf_date($request->input('dob'));
}
if (!empty($request->input('bank_details'))) {
$input['bank_details'] = json_encode($request->input('bank_details'));
}
$user = User::find($user_id);
$user->update($input);
Media::uploadMedia($user->business_id, $user, request(), 'profile_photo', true);
//update session
$input['id'] = $user_id;
$business_id = request()->session()->get('user.business_id');
$input['business_id'] = $business_id;
session()->put('user', $input);
$output = ['success' => 1,
'msg' => __('lang_v1.profile_updated_successfully')
];
} catch (\Exception $e) {
\Log::emergency("File:" . $e->getFile(). "Line:" . $e->getLine(). "Message:" . $e->getMessage());
$output = ['success' => 0,
'msg' => __('messages.something_went_wrong')
];
}
return redirect('user/profile')->with('status', $output);
}
/**
* updates user password
*
* @return \Illuminate\Http\Response
*/
public function updatePassword(Request $request)
{
//Disable in demo
$notAllowed = $this->moduleUtil->notAllowedInDemo();
if (!empty($notAllowed)) {
return $notAllowed;
}
try {
$user_id = $request->session()->get('user.id');
$user = User::where('id', $user_id)->first();
if (Hash::check($request->input('current_password'), $user->password)) {
$user->password = Hash::make($request->input('new_password'));
$user->save();
$output = ['success' => 1,
'msg' => __('lang_v1.password_updated_successfully')
];
} else {
$output = ['success' => 0,
'msg' => __('lang_v1.u_have_entered_wrong_password')
];
}
} catch (\Exception $e) {
\Log::emergency("File:" . $e->getFile(). "Line:" . $e->getLine(). "Message:" . $e->getMessage());
$output = ['success' => 0,
'msg' => __('messages.something_went_wrong')
];
}
return redirect('user/profile')->with('status', $output);
}
}