orbit-basic/app/controllers/otheraccounts_controller.rb

41 lines
1.3 KiB
Ruby
Raw Normal View History

2012-04-26 09:23:47 +00:00
class OtheraccountsController< ApplicationController
2012-04-26 06:47:49 +00:00
require 'open-uri'
require 'rexml/document'
require 'net/http'
require 'net/https'
include REXML
def saveaccountinfo
@dowhat = params['dowhat']
@email = params['email']
@password = params['password']
@account = params['account']
case @dowhat
when "new"
OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account)
when "edit"
@otheraccount = OtherAccount.where(:type.all => [@account],:user_id.all => [current_user.id])
@otheraccount.first.update_attributes(:email => @email, :encrypted_password => @password)
end
2012-04-30 06:29:42 +00:00
a = Array.new
a << {"success"=>"true"}
render :json=>a.to_json
end
2012-04-26 09:23:47 +00:00
def gmail
2012-04-30 06:29:42 +00:00
@gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id])
@decrypted_password = @gmailaccount.first.encrypted_password.decrypt
@email = @gmailaccount.first.email
2012-04-26 06:47:49 +00:00
url = URI.parse("https://mail.google.com/mail/feed/atom")
req = Net::HTTP::Get.new(url.path)
2012-04-30 06:29:42 +00:00
req.basic_auth @email, @decrypted_password
2012-04-26 06:47:49 +00:00
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