Subversion Repositories SmartDukaan

Rev

Rev 494 | Rev 766 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 14-Jul-2010

@author: ashish
'''
from shop2020.helpers.impl import DataAccessor
from shop2020.helpers.impl.DataAccessor import getSubstitutedMessage, getMessage,\
    updateMessage, addMessage, add_user, authenticate_user, delete_user, update_password,\
    initialize
from shop2020.helpers.impl.DataService import LogisticsUser
from shop2020.thriftpy.utils.ttypes import HelperServiceException
from shop2020.helpers.impl.Converters import to_t_luser

class HelperServiceHandler():
    

    def __init__(self):
        initialize()


    def sendMail(self, mail):
        
        DataAccessor.sendMail(mail)
    
    def sendText(self, message):
        """
        Parameters:
         - message
        """
        DataAccessor.sendText(message)
    
    def addMessage(self, message):
        """
        Parameters:
         - message
        """
        addMessage(message)
    
    def updateMessage(self, id, message):
        """
        Parameters:
         - id
         - message
        """
        return updateMessage(id, message)
    
    def getMessage(self, id):
        """
        Parameters:
         - id
        """
        return getMessage(id)
    
    def getSubstitutedMessage(self, id, params):
        """
        Parameters:
         - id
         - params
        """
        return getSubstitutedMessage(id, params)

    def addUser(self, username, password, warehouseId):
        """
        Parameters:
         - username
         - password
         - warehouseId
        """
        return add_user(username, password, warehouseId)
    pass
    
    def deleteUser(self, username):
        """
        Parameters:
         - username
        """
        return delete_user(username)
    pass
    
    def authenticateUser(self, username, password):
        """
        Parameters:
         - username
         - password
        """
        return authenticate_user(username, password)
    pass
    
    def updatePassword(self, username, oldPassword, newPassword):
        """
        Parameters:
         - username
         - oldPassword
         - newPassword
        """
        update_password(username, oldPassword, newPassword)
    pass

    def authenticateLogisticsUser(self, username, password):
        """
        Returns the LogisticsUser struct associated with the given username and password if they match.
        Throws an exception otherwise.
        
        Parameters:
         - username
         - password
        """
        try:
            luser = LogisticsUser.get_by(username=username, password=password)
            return to_t_luser(luser)
        except:
            raise HelperServiceException(101, "No such user")