/** * Run the database seeds. * * @return void */ public function run() { App\Models\Customer::paginate(300)->each(function ($u) { $rand = rand(0, 3); for ($i = 0; $i < $rand; $i++) { $u->addresses()->save(factory(App\Models\Address::class)->make()); } }); }
/** * Authenticate user * * @return Response */ public function signin() { $email = Input::get('email'); $password = Input::get('password'); $check = Auth::attempt(['email' => $email, 'password' => $password]); if ($check) { $result['id'] = Auth::user()['id']; $result['name'] = Auth::user()['name']; $result['email'] = Auth::user()['email']; $result['date_of_birth'] = Auth::user()['date_of_birth']; $result['role'] = Auth::user()['role']; $result['gender'] = Auth::user()['gender']; return new JSend('success', (array) $result); } elseif (Input::has('sso')) { $sso_data = Input::get('sso'); //1. check sso $sso = \App\Models\User::email($sso_data['email'])->ssomedia(['facebook'])->first(); //1a. register sso if (!$sso) { $sso = new \App\Models\Customer(); $sso->fill(['name' => $sso_data['name'], 'email' => $sso_data['email'], 'gender' => $sso_data['user']['gender'], 'sso_id' => $sso_data['id'], 'sso_media' => 'facebook', 'sso_data' => json_encode($sso_data['user']), 'role' => 'customer']); if (!$sso->save()) { return new JSend('error', (array) Input::all(), $sso->getError()); } $is_new = true; } Auth::loginUsingId($sso['id']); $result['id'] = Auth::user()['id']; $result['name'] = Auth::user()['name']; $result['email'] = Auth::user()['email']; $result['date_of_birth'] = Auth::user()['date_of_birth']; $result['role'] = Auth::user()['role']; $result['gender'] = Auth::user()['gender']; return new JSend('success', (array) $result); } return new JSend('error', (array) Input::all(), 'Username atau password tidak valid.'); }