Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Redirect;
  7. use Illuminate\Support\Facades\Input;
  8. use Session;
  9. use Illuminate\Http\Request;
  10.  
  11. use App\Http\Requests;
  12. use App\User;
  13.  
  14. use Hash;
  15.  
  16. use Mail;
  17. class UsersController extends Controller
  18. {
  19. //
  20. public function create()
  21.  
  22. {
  23.  
  24. return view('users.create');
  25.  
  26. }
  27.  
  28. public function store()
  29.  
  30. {
  31.  
  32. $data = Input::all();
  33.  
  34. $validate = Validator::make($data, User::valid());
  35.  
  36. if($validate->fails()) {
  37.  
  38. return Redirect::to('users/create')
  39.  
  40. ->withErrors($validate)
  41.  
  42. ->withInput();
  43.  
  44. } else {
  45.  
  46. $user = new User;
  47.  
  48. $user->email = Input::get('email');
  49.  
  50. $user->name = Input::get('name');
  51.  
  52. $user->password = Hash::make(Input::get('password'));
  53.  
  54. $user->save();
  55.  
  56. Session::flash('notice', 'Signup Success');
  57.  
  58. return Redirect::to('users/create');
  59.  
  60. }
  61.  
  62. }
  63. public function reset_password() {
  64.  
  65. return view('users.reset_password');
  66.  
  67. }
  68.  
  69.  
  70. public function process_reset_password(Request $request) {
  71.  
  72. $valid = array(
  73.  
  74. 'email' => 'required|email'
  75.  
  76. );
  77.  
  78. $data = $request->all();
  79.  
  80. $validate = Validator::make($data, $valid);
  81.  
  82. $find_data = User::where('email', $request->email)->first();
  83.  
  84. if($validate->fails()) {
  85.  
  86. return Redirect::to('reset-password')
  87.  
  88. ->withErrors($validate)
  89.  
  90. ->withInput();
  91.  
  92. } elseif(empty($find_data)) {
  93.  
  94. Session::flash('error', 'Email not found' . $request->email);
  95.  
  96. return Redirect::to('reset-password')
  97.  
  98. ->withErrors($validate)
  99.  
  100. ->withInput();
  101.  
  102. } else {
  103.  
  104. $find_data->forgot_token = str_random(60);
  105.  
  106. $find_data->save();
  107.  
  108. Mail::send('emails.instructionresetpassword', $find_data->toArray(), function($message) use($find_data) {
  109.  
  110. $message->from("jamballaravel@gmail.com", "Forgot password");
  111.  
  112. $message->to($find_data->email, $find_data->name)->subject('Reset Password Instruction to Jambal Laravel');
  113.  
  114. $message->subject();
  115.  
  116. });
  117.  
  118. Session::flash('notice', 'Check your email, the reset password instruction has sent to '.$find_data->email);
  119.  
  120. return Redirect::to('/');
  121.  
  122. }
  123.  
  124. }
  125.  
  126.  
  127. public function change_password($forgot_token) {
  128.  
  129. $find_user = User::where('forgot_token', $forgot_token)->first();
  130.  
  131. if(empty($find_user)) {
  132.  
  133. Session::flash('error', 'Token not valid, :)');
  134.  
  135. return Redirect::to('/');
  136.  
  137. } else {
  138.  
  139. return view('users.change_password')
  140.  
  141. ->with( 'forgot_token', $find_user->forgot_token);
  142.  
  143. }
  144.  
  145. }
  146.  
  147.  
  148. public function process_change_password(Request $request, $forgot_token) {
  149.  
  150. $valid = array(
  151.  
  152. 'password' => ('required|min: 8|confirmed')
  153.  
  154. );
  155.  
  156. $data = $request->all();
  157.  
  158. $find_data = User::where('forgot_token', $forgot_token)->first();
  159.  
  160. $validate = Validator::make($data, $valid);
  161.  
  162. if($validate->fails()) {
  163.  
  164. return Redirect::to('change-password/'.$find_data->forgot_token)
  165.  
  166. ->withErrors($validate);
  167.  
  168. } else {
  169.  
  170. $find_data->password = Hash::make($request->password);
  171.  
  172. $find_data->forgot_token = null;
  173.  
  174. $find_data->save();
  175.  
  176. Session::flash('notice ', 'Hai ' . $find_data->name . ' Password has change lets login');
  177.  
  178. return Redirect::to('sessions/create');
  179.  
  180. }
  181.  
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement