This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/otheraccounts_controller.rb

34 lines
1.1 KiB
Ruby

class OtheraccountsController< ApplicationController
require 'open-uri'
require 'rexml/document'
require 'net/http'
require 'net/https'
include REXML
def saveaccountinfo
@email = params['email']
@password = params['password']
@account = params['account']
OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account)
a = Array.new
a << {"success"=>"true"}
render :json=>a.to_json
end
def gmail
@gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id])
@decrypted_password = @gmailaccount.first.encrypted_password.decrypt
@email = @gmailaccount.first.email
url = URI.parse("https://mail.google.com/mail/feed/atom")
req = Net::HTTP::Get.new(url.path)
req.basic_auth @email, @decrypted_password
req.content_type = 'text/xml'
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
response = http.start { |http| http.request(req) }
root = Document.new(response.read_body).root
render :text=>root
end
end