def testRegisterEmailDoesNotAlreadyExistClubSpecifiedConnectionNotSpecified( self): dbName = "users/users.db" userDb = UserDatabase(dbName) userDb.emailSender = DummyEmailSender() userDb.createDatabase(None, True) email = "jeremy" name = "Jeremy" club = "Rotherham" password = "******" result = userDb.registerUser(email, name, club, password) conn = userDb.getConnection(None) c = conn.cursor() try: row = c.execute( "select id, email, name, club, status from user").fetchone() self.assertEquals( (result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result, )).fetchone() self.assertEquals((password, ), row) finally: conn.close() self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
def testRegisterBlocked(self): conn = self.inMemoryDatabaseConnection() email = "*****@*****.**" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) self.assertEquals(-1, result) c = conn.cursor() row = c.execute("select id, email, name, club, status from user").fetchone() self.assertEquals(None, row) row = c.execute("select password from password where id = ?", (result,)).fetchone() self.assertEquals(None, row) self.assertEquals([], userDb.emailSender.messages)
def testRegisterEmailDoesNotAlreadyExistClubNotSpecified(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) c = conn.cursor() row = c.execute("select id, email, name, club, status from user").fetchone() self.assertEquals((result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result,)).fetchone() self.assertEquals((password,), row) self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
def testRegisterBlocked(self): conn = self.inMemoryDatabaseConnection() email = "*****@*****.**" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) self.assertEquals(-1, result) c = conn.cursor() row = c.execute( "select id, email, name, club, status from user").fetchone() self.assertEquals(None, row) row = c.execute("select password from password where id = ?", (result, )).fetchone() self.assertEquals(None, row) self.assertEquals([], userDb.emailSender.messages)
def testRegisterEmailDoesNotAlreadyExistClubNotSpecified(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) c = conn.cursor() row = c.execute( "select id, email, name, club, status from user").fetchone() self.assertEquals( (result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result, )).fetchone() self.assertEquals((password, ), row) self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
def testRegisterEmailDoesNotAlreadyExistClubSpecifiedConnectionNotSpecified(self): dbName = "users/users.db" userDb = UserDatabase(dbName) userDb.emailSender = DummyEmailSender() userDb.createDatabase(None, True) email = "jeremy" name = "Jeremy" club = "Rotherham" password = "******" result = userDb.registerUser(email, name, club, password) conn = userDb.getConnection(None) c = conn.cursor() try: row = c.execute("select id, email, name, club, status from user").fetchone() self.assertEquals((result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result,)).fetchone() self.assertEquals((password,), row) finally: conn.close() self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
class UserRegistration(Page): def __init__(self, pageId, params={}): Page.__init__(self, pageId, params) self.userDb = UserDatabase() def getTitle(self): answer = "SEHICL User Registration" return answer def getContent(self): if (self.allParams.get("displayed", None) == "true"): processingOutcome = self.processRegistrationData() if processingOutcome.valid: answer = self.getRegistrationConfirmationPage() else: answer = self.getRegistrationPage(processingOutcome) else: answer = self.getRegistrationPage() return answer def getRegistrationPage(self, validation=RegistrationValidation()): html = """ <h1>New user registration</h1> <p> Please fill in the fields below and press "Submit". All fields marked with "*" must be completed. </p> <form action="{submit.url}" method="post"> <input type="hidden" name="displayed" value="true"> <input type="hidden" name="forward" value="{forward}"> <table> <tr> <td>Name</td> <td>*</td> <td><input type="text" name="name" value="{valid.name}"></td> <td>{valid.nameMessage}</td> </tr> <tr> <td>Club</td> <td></td> <td><input type="text" name="club" value="{club}"></td> <td>{valid.clubMessage}</td> </tr> <tr> <td>E-mail address</td> <td>*</td> <td><input type="text" name="email" value="{valid.email}"></td> <td>{valid.emailMessage}</td> </tr> <tr> <td>Password</td> <td>*</td> <td><input type="password" name="password""></td> <td>{valid.passwordMessage}</td> </tr> <tr> <td>Confirm password</td> <td>*</td> <td><input type="password" name="passwordconf""></td> <td>{valid.passwordconfMessage}</td> </tr> </table> <p> By clicking the "Submit" button below, you agree that: <ul> <li> We may store the information you have supplied on a computer system, and we may use it only for the purpose of administering your rights as a registered user of this site. We will never give your details to any other party. </li> <li> You will treat all information to which your login gives you access with appropriate care and respect. In particular, where that information comprises other people's personal details, you may use it only for legitimate purposes connected with the League, unless you first gain the explicit consent of the person or persons concerned. </li> </ul> </p> <p> <input type="Submit" value="Submit"> </p> </form> """ submitLink = PageLink("register", self) club = "" if validation.club is None else validation.club forward = self.allParams.get("forward", PageLink(None, self).url) answer = html.format(submit=submitLink, valid=validation, forward=forward, club=club) return answer def processRegistrationData(self): answer = RegistrationValidation() answer.name = string.strip(self.allParams.get("name", "")) if answer.name == "": answer.valid = False answer.nameMessage = "Please specify your name." club = self.allParams.get("club", None) if club is not None: club = string.strip(club) if club == "": club = None answer.club = club answer.email = string.strip(self.allParams.get("email", "")) if answer.email == "": answer.valid = False answer.emailMessage = "Please specify your e-mail address." answer.password = string.strip(self.allParams.get("password", "")) if answer.password == "": answer.valid = False answer.passwordMessage = "Please specify your password." answer.passwordconf = string.strip(self.allParams.get("passwordconf", "")) if answer.passwordconf == "": answer.valid = False answer.passwordconfMessage = "Please confirm your password." elif answer.passwordconf != answer.password: answer.valid = False answer.passwordconfMessage = "Password and Confirm password must be the same." if answer.valid: try: self.userDb.registerUser(answer.email, answer.name, answer.club, answer.password) except UserException as ex: answer.valid = False answer.emailMessage = ex.message return answer def getRegistrationConfirmationPage(self): html = """ <h1>Registration successful</h1> <p>Thank you for registering. Your account has been set up, but needs to be activated.</p> <p>An e-mail has been sent to {email}. It contains a link, which you need to click in order to activate the account. Once you have done this the account will be active and you will be able to log in.</p> """ answer = html.format(email=self.allParams["email"]) return answer
class UserRegistration(Page): def __init__(self, pageId, params={}): Page.__init__(self, pageId, params) self.userDb = UserDatabase() def getTitle(self): answer = "SEHICL User Registration" return answer def getContent(self): if (self.allParams.get("displayed", None) == "true"): processingOutcome = self.processRegistrationData() if processingOutcome.valid: answer = self.getRegistrationConfirmationPage() else: answer = self.getRegistrationPage(processingOutcome) else: answer = self.getRegistrationPage() return answer def getRegistrationPage(self, validation=RegistrationValidation()): html = """ <h1>New user registration</h1> <p> Please fill in the fields below and press "Submit". All fields marked with "*" must be completed. </p> <form action="{submit.url}" method="post"> <input type="hidden" name="displayed" value="true"> <input type="hidden" name="forward" value="{forward}"> <table> <tr> <td>Name</td> <td>*</td> <td><input type="text" name="name" value="{valid.name}"></td> <td>{valid.nameMessage}</td> </tr> <tr> <td>Club</td> <td></td> <td><input type="text" name="club" value="{club}"></td> <td>{valid.clubMessage}</td> </tr> <tr> <td>E-mail address</td> <td>*</td> <td><input type="text" name="email" value="{valid.email}"></td> <td>{valid.emailMessage}</td> </tr> <tr> <td>Password</td> <td>*</td> <td><input type="password" name="password""></td> <td>{valid.passwordMessage}</td> </tr> <tr> <td>Confirm password</td> <td>*</td> <td><input type="password" name="passwordconf""></td> <td>{valid.passwordconfMessage}</td> </tr> </table> <p> By clicking the "Submit" button below, you agree that: <ul> <li> We may store the information you have supplied on a computer system, and we may use it only for the purpose of administering your rights as a registered user of this site. We will never give your details to any other party. </li> <li> You will treat all information to which your login gives you access with appropriate care and respect. In particular, where that information comprises other people's personal details, you may use it only for legitimate purposes connected with the League, unless you first gain the explicit consent of the person or persons concerned. </li> </ul> </p> <p> <input type="Submit" value="Submit"> </p> </form> """ submitLink = PageLink("register", self) club = "" if validation.club is None else validation.club forward = self.allParams.get("forward", PageLink(None, self).url) answer = html.format(submit=submitLink, valid=validation, forward=forward, club=club) return answer def processRegistrationData(self): answer = RegistrationValidation() answer.name = string.strip(self.allParams.get("name", "")) if answer.name == "": answer.valid = False answer.nameMessage = "Please specify your name." club = self.allParams.get("club", None) if club is not None: club = string.strip(club) if club == "": club = None answer.club = club answer.email = string.strip(self.allParams.get("email", "")) if answer.email == "": answer.valid = False answer.emailMessage = "Please specify your e-mail address." answer.password = string.strip(self.allParams.get("password", "")) if answer.password == "": answer.valid = False answer.passwordMessage = "Please specify your password." answer.passwordconf = string.strip( self.allParams.get("passwordconf", "")) if answer.passwordconf == "": answer.valid = False answer.passwordconfMessage = "Please confirm your password." elif answer.passwordconf != answer.password: answer.valid = False answer.passwordconfMessage = "Password and Confirm password must be the same." if answer.valid: try: self.userDb.registerUser(answer.email, answer.name, answer.club, answer.password) except UserException as ex: answer.valid = False answer.emailMessage = ex.message return answer def getRegistrationConfirmationPage(self): html = """ <h1>Registration successful</h1> <p>Thank you for registering. Your account has been set up, but needs to be activated.</p> <p>An e-mail has been sent to {email}. It contains a link, which you need to click in order to activate the account. Once you have done this the account will be active and you will be able to log in.</p> """ answer = html.format(email=self.allParams["email"]) return answer
import sqlite3 from userdb.userdb import UserDatabase from test.users.userdbtest import DummyEmailSender conn = sqlite3.connect("users/users.db") userDb = UserDatabase(emailSender=DummyEmailSender()) userDb.createDatabase(conn, True) userId = userDb.registerUser("*****@*****.**", "User Admin", None, "wceag1es", conn) userDb.activateUser(userId, conn) conn.cursor().execute("insert into role (id, role) values(?, 'admin')", (userId, )) conn.commit() conn.close()