Class: ItunesController::PasswordCommand

Inherits:
ServerCommand show all
Defined in:
lib/itunesController/controllserver.rb

Overview

The password command takes the format PASSWORD:<password> and is used to log the user in if the username and password are correct.

Instance Attribute Summary

Attributes inherited from ServerCommand

#name, #requiredLoginState, #singleThreaded

Instance Method Summary collapse

Methods inherited from ServerCommand

#executeSingleThreaded, #processLine

Constructor Details

#initialize(state, itunes) ⇒ PasswordCommand

The constructor

Parameters:



224
225
226
# File 'lib/itunesController/controllserver.rb', line 224

def initialize(state,itunes)
    super(ItunesController::CommandName::PASSWORD,ServerState::DOING_AUTH,false,state,itunes)
end

Instance Method Details

#processData(line, io) ⇒ Boolean, String

The line is processed to get the password. Then the authentication deatials are checked. If they pass, then the user is now logged in and the server state changes to ItunesController::ServerState::AUTH with a reply to the client of “223 Logged in”. If the autentication check fails, then a reply “”501 Incorrect username/password“ is sent and the client is disconnected.

Parameters:

  • data (String)

    The commands parameters if their are any

  • io

    A IO Stream that is used to talk to the connected client

Returns:

  • (Boolean, String)

    The returned status of the command. If the first part is false, then the server will disconnect the client. The second part is a string message send to the client



238
239
240
241
242
243
244
245
246
# File 'lib/itunesController/controllserver.rb', line 238

def processData(line,io)
    if (line =~ /^\:(.+)$/)
        if (checkAuth(@state.user,$1))
            @state.state = ServerState::AUTHED
            return true,"223 Logged in\r\n"
        end
    end
    return false,"501 Incorrect username/password\r\n"
end