Advertisement
Guest User

Untitled

a guest
Nov 19th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Auth;
  4.  
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Validator;
  9. use Illuminate\Support\Facades\Input;
  10. use Illuminate\Support\Facades\Redirect;
  11. use App\User;
  12. use Auth;
  13.  
  14.  
  15. class LoginController extends Controller
  16. {
  17. /*
  18. |--------------------------------------------------------------------------
  19. | Login Controller
  20. |--------------------------------------------------------------------------
  21. |
  22. | This controller handles authenticating users for the application and
  23. | redirecting them to your home screen. The controller uses a trait
  24. | to conveniently provide its functionality to your applications.
  25. |
  26. */
  27.  
  28. use AuthenticatesUsers;
  29.  
  30. /**
  31. * Where to redirect users after login.
  32. *
  33. * @var string
  34. */
  35. protected $redirectTo = '/';
  36.  
  37. /**
  38. * Create a new controller instance.
  39. *
  40. * @return void
  41. */
  42. public function __construct()
  43. {
  44. $this->middleware('guest', ['except' => 'logout']);
  45. }
  46.  
  47. public function LoginForm() {
  48. // $data['refid'] = $refkey;
  49. if (!empty($refkey)) {
  50. return view('auth.login')->with('refkey',$refkey);
  51. }
  52. return view('auth.login');
  53.  
  54.  
  55. }
  56.  
  57. public function dologin(){
  58.  
  59. $rules = array(
  60. 'btcaddress' => 'required|min:20|max:50',
  61. 'password' => 'required|alphaNum|min:6'
  62. );
  63. $validator = Validator::make(Input::all(), $rules);
  64. if ($validator->fails()) {
  65. return Redirect::to('login')
  66. ->withErrors($validator) // send back all errors to the login form
  67. ->withInput(Input::except('password'));
  68. }
  69. $count = User::where('btcaddress', Input::get('btcaddress'))->count();
  70.  
  71. if ($count === 1) {
  72.  
  73. $userdata = array(
  74. 'btcaddress' => Input::get('btcaddress'),
  75. 'password' => Input::get('password')
  76. );
  77.  
  78. if (Auth::attempt($userdata)) {
  79.  
  80. // validation successful!
  81. // redirect them to the secure section or whatever
  82. // return Redirect::to('secure');
  83. // for now we'll just echo success (even though echoing in a controller is bad)
  84. $user = Auth::user();
  85. if ($user->status == '1') {
  86.  
  87. // validation not successful, send back to form
  88. return redirect()->route('logout');
  89. }
  90.  
  91.  
  92.  
  93. return redirect('/');
  94.  
  95. } else {
  96. $errstatus = 'Wrong password !';
  97. // validation not successful, send back to form
  98. return view('auth.login')->with('errstatus',$errstatus);
  99.  
  100. }
  101.  
  102.  
  103. } else {
  104.  
  105.  
  106. $newuser = new User;
  107. $newuser->btcaddress = Input::get('btcaddress');
  108. $newuser->password = bcrypt(Input::get('password'));
  109. $newuser->refby = Input::get('refkey');
  110. $newuser->refcode = str_random(6);
  111. $newuser->save();
  112. // User::create([
  113. // 'btcaddress' => Input::get('btcaddress'),
  114. // 'password' => bcrypt(Input::get('password')),
  115. // 'refby' => Input::get('refkey'),
  116. // ]);
  117. $succstatus = 'Account created ! Enter credentials again to log in ';
  118. return view('auth.login')->with('succstatus',$succstatus);
  119. }
  120.  
  121.  
  122.  
  123.  
  124. }
  125. public function refferal($refkey)
  126. {
  127. if (!empty( Auth::user() ) ) {
  128.  
  129. return redirect()->back();
  130.  
  131. }
  132. else
  133. {
  134. if (!empty($refkey)) {
  135.  
  136. return view('auth.login')->with('refkey',$refkey);
  137.  
  138. } else {
  139.  
  140. return view('auth.login');
  141. }
  142. }
  143.  
  144.  
  145.  
  146. }
  147.  
  148.  
  149.  
  150. }//end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement