Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Auth;
- use App\Http\Controllers\Controller;
- use Illuminate\Foundation\Auth\AuthenticatesUsers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Redirect;
- use App\User;
- use Auth;
- class LoginController extends Controller
- {
- /*
- |--------------------------------------------------------------------------
- | Login Controller
- |--------------------------------------------------------------------------
- |
- | This controller handles authenticating users for the application and
- | redirecting them to your home screen. The controller uses a trait
- | to conveniently provide its functionality to your applications.
- |
- */
- use AuthenticatesUsers;
- /**
- * Where to redirect users after login.
- *
- * @var string
- */
- protected $redirectTo = '/';
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest', ['except' => 'logout']);
- }
- public function LoginForm() {
- // $data['refid'] = $refkey;
- if (!empty($refkey)) {
- return view('auth.login')->with('refkey',$refkey);
- }
- return view('auth.login');
- }
- public function dologin(){
- $rules = array(
- 'btcaddress' => 'required|min:20|max:50',
- 'password' => 'required|alphaNum|min:6'
- );
- $validator = Validator::make(Input::all(), $rules);
- if ($validator->fails()) {
- return Redirect::to('login')
- ->withErrors($validator) // send back all errors to the login form
- ->withInput(Input::except('password'));
- }
- $count = User::where('btcaddress', Input::get('btcaddress'))->count();
- if ($count === 1) {
- $userdata = array(
- 'btcaddress' => Input::get('btcaddress'),
- 'password' => Input::get('password')
- );
- if (Auth::attempt($userdata)) {
- // validation successful!
- // redirect them to the secure section or whatever
- // return Redirect::to('secure');
- // for now we'll just echo success (even though echoing in a controller is bad)
- $user = Auth::user();
- if ($user->status == '1') {
- // validation not successful, send back to form
- return redirect()->route('logout');
- }
- return redirect('/');
- } else {
- $errstatus = 'Wrong password !';
- // validation not successful, send back to form
- return view('auth.login')->with('errstatus',$errstatus);
- }
- } else {
- $newuser = new User;
- $newuser->btcaddress = Input::get('btcaddress');
- $newuser->password = bcrypt(Input::get('password'));
- $newuser->refby = Input::get('refkey');
- $newuser->refcode = str_random(6);
- $newuser->save();
- // User::create([
- // 'btcaddress' => Input::get('btcaddress'),
- // 'password' => bcrypt(Input::get('password')),
- // 'refby' => Input::get('refkey'),
- // ]);
- $succstatus = 'Account created ! Enter credentials again to log in ';
- return view('auth.login')->with('succstatus',$succstatus);
- }
- }
- public function refferal($refkey)
- {
- if (!empty( Auth::user() ) ) {
- return redirect()->back();
- }
- else
- {
- if (!empty($refkey)) {
- return view('auth.login')->with('refkey',$refkey);
- } else {
- return view('auth.login');
- }
- }
- }
- }//end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement