Skip to content

Instantly share code, notes, and snippets.

@cbergau
Created May 10, 2014 16:55
Show Gist options
  • Save cbergau/710d4c5715d75937101b to your computer and use it in GitHub Desktop.
Save cbergau/710d4c5715d75937101b to your computer and use it in GitHub Desktop.
My very first Pyhton Script
class LoginPresenter:
def __init__(self):
self.response = 0
def present_response(self, response):
self.response = response
class User:
def __init__(self, userid, username, password):
self.userid = userid
self.username = username
self.password = password
class Usergateway:
def __init__(self):
user1 = User(1, "christian.bergau", "123")
self.users = [user1]
def find_by_username_and_password(self, username, password):
for user in self.users:
if (user.username == username) and (user.password == password):
return user
return 0
class LoginRequest:
def __init__(self, username, password):
self.username = username
self.password = password
def get_username(self):
return self.username
def get_password(self):
return self.password
class LoginResponse:
def __init__(self, userid, success):
self.userid = userid
self.success = success
def is_successful(self):
return self.success == 1
def get_user_id(self):
return self.userid
class LoginInteractor:
def __init__(self, presenter, usergateway):
self.presenter = presenter
self.usergateway = usergateway
def execute(self, request):
response = LoginResponse
user = self.usergateway.find_by_username_and_password(request.get_username(), request.get_password())
if user == 0:
response.userid = 0
response.success = 0
else:
response.userid = user.userid
response.success = 1
self.presenter.present_response(response)
presenter = LoginPresenter()
usergateway = Usergateway()
interactor = LoginInteractor(presenter, usergateway)
request = LoginRequest("christian.bergau", "123")
interactor.execute(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment