Exemple #1
0
 def testRemindOfPasswordEmailDoesNotExist(self):
     conn = self.inMemoryDatabaseConnection()
     email = "jeremy"
     userDb = UserDatabase()
     userDb.emailSender = DummyEmailSender()
     try:
         userDb.remindOfPassword(email, conn)
         self.fail("Should have thrown an exception")
     except UserException as ex:
         self.assertEquals(UserException.emailNotFound, ex.message)
         self.assertEquals(None, ex.cause)
Exemple #2
0
 def testRemindOfPasswordEmailExists(self):
     conn = self.inMemoryDatabaseConnection()
     email = "jeremy"
     password = "******"
     c = conn.cursor()
     c.execute("insert into user (id, email) values (?, ?)", (1, email))
     c.execute("insert into password (id, password) values (?, ?)", (1, password))
     userDb = UserDatabase()
     userDb.emailSender = DummyEmailSender()
     userDb.remindOfPassword(email, conn)
     self.assertEquals([email], userDb.emailSender.messages[0].addressees)
Exemple #3
0
 def testRemindOfPasswordEmailDoesNotExist(self):
     conn = self.inMemoryDatabaseConnection()
     email = "jeremy"
     userDb = UserDatabase()
     userDb.emailSender = DummyEmailSender()
     try:
         userDb.remindOfPassword(email, conn)
         self.fail("Should have thrown an exception")
     except UserException as ex:
         self.assertEquals(UserException.emailNotFound, ex.message)
         self.assertEquals(None, ex.cause)
Exemple #4
0
 def testRemindOfPasswordEmailExists(self):
     conn = self.inMemoryDatabaseConnection()
     email = "jeremy"
     password = "******"
     c = conn.cursor()
     c.execute("insert into user (id, email) values (?, ?)", (1, email))
     c.execute("insert into password (id, password) values (?, ?)",
               (1, password))
     userDb = UserDatabase()
     userDb.emailSender = DummyEmailSender()
     userDb.remindOfPassword(email, conn)
     self.assertEquals([email], userDb.emailSender.messages[0].addressees)
Exemple #5
0
class UserLogin(Page):
    
    msgKeyNoLogin = "******"
    msgKeyNoAuth = "noAuth"
    messages = {}
    messages[msgKeyNoLogin] = "You must be logged in to view the requested page."
    messages[msgKeyNoAuth] = "You do not have the necessary authority ('{role}') to view the requested page."
    
    def __init__(self, pageId, params={}):
        Page.__init__(self, pageId, params)
        self.userDb = UserDatabase()

    def getTitle(self):
        answer = "SEHICL User Login"
        return answer
    
    def getContent(self):
        if (self.allParams.get("displayed", None) == "true"):
            processingOutcome = self.processLoginData()
            if processingOutcome.valid:
                if processingOutcome.token is not None:
                    self.allParams["session"] = processingOutcome.token
                    pageLink = PageLink(self.allParams["forward"], self) 
                    raise RedirectException(pageLink)
                else:
                    answer = self.getLoginPage(processingOutcome)
            else:
                answer = self.getLoginPage(processingOutcome)
        else:
            answer = self.getLoginPage()
        return answer

    def getLoginPage(self, validation=LoginValidation()):
        html = """
        <h1>Login</h1>
        {message}
        <p>
            If you do not have a login, <a href="{register.url}">register here</a>.<br>
            Please note that if you registered for a login during the 2012-13 season, that login
            no longer works and you must re-register.
        </p>
        <p>
            If you have already registered, please fill in the fields below and press "Login".
            If you cannot remember your password, fill in the e-mail address and press 
            "Remind"; if the e-mail address you specify is that of a registered user, a password
            reminder will be sent to that address.
        </p>
        <form action="{submit.url}" method="post">
            <input type="hidden" name="displayed" value="true">
            <table>
                <tr>
                    <td>E-mail address</td>
                    <td><input type="text" name="email" value="{valid.email}"></td>
                    <td>{valid.emailMessage}</td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password" value="{valid.password}"></td>
                    <td>{valid.passwordMessage}</td>
                </tr>
            </table>
            <p>
                <input name="button" type="Submit" value="Login">
                <input name="button" type="Submit" value="Remind">
            </p>
        </form>
        """
        params = {}
        for k, v in self.allParams.items():
            if k in ("message", "role", "forward"):
                params[k] = v
        submitLink = PageLink("login", self, params)
        registerLink = PageLink("register", self)
        msgKey = self.allParams.get("message", None)
        msgTemplate = self.messages.get(msgKey, "")
        message = msgTemplate.format(role=self.allParams.get("role", None))
        answer = html.format(submit=submitLink, valid=validation, message=message, register=registerLink)
        return answer

    def processLoginData(self):
        answer = LoginValidation()
        buttonPressed = self.allParams.get("button", "") 
        answer.email = string.strip(self.allParams.get("email", ""))
        if answer.email == "":
            answer.valid = False
            answer.emailMessage = "Please specify your e-mail address."
        if buttonPressed != "Remind":
            answer.password = string.strip(self.allParams.get("password", ""))
            if answer.password == "":
                answer.valid = False
                answer.passwordMessage = "Please specify your password."
        if answer.valid:
            try:
                if buttonPressed == "Remind":
                    self.userDb.remindOfPassword(answer.email)
                    answer.token = None
                    answer.emailMessage = "A password reminder has been sent to this address."
                else:
                    answer.token = self.userDb.login(answer.email, answer.password)
            except UserException as ex:
                answer.valid = False
                answer.emailMessage = ex.message
        return answer
Exemple #6
0
class UserLogin(Page):

    msgKeyNoLogin = "******"
    msgKeyNoAuth = "noAuth"
    messages = {}
    messages[
        msgKeyNoLogin] = "You must be logged in to view the requested page."
    messages[
        msgKeyNoAuth] = "You do not have the necessary authority ('{role}') to view the requested page."

    def __init__(self, pageId, params={}):
        Page.__init__(self, pageId, params)
        self.userDb = UserDatabase()

    def getTitle(self):
        answer = "SEHICL User Login"
        return answer

    def getContent(self):
        if (self.allParams.get("displayed", None) == "true"):
            processingOutcome = self.processLoginData()
            if processingOutcome.valid:
                if processingOutcome.token is not None:
                    self.allParams["session"] = processingOutcome.token
                    pageLink = PageLink(self.allParams["forward"], self)
                    raise RedirectException(pageLink)
                else:
                    answer = self.getLoginPage(processingOutcome)
            else:
                answer = self.getLoginPage(processingOutcome)
        else:
            answer = self.getLoginPage()
        return answer

    def getLoginPage(self, validation=LoginValidation()):
        html = """
        <h1>Login</h1>
        {message}
        <p>
            If you do not have a login, <a href="{register.url}">register here</a>.<br>
            Please note that if you registered for a login during the 2012-13 season, that login
            no longer works and you must re-register.
        </p>
        <p>
            If you have already registered, please fill in the fields below and press "Login".
            If you cannot remember your password, fill in the e-mail address and press 
            "Remind"; if the e-mail address you specify is that of a registered user, a password
            reminder will be sent to that address.
        </p>
        <form action="{submit.url}" method="post">
            <input type="hidden" name="displayed" value="true">
            <table>
                <tr>
                    <td>E-mail address</td>
                    <td><input type="text" name="email" value="{valid.email}"></td>
                    <td>{valid.emailMessage}</td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password" value="{valid.password}"></td>
                    <td>{valid.passwordMessage}</td>
                </tr>
            </table>
            <p>
                <input name="button" type="Submit" value="Login">
                <input name="button" type="Submit" value="Remind">
            </p>
        </form>
        """
        params = {}
        for k, v in self.allParams.items():
            if k in ("message", "role", "forward"):
                params[k] = v
        submitLink = PageLink("login", self, params)
        registerLink = PageLink("register", self)
        msgKey = self.allParams.get("message", None)
        msgTemplate = self.messages.get(msgKey, "")
        message = msgTemplate.format(role=self.allParams.get("role", None))
        answer = html.format(submit=submitLink,
                             valid=validation,
                             message=message,
                             register=registerLink)
        return answer

    def processLoginData(self):
        answer = LoginValidation()
        buttonPressed = self.allParams.get("button", "")
        answer.email = string.strip(self.allParams.get("email", ""))
        if answer.email == "":
            answer.valid = False
            answer.emailMessage = "Please specify your e-mail address."
        if buttonPressed != "Remind":
            answer.password = string.strip(self.allParams.get("password", ""))
            if answer.password == "":
                answer.valid = False
                answer.passwordMessage = "Please specify your password."
        if answer.valid:
            try:
                if buttonPressed == "Remind":
                    self.userDb.remindOfPassword(answer.email)
                    answer.token = None
                    answer.emailMessage = "A password reminder has been sent to this address."
                else:
                    answer.token = self.userDb.login(answer.email,
                                                     answer.password)
            except UserException as ex:
                answer.valid = False
                answer.emailMessage = ex.message
        return answer