HomeController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Settings;
  4. use App\User;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Str;
  8. class HomeController extends Controller
  9. {
  10. /**
  11. * Create a new controller instance.
  12. *
  13. * @return void
  14. */
  15. public function __construct()
  16. {
  17. $this->middleware('auth');
  18. }
  19. public function usersControl(){
  20. return view('users', ['user_list'=>User::all()]);
  21. }
  22. public function userSwitch(User $user){
  23. $user->isEnabled ^= 1;
  24. $user->save();
  25. return redirect('users');
  26. }
  27. public function userShutdown(){
  28. $users = User::all();
  29. foreach ($users as $user) {
  30. if(!$user->isAdmin) {
  31. $user->isEnabled = false;
  32. $user->save();
  33. }
  34. }
  35. return redirect('users');
  36. }
  37. public function userGreenlight(){
  38. $users = User::all();
  39. foreach ($users as $user) {
  40. if(!$user->isAdmin) {
  41. $user->isEnabled = true;
  42. $user->save();
  43. }
  44. }
  45. return redirect('users');
  46. }
  47. public function pwResetAsk(User $user, String $orig){
  48. return view('auth.passwords.reset', [
  49. 'express'=>True,
  50. 'uid' => $user->id,
  51. 'email'=>$user->email,
  52. 'origin' => $orig,
  53. ]);
  54. }
  55. public function usrUpdatePw(Request $request, User $user){
  56. $user->password = Hash::make($request->password);
  57. $user->setRememberToken(Str::random(60));
  58. $user->save();
  59. // Width() method will set a sesion variable just for one call
  60. return redirect($request->origin)->with('status', __('ui.pwchok'));
  61. }
  62. public function switchRegLock(Request $request){
  63. $state = Settings::where('key','lockdown')->first();
  64. if($state->value == 'no'){
  65. $state->value = 'yes';
  66. $state->save();
  67. $state = Settings::where('key','lockdown_msg')->first();
  68. $state->value = $request->message_text;
  69. $state->save();
  70. $state = Settings::where('key','srv_email')->first();
  71. $state->value = $request->recipient_name;
  72. $state->save();
  73. $ui_msg = 'ui.lockdown_on';
  74. } else {
  75. $state->value = 'no';
  76. $state->save();
  77. $ui_msg = 'ui.lockdown_off';
  78. }
  79. return redirect('home')->with('status', __($ui_msg));
  80. }
  81. public function userAdd(){
  82. return view('auth.register', ['express'=>True]);
  83. }
  84. public function addNewUser(Request $request){
  85. $usr = new User();
  86. $usr->name = $request->name;
  87. $usr->email = $request->email;
  88. $usr->password = Hash::make($request->password);
  89. $usr->setRememberToken(Str::random(60));
  90. $usr->save();
  91. return redirect('users')->with('status', __('ui.adduserok'));
  92. }
  93. }