Source code for cock.li
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.

UserController.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php namespace App\Http\Controllers;
  2. use App\Http\Requests;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Hash;
  6. use Validator;
  7. use Auth;
  8. use App\PasswordChange;
  9. class UserController extends Controller {
  10. public function __construct() {
  11. $this->middleware('auth');
  12. }
  13. public function getIndex() {
  14. return view('pages.user.home');
  15. }
  16. public function getCongrats() {
  17. if(!session()->has('just_registered'))
  18. return redirect('/user');
  19. return view('pages.user.congrats');
  20. }
  21. public function getChangepass() {
  22. return view('pages.user.changepass');
  23. }
  24. public function postChangepass(Request $request) {
  25. Validator::extend('passcheck', function ($attribute, $value, $parameters)
  26. {
  27. return Hash::check($value, Auth::user()->password);
  28. });
  29. $this->validate($request, [
  30. 'old_password' => 'required|passcheck',
  31. 'password' => 'required|confirmed|min:8|max:255',
  32. ],[
  33. 'old_password.passcheck' => 'The password you entered is incorrect',
  34. 'password.min' => 'Password must be 8-255 characters',
  35. ]);
  36. $user = Auth::user();
  37. $user->password = Hash::make($request->password);
  38. $user->save();
  39. $password_change = new PasswordChange();
  40. $password_change->user_id = $user->id;
  41. $password_change->save();
  42. return redirect('/user/changepass')->with('message','Your password has been changed!');
  43. }
  44. }