Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Api\Auth;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use App\User;
- class LoginController extends Controller
- {
- private $ig;
- private $username;
- private $password;
- public function __construct()
- {
- $this->ig = new \InstagramAPI\Instagram();
- $this->username = "nastyaantipovaa";
- $this->password = "789456123qweRTY";
- }
- public function login(Request $request)
- {
- $this->ig->login($this->username, $this->password);
- $isAuth = false;
- try {
- $userInfo = $this->ig->people->getInfoByName($request->username)->getUser();
- $isAuth = true;
- //Я предполагаю, что проверку есть ли такой акк в бд - надо делать тут.
- //Так как будет потом проверка на пароль (если пользователь указал)
- //Попробуй разобраться со встроенной. Пока не сделал - отложил. 1.03
- //Бери recipe как пример по авторизации
- $data = [
- "username"=> $userInfo->getUsername(),
- "fullName" => $userInfo->getFullName()
- ];
- $this->create($data); //надо сделать проверку, существует ли аккаунт
- } catch (Exception $e) {}
- finally {
- return response()
- ->json([
- 'is_auth' => $isAuth,
- 'message' => "",
- ], 200);
- }
- }
- public function verify(Request $request)
- {
- $this->ig->login($this->username, $this->password);
- $mediaId = $this->ig->media->getMediaId("https://www.instagram.com/p/BuR2C3eHn96/");
- $likes = $this->ig->media->getLikers($mediaId)->getUsers();
- $isLike = false;
- foreach ($likes as $i){
- if($i->getUsername() == $request->username){
- $isLike = true;
- break;
- }
- }
- return response()
- ->json([
- 'is_like' => $isLike,
- ], 200);
- }
- protected function create(array $data)
- {
- return User::firstOrCreate([
- 'username' => $data["username"],
- 'instagram_link' => "https://www.instagram.com/". $data["username"],
- 'full_name' => $data["fullName"],
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement