Module: Login

Included in:
Instabot
Defined in:
lib/instabot/login.rb

Instance Method Summary collapse

Instance Method Details

#check_login_status(_mode = :default) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/instabot/login.rb', line 50

def (_mode = :default)
  puts '[+] '.cyan + 'Checking login status' if @login_mode != :manual
  log('checking loging status', 'LOGIN')
  if @login_status
    return true
  else
    puts "[-] [##{@login_counter}] ".cyan + "You're not logged in (or it is an error with the request)\t[TRYING AGAIN]".red.bold
    exit! if @login_counter == 3
    @login_counter += 1
    
  end
end

#login(username = '', password = '') ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/instabot/login.rb', line 2

def (username = '', password = '')
  if @login_mode == :manual
    username = username.to_s
    password = password.to_s
  else
    username = options[:username]
    password = options[:password]
  end

  log('trying to login', 'LOGIN')
  puts '[+] '.cyan + "Trying to login as [#{username}]"
           = @agent.get('https://www.instagram.com/accounts/login/?force_classic_login')
  page_form          = .forms.last
  page_form.username = username
  page_form.password = password
  page               = page_form.submit

  if page.code == '200' && page.uri.to_s != 'https://www.instagram.com/accounts/login/?force_classic_login' && !page.uri.to_s.include?('challenge')
    @login_status = true
    log('successfully logged in', 'LOGIN')
    puts '[+] '.cyan + 'Successfully logged in'.green.bold
  else
    @login_status = false
    if page.uri.to_s.include?('challenge')
      puts '[-] '.cyan + 'Your account needs veryfication or it has been banned from instagram'.red.bold
    else
      puts '[-] '.cyan + 'Invalid username or password'.red.bold
    end
    
  end

rescue Exception => e
  log("an error detected: #{e.class} #{e} #{e.backtrace}", 'LOGIN')
  @login_status = false
  puts '[-] '.cyan + "#{e.class} #{e.message}\n check out the log file for full trace ".red
  exit
end

#logoutObject



40
41
42
43
44
45
46
47
48
# File 'lib/instabot/login.rb', line 40

def logout
  log('trying to logout', 'LOGIN')
  puts '[+] '.cyan + 'Trying to logging out'
  set_mechanic_data
  @agent.get('https://www.instagram.com/accounts/logout/')
  @logout_status = true
  log('successfully logged out', 'LOGIN')
  puts '[+] '.cyan + 'Successfully logged out'
end