Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*Login Form (mainly to be used in Pyramid apps)* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import object 

10import sys 

11import os 

12from fundamentals import tools, times 

13import khufu 

14 

15class login_form(object): 

16 """ 

17 *The worker class for the login_form module* 

18 

19 **Key Arguments** 

20 

21 - ``log`` -- logger 

22 - ``iconPath`` -- path to webapp icon 

23 - ``message`` -- message to display (warning) 

24  

25 """ 

26 

27 def __init__( 

28 self, 

29 log, 

30 iconPath, 

31 message 

32 ): 

33 self.log = log 

34 log.debug("instansiating a new 'login_form' object") 

35 self.iconPath = iconPath 

36 self.message = message 

37 

38 # xt-self-arg-tmpx 

39 

40 # BUILD IMAGE WITH ICON PATH 

41 self.icon = khufu.image( 

42 src=iconPath, # [ industrial | gray | social ] 

43 href=False, 

44 display="circle", # [ rounded | circle | polaroid | False ] 

45 pull=False 

46 ) 

47 

48 return None 

49 

50 def close(self): 

51 del self 

52 return None 

53 

54 def get(self): 

55 """ 

56 *get the login_form object* 

57 

58 **Return** 

59 

60 - ``formContent`` -- the content of the login form 

61  

62 """ 

63 self.log.debug('starting the ``get`` method') 

64 

65 formContent = self._setup_form() 

66 

67 self.log.debug('completed the ``get`` method') 

68 return formContent 

69 

70 def _setup_form( 

71 self): 

72 """ 

73 *setup loging form* 

74 

75 **Return** 

76 

77 - ``formContent`` -- content of the login form 

78  

79 """ 

80 self.log.debug('starting the ``_setup_form`` method') 

81 

82 # username input 

83 username = khufu.formInput( 

84 ttype='text', 

85 placeholder='username', 

86 span=12, 

87 htmlId="login", 

88 required=True 

89 ) 

90 username = khufu.controlRow( 

91 inputList=[username, ] 

92 ) 

93 username = khufu.horizontalFormControlGroup( 

94 content=username, 

95 validationLevel=False 

96 ) 

97 

98 # password input 

99 password = khufu.formInput( 

100 ttype='password', 

101 placeholder='password', 

102 span=12, 

103 htmlId="password", 

104 required=True 

105 ) 

106 password = khufu.controlRow( 

107 inputList=[password, ] 

108 ) 

109 password = khufu.horizontalFormControlGroup( 

110 content=password, 

111 validationLevel=False 

112 ) 

113 

114 submit = khufu.button( 

115 buttonText='login', 

116 buttonStyle='info', 

117 buttonSize='default', # [ large | default | small | mini ] 

118 htmlId="form.submitted", 

119 submit=True 

120 ) 

121 submit = khufu.horizontalFormControlGroup( 

122 content=submit, 

123 validationLevel=False 

124 ) 

125 

126 # add a warning notification 

127 if len(self.message): 

128 self.message = khufu.alert( 

129 alertText=self.message, 

130 alertHeading="WARNING: ", 

131 extraPadding=False, 

132 alertLevel='error' 

133 ) 

134 self.message = khufu.horizontalFormControlGroup( 

135 content=self.message, 

136 validationLevel=False 

137 ) 

138 

139 formContent = khufu.form( 

140 content=self.icon + username + password + submit + self.message, 

141 formType='inline', 

142 postToScript="" 

143 ) 

144 

145 self.log.debug('completed the ``_setup_form`` method') 

146 return formContent 

147 

148 # xt-class-method