Created
January 4, 2012 22:33
-
-
Save sr3d/1562560 to your computer and use it in GitHub Desktop.
exchange_authentication.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Viewpoint::EWS::EWS.endpoint = 'https://webmail.sherweb2010.com/EWS/Exchange.asmx' | |
class << self | |
# Authenticate against @Wordnik.com Email account | |
# Viewpoint::EWS::EWS.set_auth('DOMAIN\alex_wordnik.com','password') | |
def authenticate(user, password) | |
user = user.downcase.strip | |
exchange_user = "DOMAIN\\#{user}_wordnik.com" | |
Rails.logger.debug "Authenticate for Exchange User #{exchange_user}" | |
Viewpoint::EWS::EWS.set_auth exchange_user, password | |
begin | |
# TODO: find a better way for authentication | |
inbox = Viewpoint::EWS::Folder.get_folder_by_name('Inbox') | |
# Yay! We're in! | |
email = "#{user}@wordnik.com" | |
unless @user = User.find_by_email(email) | |
@user = User.create :email => email, :name => user | |
end | |
@user | |
# user = User.new(:email => "#{user}@wordnik.com", :name => user.titlecase ) | |
rescue Exception => e | |
Rails.logger.error "Exchange EWS Failed: #{e}" | |
Rails.logger.error e.backtrace | |
raise ActiveRecord::RecordNotFound | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment