lib/twimock/api/intent/sessions.rb in twimock-0.0.1 vs lib/twimock/api/intent/sessions.rb in twimock-0.0.2

- old
+ new

@@ -22,10 +22,12 @@ @username_or_email = body["session[username_or_email]"] @password = body["session[password]"] if !validate_request_token(@oauth_token) raise Twimock::Errors::InvalidRequestToken.new + elsif body.cancel + raise Twimock::Errors::OAuthCancelled.new elsif !(user = Twimock::User.find_by_tiwtter_id_or_email(@username_or_email)) raise Twimock::Errors::InvalidUsernameOrEmail.new elsif @password.blank? || @password != user.password raise Twimock::Errors::InvalidPassword.new end @@ -40,9 +42,15 @@ status = 302 body = "" header = { "Content-Length" => body.bytesize.to_s, "Location" => callback_url } + [ status, header, [ body ] ] + rescue Twimock::Errors::OAuthCancelled + status = 303 + body = "" + header = { "Content-Length" => body.bytesize.to_s, + "Location" => "/oauth/authorize?oauth_token=#{@oauth_token}&cancel=true" } [ status, header, [ body ] ] rescue Twimock::Errors::InvalidUsernameOrEmail, Twimock::Errors::InvalidPassword => @error response = unauthorized response[0] = 302 response[1].merge!( {"Location" => "/oauth/authenticate?oauth_token=#{@oauth_token}" })