You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProfileControllerA.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Http\Controllers\DS;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use PDF;
  10. use App\Staff;
  11. use App\Model\StaffDetail;
  12. use App\Model\WorkOrder;
  13. use File;
  14. class ProfileControllerA extends Controller
  15. {
  16. public function encryptPassword($action, $string) {
  17. $output = false;
  18. $encrypt_method = "AES-256-CBC";
  19. $secret_key = '28472B4B6250655368566D5970337336';
  20. $secret_iv = md5(md5($string)); //'This is my secret iv';
  21. // hash
  22. $key = hash('sha256', $secret_key);
  23. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  24. if ( $action == 'encrypt' ) {
  25. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  26. $output = base64_encode($output);
  27. } else if( $action == 'decrypt' ) {
  28. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  29. }
  30. return $output;
  31. }
  32. public function viewProfile(){
  33. $id = Auth::guard('agent')->id();
  34. $user = Staff::with('StaffDetail')->find($id);
  35. return view('sales.view_profile',compact('user'));
  36. }
  37. public function updateProfilePicture(Request $request){
  38. $this->validate($request, [
  39. 'prof_img' => 'mimes:jpeg,jpg,png|required|dimensions:width=128,height=128'
  40. ]);
  41. $pathIcon = '';
  42. if($request->hasfile('prof_img')){
  43. // Move / Upload Icon into server
  44. $destinationPath = 'assets/avatar';
  45. // create folder/dir if not exist
  46. if(!File::exists(public_path().$destinationPath)){
  47. File::makeDirectory(public_path().$destinationPath,0777,true);
  48. }
  49. $icon = $request->file('prof_img');
  50. $icon->move($destinationPath,$request->id.'.'.$icon->getClientOriginalExtension());
  51. $pathIcon = $destinationPath.'/'.$request->id.'.'.$icon->getClientOriginalExtension();
  52. }
  53. $user = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  54. $user->StaffDetail->user_pic = $pathIcon;
  55. $user->StaffDetail->save();
  56. if($pathIcon != ''){
  57. return redirect()->back()->with('success_msg', 'Success update your image profile');
  58. }else{
  59. return redirect()->back()->with('error_msg', 'Cant update your image profile');
  60. }
  61. }
  62. public function updateFullName(Request $request){
  63. $user = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  64. $user->StaffDetail->name = $request->name;
  65. $user->StaffDetail->save();
  66. return redirect()->back()->with('success_msg', 'Success update your full name');
  67. }
  68. public function updateIdentity(Request $request){
  69. $user = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  70. $user->StaffDetail->ic = $request->ic;
  71. $user->StaffDetail->save();
  72. return redirect()->back()->with('success_msg', 'Success update your indentity/NRIC');
  73. }
  74. public function updatePhone(Request $request){
  75. $user = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  76. $user->StaffDetail->phone = $request->phone;
  77. $user->StaffDetail->save();
  78. return redirect()->back()->with('success_msg', 'Success update your phone');
  79. }
  80. public function updatePassword(Request $request){
  81. $user = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  82. $enc_pass = $this->encryptPassword('encrypt',$request->password);
  83. $user->password = $enc_pass;
  84. $user->save();
  85. $user->StaffDetail->password = $enc_pass;
  86. $user->StaffDetail->save();
  87. return redirect()->back()->with('success_msg', 'Success update your password');
  88. }
  89. }