From aacd9da9fb71e93e4515a81f68bbebaa3fc35cd8 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 30 Apr 2012 14:29:42 +0800 Subject: [PATCH] =?UTF-8?q?auto=20login=20encryption=20done=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/assets/javascripts/orbitdesktop.js | 2 +- app/controllers/otheraccounts_controller.rb | 10 ++++++++-- .../{other_accounts.rb => other_account.rb} | 6 +++--- app/models/user/user.rb | 2 +- .../desktop/settings/connections.html.erb | 3 ++- public/desktop_widgets/gmail/gmail.js | 19 ++++--------------- public/desktop_widgets/gmail/index.html.erb | 15 ++------------- 9 files changed, 28 insertions(+), 36 deletions(-) rename app/models/{other_accounts.rb => other_account.rb} (56%) diff --git a/Gemfile b/Gemfile index d1afdb8c..11a9dc2e 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'sinatra' gem 'sprockets' gem 'tinymce-rails' gem 'therubyracer' if RUBY_PLATFORM.downcase.include?("linux") +gem 'mongoid-encryptor', :require => 'mongoid/encryptor' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 71742974..339bae0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,7 @@ GEM orm_adapter (~> 0.0.3) warden (~> 1.1) diff-lcs (1.1.3) + encrypted_strings (0.3.3) erubis (2.7.0) exception_notification (2.5.2) actionmailer (>= 3.0.4) @@ -115,6 +116,10 @@ GEM activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) + mongoid-encryptor (0.0.5) + activesupport (~> 3.0) + encrypted_strings (~> 0.3.3) + mongoid (~> 2) multi_json (1.1.0) nokogiri (1.5.2) nokogiri (1.5.2-x86-mingw32) @@ -255,6 +260,7 @@ DEPENDENCIES mini_magick mongo_session_store-rails3 mongoid + mongoid-encryptor nokogiri radius rails (>= 3.1.0, < 3.2.0) diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 33aab4fc..bccaa7af 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -141,7 +141,7 @@ var orbitDesktop = function(dom){ var bindHandlers = function(){ // this function will bind all the handlers in the desktop var groupWrapperWidth = 0; var groupWrapperHeight = 0; - $('div#desktop div.group').width(528); + $('div#desktop div.group').width(800); $("div#desktop .element").mousedown(function(){ currentElement = $(this); elementParent = $(this).parent(); diff --git a/app/controllers/otheraccounts_controller.rb b/app/controllers/otheraccounts_controller.rb index f5051cb8..2f76c905 100644 --- a/app/controllers/otheraccounts_controller.rb +++ b/app/controllers/otheraccounts_controller.rb @@ -9,13 +9,19 @@ class OtheraccountsController< ApplicationController @email = params['email'] @password = params['password'] @account = params['account'] - OtherAccount.new(email: @email, encrypted_password: @password, type: @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 params['username'], params['password'] + req.basic_auth @email, @decrypted_password req.content_type = 'text/xml' http = Net::HTTP.new(url.host, url.port) diff --git a/app/models/other_accounts.rb b/app/models/other_account.rb similarity index 56% rename from app/models/other_accounts.rb rename to app/models/other_account.rb index b702974f..2b660666 100644 --- a/app/models/other_accounts.rb +++ b/app/models/other_account.rb @@ -1,15 +1,15 @@ class OtherAccount include Mongoid::Document include Mongoid::Timestamps + include Mongoid::Encryptor + field :user_id field :type field :email field :encrypted_password - attr_encrypted :encrypted_password, :key => 'rulingorbit.com', :encode => true + encrypts :encrypted_password, :mode => :symmetric, :password => 'rulingcom' belongs_to :user - - end \ No newline at end of file diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 84f556c2..2b405e16 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -17,7 +17,7 @@ class User has_many :managing_apps,:class_name => "AppManager" has_one :desktop, :autosave => true, :dependent => :destroy - has_many :otheraccount, :autosave => true, :dependent => :destroy + has_many :other_accounts, :autosave => true, :dependent => :destroy belongs_to :role has_and_belongs_to_many :sub_roles accepts_nested_attributes_for :attribute_values, :allow_destroy => true diff --git a/app/views/desktop/settings/connections.html.erb b/app/views/desktop/settings/connections.html.erb index cac2acd7..44a4e044 100644 --- a/app/views/desktop/settings/connections.html.erb +++ b/app/views/desktop/settings/connections.html.erb @@ -10,7 +10,8 @@ - + + Connect diff --git a/public/desktop_widgets/gmail/gmail.js b/public/desktop_widgets/gmail/gmail.js index 3a267e74..e7d2218f 100644 --- a/public/desktop_widgets/gmail/gmail.js +++ b/public/desktop_widgets/gmail/gmail.js @@ -1,20 +1,10 @@ var gmail = function(){ - var usernm = $("#gmail input[type=text]").val(); - var pwd = $("#gmail input[type=password]").val(); -// usernm = "hr@rulingcom.com"; -// pwd = "hr08973" - if(usernm!="" && pwd!=""){ - $("#gmail a#gmail_button").text("Check again"); - $("#gmail #loading").show(); - $("#gmail table#form").hide(); $.ajax({ url: "/desktop/forgmail", dataType : "xml", - data : {username:usernm,password:pwd}, success:function(data){ if($(data).find("HEAD").find("TITLE").text()=="Unauthorized"){ $("#gmail #forerror").text($(data).find("HEAD").find("TITLE").text()).show(); - $("#gmail table#form").show(); }else{ if($(data).find("fullcount").text()=="0"){ $("#gmail #forerror").hide(); @@ -22,9 +12,9 @@ var gmail = function(){ }else{ var msg; if($(data).find("fullcount").text()=="1") - msg = $(data).find("fullcount").text()+" unread message in your inbox." + msg = $(data).find("fullcount").text()+" unread message in your inbox."; else - msg = $(data).find("fullcount").text()+" unread messages in your inbox." + msg = $(data).find("fullcount").text()+" unread messages in your inbox."; o.notify(msg,"alert",2); $(data).find("entry").each(function(i,val){ if(i==0){ @@ -41,15 +31,14 @@ var gmail = function(){ $("#gmail #content").show(); } }); - } } var saveaccount = function(){ var usernm = $("#gmail input[type=text]").val(); var pwd = $("#gmail input[type=password]").val(); - usernm = "hr@rulingcom.com"; + usernm = "harry@rulingcom.com"; pwd = "hr08973"; if(usernm!="" && pwd!=""){ - $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:"gmail"}) + $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:"yahoo"}) } } \ No newline at end of file diff --git a/public/desktop_widgets/gmail/index.html.erb b/public/desktop_widgets/gmail/index.html.erb index 95880c08..f66a98c9 100644 --- a/public/desktop_widgets/gmail/index.html.erb +++ b/public/desktop_widgets/gmail/index.html.erb @@ -1,17 +1,6 @@
- - - - - - - - - - -
Check for new mail
- +
Retrieving new emails...
\ No newline at end of file