-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathlogin.rb
62 lines (57 loc) · 2.1 KB
/
login.rb
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Login
def login(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}]"
login_page = @agent.get('https://www.instagram.com/accounts/login/?force_classic_login')
page_form = login_page.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
check_login_status
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
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
def check_login_status(_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
login
end
end
end