<s> import htmlutils <EOL> import page <EOL> import auth <EOL> import dbutils <EOL> import configuration <EOL> from page . parameters import Optional <EOL> class CreateUserHandler ( page . Page . Handler ) : <EOL> def __init__ ( self , target = None , username = None , email = None , fullname = None , <EOL> provider = None , account = None , token = None ) : <EOL> super ( CreateUserHandler , self ) . __init__ ( ) <EOL> self . target = target <EOL> self . username = username <EOL> self . email = email <EOL> self . fullname = fullname <EOL> self . provider = provider <EOL> self . account = account <EOL> self . token = token <EOL> def generateHeader ( self ) : <EOL> self . document . addExternalStylesheet ( "<STR_LIT>" ) <EOL> self . document . addExternalScript ( "<STR_LIT>" ) <EOL> if self . target : <EOL> self . document . addInternalScript ( <EOL> "<STR_LIT>" % htmlutils . jsify ( self . target ) ) <EOL> def generateContent ( self ) : <EOL> table = page . utils . PaleYellowTable ( self . body , "<STR_LIT>" ) <EOL> if self . provider and self . token and self . provider in auth . PROVIDERS : <EOL> provider = auth . PROVIDERS [ self . provider ] <EOL> if not provider . validateToken ( self . db , self . account , self . token ) : <EOL> raise page . utils . DisplayMessage ( "<STR_LIT>" ) <EOL> allow_user_registration = provider . configuration . get ( "<STR_LIT>" , False ) <EOL> else : <EOL> provider = None <EOL> allow_user_registration = configuration . base . ALLOW_USER_REGISTRATION <EOL> if not allow_user_registration : <EOL> administrators = dbutils . getAdministratorContacts ( <EOL> self . db , as_html = True ) <EOL> raise page . utils . DisplayMessage ( <EOL> title = "<STR_LIT>" , <EOL> body = ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> % administrators ) , <EOL> html = True ) <EOL> def render ( target ) : <EOL> table = target . table ( "<STR_LIT>" , align = "<STR_LIT>" ) <EOL> def header ( label ) : <EOL> row = table . tr ( "<STR_LIT>" ) <EOL> row . td ( colspan = <NUM_LIT:2> ) . text ( label ) <EOL> def item ( key ) : <EOL> row = table . tr ( "<STR_LIT>" ) <EOL> row . td ( "<STR_LIT:key>" ) . text ( "<STR_LIT>" % key ) <EOL> return row . td ( "<STR_LIT:value>" ) <EOL> def button ( class_name ) : <EOL> row = table . tr ( "<STR_LIT>" ) <EOL> return row . td ( colspan = <NUM_LIT:2> ) . button ( class_name ) <EOL> def separator ( ) : <EOL> table . tr ( "<STR_LIT>" ) . td ( colspan = <NUM_LIT:2> ) <EOL> table . tr ( "<STR_LIT>" ) . td ( colspan = <NUM_LIT:2> ) <EOL> if provider : <EOL> self . document . addInternalScript ( <EOL> "<STR_LIT>" <EOL> % ( htmlutils . jsify ( self . provider ) , <EOL> htmlutils . jsify ( self . account ) , <EOL> htmlutils . jsify ( self . token ) ) ) <EOL> url = provider . getAccountURL ( self . account ) <EOL> item ( provider . getTitle ( ) ) . a ( "<STR_LIT>" , href = url ) . text ( self . account ) <EOL> separator ( ) <EOL> else : <EOL> self . document . addInternalScript ( "<STR_LIT>" ) <EOL> message = table . tr ( "<STR_LIT>" ) . td ( colspan = <NUM_LIT:2> ) . div ( "<STR_LIT:message>" ) <EOL> if self . username : <EOL> try : <EOL> dbutils . User . fromName ( self . db , self . username ) <EOL> except dbutils . NoSuchUser : <EOL> try : <EOL> auth . validateUserName ( self . username ) <EOL> except auth . InvalidUserName as error : <EOL> message . u ( "<STR_LIT>" ) <EOL> message . br ( ) <EOL> message . text ( str ( error ) ) <EOL> else : <EOL> message . text ( "<STR_LIT>" <EOL> % self . username ) <EOL> item ( "<STR_LIT>" ) . input ( id = "<STR_LIT>" , value = self . username , size = <NUM_LIT> ) <EOL> item ( "<STR_LIT>" ) . input ( id = "<STR_LIT>" , value = self . fullname , size = <NUM_LIT> ) <EOL> item ( "<STR_LIT>" ) . input ( id = "<STR_LIT:email>" , value = self . email , size = <NUM_LIT> ) <EOL> if not provider : <EOL> separator ( ) <EOL> item ( "<STR_LIT>" ) . input ( id = "<STR_LIT>" , type = "<STR_LIT:password>" , size = <NUM_LIT> ) <EOL> item ( "<STR_LIT>" ) . input ( id = "<STR_LIT>" , type = "<STR_LIT:password>" , size = <NUM_LIT> ) <EOL> button ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> table . addCentered ( render ) <EOL> class CreateUser ( page . Page ) : <EOL> def __init__ ( self ) : <EOL> super ( CreateUser , self ) . __init__ ( "<STR_LIT>" , <EOL> { "<STR_LIT:target>" : Optional ( str ) , <EOL> "<STR_LIT:username>" : Optional ( str ) , <EOL> "<STR_LIT:email>" : Optional ( str ) , <EOL> "<STR_LIT>" : Optional ( str ) , <EOL> "<STR_LIT>" : Optional ( str ) , <EOL> "<STR_LIT>" : Optional ( str ) , <EOL> "<STR_LIT>" : Optional ( str ) } , <EOL> CreateUserHandler ) </s>
