Class: Ayadn::Authorize
- Inherits:
-
Object
- Object
- Ayadn::Authorize
- Defined in:
- lib/ayadn/authorize.rb
Instance Method Summary collapse
- #authorize ⇒ Object
-
#initialize ⇒ Authorize
constructor
A new instance of Authorize.
- #unauthorize(user, options) ⇒ Object
Constructor Details
#initialize ⇒ Authorize
Returns a new instance of Authorize.
5 6 7 8 |
# File 'lib/ayadn/authorize.rb', line 5 def initialize @thor = Thor::Shell::Color.new # local statuses @status = Status.new # global statuses + utils end |
Instance Method Details
#authorize ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ayadn/authorize.rb', line 10 def puts "\n" if File.exist?(Dir.home + "/ayadn/accounts.db") @status.has_to_migrate exit end puts "\e[H\e[2J" show_link token = get_token check_token(token) puts "\e[H\e[2J" @thor.say_status :connexion, "downloading user info", :yellow user = create_user_data(token, Dir.home + "/ayadn") prepare(user) @thor.say_status :create, "configuration", :yellow Settings.load_config Logs.create_logger install @thor.say_status :done, "user #{user.handle} is authorized", :green Errors.info "#{user.handle} authorized." @status.say { @thor.say_status :end, "Thank you for using Ayadn. Enjoy!", :green } Switch.new.list end |
#unauthorize(user, options) ⇒ Object
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 63 64 65 66 |
# File 'lib/ayadn/authorize.rb', line 34 def (user, ) begin @workers = Workers.new if user.size > 1 @status.one_username exit end user = @workers.remove_arobase_if_present(user)[0] puts "\e[H\e[2J" if [:delete] sure = @thor.yes?("Are you sure you want to unauthorize user @#{user} and delete its folders?\n\n> ", :red) else sure = @thor.yes?("Are you sure you want to unauthorize user @#{user} ?\n\n> ", :red) end unless sure == true Status.new.canceled exit end puts "\e[H\e[2J" @thor.say_status :delete, "database entry for @#{user}", :yellow db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite") Databases.remove_from_accounts(db, user) if [:delete] @thor.say_status :delete, "@#{user} user folders", :yellow FileUtils.remove_dir(Dir.home + "/ayadn/#{user}") end @thor.say_status :done, "user @#{user} has been unauthorized", :green puts "\n" rescue Interrupt Status.new.canceled exit end end |