Show More
@@ -1,310 +1,310 | |||||
1 | """ this is forms validation classes |
|
1 | """ this is forms validation classes | |
2 | http://formencode.org/module-formencode.validators.html |
|
2 | http://formencode.org/module-formencode.validators.html | |
3 | for list off all availible validators |
|
3 | for list off all availible validators | |
4 |
|
4 | |||
5 | we can create our own validators |
|
5 | we can create our own validators | |
6 |
|
6 | |||
7 | The table below outlines the options which can be used in a schema in addition to the validators themselves |
|
7 | The table below outlines the options which can be used in a schema in addition to the validators themselves | |
8 | pre_validators [] These validators will be applied before the schema |
|
8 | pre_validators [] These validators will be applied before the schema | |
9 | chained_validators [] These validators will be applied after the schema |
|
9 | chained_validators [] These validators will be applied after the schema | |
10 | allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present |
|
10 | allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present | |
11 | filter_extra_fields False If True, then keys that aren't associated with a validator are removed |
|
11 | filter_extra_fields False If True, then keys that aren't associated with a validator are removed | |
12 | if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value. |
|
12 | if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value. | |
13 | ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already |
|
13 | ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | <name> = formencode.validators.<name of validator> |
|
16 | <name> = formencode.validators.<name of validator> | |
17 | <name> must equal form name |
|
17 | <name> must equal form name | |
18 | list=[1,2,3,4,5] |
|
18 | list=[1,2,3,4,5] | |
19 | for SELECT use formencode.All(OneOf(list), Int()) |
|
19 | for SELECT use formencode.All(OneOf(list), Int()) | |
20 |
|
20 | |||
21 | """ |
|
21 | """ | |
22 | import logging |
|
22 | import logging | |
23 |
|
23 | |||
24 | import formencode |
|
24 | import formencode | |
25 | from formencode import All |
|
25 | from formencode import All | |
26 |
|
26 | |||
27 | from pylons.i18n.translation import _ |
|
27 | from pylons.i18n.translation import _ | |
28 |
|
28 | |||
29 | from rhodecode.model import validators as v |
|
29 | from rhodecode.model import validators as v | |
30 | from rhodecode import BACKENDS |
|
30 | from rhodecode import BACKENDS | |
31 |
|
31 | |||
32 | log = logging.getLogger(__name__) |
|
32 | log = logging.getLogger(__name__) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class LoginForm(formencode.Schema): |
|
35 | class LoginForm(formencode.Schema): | |
36 | allow_extra_fields = True |
|
36 | allow_extra_fields = True | |
37 | filter_extra_fields = True |
|
37 | filter_extra_fields = True | |
38 | username = v.UnicodeString( |
|
38 | username = v.UnicodeString( | |
39 | strip=True, |
|
39 | strip=True, | |
40 | min=1, |
|
40 | min=1, | |
41 | not_empty=True, |
|
41 | not_empty=True, | |
42 | messages={ |
|
42 | messages={ | |
43 | 'empty': _(u'Please enter a login'), |
|
43 | 'empty': _(u'Please enter a login'), | |
44 | 'tooShort': _(u'Enter a value %(min)i characters long or more')} |
|
44 | 'tooShort': _(u'Enter a value %(min)i characters long or more')} | |
45 | ) |
|
45 | ) | |
46 |
|
46 | |||
47 | password = v.UnicodeString( |
|
47 | password = v.UnicodeString( | |
48 | strip=False, |
|
48 | strip=False, | |
49 | min=3, |
|
49 | min=3, | |
50 | not_empty=True, |
|
50 | not_empty=True, | |
51 | messages={ |
|
51 | messages={ | |
52 | 'empty': _(u'Please enter a password'), |
|
52 | 'empty': _(u'Please enter a password'), | |
53 | 'tooShort': _(u'Enter %(min)i characters or more')} |
|
53 | 'tooShort': _(u'Enter %(min)i characters or more')} | |
54 | ) |
|
54 | ) | |
55 |
|
55 | |||
56 | remember = v.StringBoolean(if_missing=False) |
|
56 | remember = v.StringBoolean(if_missing=False) | |
57 |
|
57 | |||
58 | chained_validators = [v.ValidAuth()] |
|
58 | chained_validators = [v.ValidAuth()] | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def UserForm(edit=False, old_data={}): |
|
61 | def UserForm(edit=False, old_data={}): | |
62 | class _UserForm(formencode.Schema): |
|
62 | class _UserForm(formencode.Schema): | |
63 | allow_extra_fields = True |
|
63 | allow_extra_fields = True | |
64 | filter_extra_fields = True |
|
64 | filter_extra_fields = True | |
65 | username = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
65 | username = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
66 | v.ValidUsername(edit, old_data)) |
|
66 | v.ValidUsername(edit, old_data)) | |
67 | if edit: |
|
67 | if edit: | |
68 | new_password = All( |
|
68 | new_password = All( | |
69 | v.ValidPassword(), |
|
69 | v.ValidPassword(), | |
70 | v.UnicodeString(strip=False, min=6, not_empty=False) |
|
70 | v.UnicodeString(strip=False, min=6, not_empty=False) | |
71 | ) |
|
71 | ) | |
72 | password_confirmation = All( |
|
72 | password_confirmation = All( | |
73 | v.ValidPassword(), |
|
73 | v.ValidPassword(), | |
74 | v.UnicodeString(strip=False, min=6, not_empty=False), |
|
74 | v.UnicodeString(strip=False, min=6, not_empty=False), | |
75 | ) |
|
75 | ) | |
76 | admin = v.StringBoolean(if_missing=False) |
|
76 | admin = v.StringBoolean(if_missing=False) | |
77 | else: |
|
77 | else: | |
78 | password = All( |
|
78 | password = All( | |
79 | v.ValidPassword(), |
|
79 | v.ValidPassword(), | |
80 | v.UnicodeString(strip=False, min=6, not_empty=True) |
|
80 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
81 | ) |
|
81 | ) | |
82 | password_confirmation = All( |
|
82 | password_confirmation = All( | |
83 | v.ValidPassword(), |
|
83 | v.ValidPassword(), | |
84 | v.UnicodeString(strip=False, min=6, not_empty=False) |
|
84 | v.UnicodeString(strip=False, min=6, not_empty=False) | |
85 | ) |
|
85 | ) | |
86 |
|
86 | |||
87 | active = v.StringBoolean(if_missing=False) |
|
87 | active = v.StringBoolean(if_missing=False) | |
88 | firstname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
88 | firstname = v.UnicodeString(strip=True, min=1, not_empty=False) | |
89 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
89 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) | |
90 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) |
|
90 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) | |
91 |
|
91 | |||
92 | chained_validators = [v.ValidPasswordsMatch()] |
|
92 | chained_validators = [v.ValidPasswordsMatch()] | |
93 |
|
93 | |||
94 | return _UserForm |
|
94 | return _UserForm | |
95 |
|
95 | |||
96 |
|
96 | |||
97 | def UsersGroupForm(edit=False, old_data={}, available_members=[]): |
|
97 | def UsersGroupForm(edit=False, old_data={}, available_members=[]): | |
98 | class _UsersGroupForm(formencode.Schema): |
|
98 | class _UsersGroupForm(formencode.Schema): | |
99 | allow_extra_fields = True |
|
99 | allow_extra_fields = True | |
100 | filter_extra_fields = True |
|
100 | filter_extra_fields = True | |
101 |
|
101 | |||
102 | users_group_name = All( |
|
102 | users_group_name = All( | |
103 | v.UnicodeString(strip=True, min=1, not_empty=True), |
|
103 | v.UnicodeString(strip=True, min=1, not_empty=True), | |
104 | v.ValidUsersGroup(edit, old_data) |
|
104 | v.ValidUsersGroup(edit, old_data) | |
105 | ) |
|
105 | ) | |
106 |
|
106 | |||
107 | users_group_active = v.StringBoolean(if_missing=False) |
|
107 | users_group_active = v.StringBoolean(if_missing=False) | |
108 |
|
108 | |||
109 | if edit: |
|
109 | if edit: | |
110 | users_group_members = v.OneOf( |
|
110 | users_group_members = v.OneOf( | |
111 | available_members, hideList=False, testValueList=True, |
|
111 | available_members, hideList=False, testValueList=True, | |
112 | if_missing=None, not_empty=False |
|
112 | if_missing=None, not_empty=False | |
113 | ) |
|
113 | ) | |
114 |
|
114 | |||
115 | return _UsersGroupForm |
|
115 | return _UsersGroupForm | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | def ReposGroupForm(edit=False, old_data={}, available_groups=[]): |
|
118 | def ReposGroupForm(edit=False, old_data={}, available_groups=[]): | |
119 | class _ReposGroupForm(formencode.Schema): |
|
119 | class _ReposGroupForm(formencode.Schema): | |
120 | allow_extra_fields = True |
|
120 | allow_extra_fields = True | |
121 | filter_extra_fields = False |
|
121 | filter_extra_fields = False | |
122 |
|
122 | |||
123 | group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
123 | group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
124 | v.SlugifyName()) |
|
124 | v.SlugifyName()) | |
125 | group_description = v.UnicodeString(strip=True, min=1, |
|
125 | group_description = v.UnicodeString(strip=True, min=1, | |
126 | not_empty=True) |
|
126 | not_empty=True) | |
127 | group_parent_id = v.OneOf(available_groups, hideList=False, |
|
127 | group_parent_id = v.OneOf(available_groups, hideList=False, | |
128 | testValueList=True, |
|
128 | testValueList=True, | |
129 | if_missing=None, not_empty=False) |
|
129 | if_missing=None, not_empty=False) | |
130 |
|
130 | |||
131 | chained_validators = [v.ValidReposGroup(edit, old_data), |
|
131 | chained_validators = [v.ValidReposGroup(edit, old_data), | |
132 | v.ValidPerms('group')] |
|
132 | v.ValidPerms('group')] | |
133 |
|
133 | |||
134 | return _ReposGroupForm |
|
134 | return _ReposGroupForm | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | def RegisterForm(edit=False, old_data={}): |
|
137 | def RegisterForm(edit=False, old_data={}): | |
138 | class _RegisterForm(formencode.Schema): |
|
138 | class _RegisterForm(formencode.Schema): | |
139 | allow_extra_fields = True |
|
139 | allow_extra_fields = True | |
140 | filter_extra_fields = True |
|
140 | filter_extra_fields = True | |
141 | username = All( |
|
141 | username = All( | |
142 | v.ValidUsername(edit, old_data), |
|
142 | v.ValidUsername(edit, old_data), | |
143 | v.UnicodeString(strip=True, min=1, not_empty=True) |
|
143 | v.UnicodeString(strip=True, min=1, not_empty=True) | |
144 | ) |
|
144 | ) | |
145 | password = All( |
|
145 | password = All( | |
146 | v.ValidPassword(), |
|
146 | v.ValidPassword(), | |
147 | v.UnicodeString(strip=False, min=6, not_empty=True) |
|
147 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
148 | ) |
|
148 | ) | |
149 | password_confirmation = All( |
|
149 | password_confirmation = All( | |
150 | v.ValidPassword(), |
|
150 | v.ValidPassword(), | |
151 | v.UnicodeString(strip=False, min=6, not_empty=True) |
|
151 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
152 | ) |
|
152 | ) | |
153 | active = v.StringBoolean(if_missing=False) |
|
153 | active = v.StringBoolean(if_missing=False) | |
154 | name = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
154 | firstname = v.UnicodeString(strip=True, min=1, not_empty=False) | |
155 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
155 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) | |
156 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) |
|
156 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) | |
157 |
|
157 | |||
158 | chained_validators = [v.ValidPasswordsMatch()] |
|
158 | chained_validators = [v.ValidPasswordsMatch()] | |
159 |
|
159 | |||
160 | return _RegisterForm |
|
160 | return _RegisterForm | |
161 |
|
161 | |||
162 |
|
162 | |||
163 | def PasswordResetForm(): |
|
163 | def PasswordResetForm(): | |
164 | class _PasswordResetForm(formencode.Schema): |
|
164 | class _PasswordResetForm(formencode.Schema): | |
165 | allow_extra_fields = True |
|
165 | allow_extra_fields = True | |
166 | filter_extra_fields = True |
|
166 | filter_extra_fields = True | |
167 | email = All(v.ValidSystemEmail(), v.Email(not_empty=True)) |
|
167 | email = All(v.ValidSystemEmail(), v.Email(not_empty=True)) | |
168 | return _PasswordResetForm |
|
168 | return _PasswordResetForm | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), |
|
171 | def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), | |
172 | repo_groups=[], landing_revs=[]): |
|
172 | repo_groups=[], landing_revs=[]): | |
173 | class _RepoForm(formencode.Schema): |
|
173 | class _RepoForm(formencode.Schema): | |
174 | allow_extra_fields = True |
|
174 | allow_extra_fields = True | |
175 | filter_extra_fields = False |
|
175 | filter_extra_fields = False | |
176 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
176 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
177 | v.SlugifyName()) |
|
177 | v.SlugifyName()) | |
178 | clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False)) |
|
178 | clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False)) | |
179 | repo_group = v.OneOf(repo_groups, hideList=True) |
|
179 | repo_group = v.OneOf(repo_groups, hideList=True) | |
180 | repo_type = v.OneOf(supported_backends) |
|
180 | repo_type = v.OneOf(supported_backends) | |
181 | description = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
181 | description = v.UnicodeString(strip=True, min=1, not_empty=False) | |
182 | private = v.StringBoolean(if_missing=False) |
|
182 | private = v.StringBoolean(if_missing=False) | |
183 | enable_statistics = v.StringBoolean(if_missing=False) |
|
183 | enable_statistics = v.StringBoolean(if_missing=False) | |
184 | enable_downloads = v.StringBoolean(if_missing=False) |
|
184 | enable_downloads = v.StringBoolean(if_missing=False) | |
185 | landing_rev = v.OneOf(landing_revs, hideList=True) |
|
185 | landing_rev = v.OneOf(landing_revs, hideList=True) | |
186 |
|
186 | |||
187 | if edit: |
|
187 | if edit: | |
188 | #this is repo owner |
|
188 | #this is repo owner | |
189 | user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser()) |
|
189 | user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser()) | |
190 |
|
190 | |||
191 | chained_validators = [v.ValidCloneUri(), |
|
191 | chained_validators = [v.ValidCloneUri(), | |
192 | v.ValidRepoName(edit, old_data), |
|
192 | v.ValidRepoName(edit, old_data), | |
193 | v.ValidPerms()] |
|
193 | v.ValidPerms()] | |
194 | return _RepoForm |
|
194 | return _RepoForm | |
195 |
|
195 | |||
196 |
|
196 | |||
197 | def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), |
|
197 | def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), | |
198 | repo_groups=[], landing_revs=[]): |
|
198 | repo_groups=[], landing_revs=[]): | |
199 | class _RepoForkForm(formencode.Schema): |
|
199 | class _RepoForkForm(formencode.Schema): | |
200 | allow_extra_fields = True |
|
200 | allow_extra_fields = True | |
201 | filter_extra_fields = False |
|
201 | filter_extra_fields = False | |
202 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
202 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
203 | v.SlugifyName()) |
|
203 | v.SlugifyName()) | |
204 | repo_group = v.OneOf(repo_groups, hideList=True) |
|
204 | repo_group = v.OneOf(repo_groups, hideList=True) | |
205 | repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends)) |
|
205 | repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends)) | |
206 | description = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
206 | description = v.UnicodeString(strip=True, min=1, not_empty=True) | |
207 | private = v.StringBoolean(if_missing=False) |
|
207 | private = v.StringBoolean(if_missing=False) | |
208 | copy_permissions = v.StringBoolean(if_missing=False) |
|
208 | copy_permissions = v.StringBoolean(if_missing=False) | |
209 | update_after_clone = v.StringBoolean(if_missing=False) |
|
209 | update_after_clone = v.StringBoolean(if_missing=False) | |
210 | fork_parent_id = v.UnicodeString() |
|
210 | fork_parent_id = v.UnicodeString() | |
211 | chained_validators = [v.ValidForkName(edit, old_data)] |
|
211 | chained_validators = [v.ValidForkName(edit, old_data)] | |
212 | landing_rev = v.OneOf(landing_revs, hideList=True) |
|
212 | landing_rev = v.OneOf(landing_revs, hideList=True) | |
213 |
|
213 | |||
214 | return _RepoForkForm |
|
214 | return _RepoForkForm | |
215 |
|
215 | |||
216 |
|
216 | |||
217 | def RepoSettingsForm(edit=False, old_data={}, |
|
217 | def RepoSettingsForm(edit=False, old_data={}, | |
218 | supported_backends=BACKENDS.keys(), repo_groups=[], |
|
218 | supported_backends=BACKENDS.keys(), repo_groups=[], | |
219 | landing_revs=[]): |
|
219 | landing_revs=[]): | |
220 | class _RepoForm(formencode.Schema): |
|
220 | class _RepoForm(formencode.Schema): | |
221 | allow_extra_fields = True |
|
221 | allow_extra_fields = True | |
222 | filter_extra_fields = False |
|
222 | filter_extra_fields = False | |
223 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
223 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
224 | v.SlugifyName()) |
|
224 | v.SlugifyName()) | |
225 | description = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
225 | description = v.UnicodeString(strip=True, min=1, not_empty=True) | |
226 | repo_group = v.OneOf(repo_groups, hideList=True) |
|
226 | repo_group = v.OneOf(repo_groups, hideList=True) | |
227 | private = v.StringBoolean(if_missing=False) |
|
227 | private = v.StringBoolean(if_missing=False) | |
228 | landing_rev = v.OneOf(landing_revs, hideList=True) |
|
228 | landing_rev = v.OneOf(landing_revs, hideList=True) | |
229 | chained_validators = [v.ValidRepoName(edit, old_data), v.ValidPerms(), |
|
229 | chained_validators = [v.ValidRepoName(edit, old_data), v.ValidPerms(), | |
230 | v.ValidSettings()] |
|
230 | v.ValidSettings()] | |
231 | return _RepoForm |
|
231 | return _RepoForm | |
232 |
|
232 | |||
233 |
|
233 | |||
234 | def ApplicationSettingsForm(): |
|
234 | def ApplicationSettingsForm(): | |
235 | class _ApplicationSettingsForm(formencode.Schema): |
|
235 | class _ApplicationSettingsForm(formencode.Schema): | |
236 | allow_extra_fields = True |
|
236 | allow_extra_fields = True | |
237 | filter_extra_fields = False |
|
237 | filter_extra_fields = False | |
238 | rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
238 | rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True) | |
239 | rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
239 | rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True) | |
240 | rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
240 | rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False) | |
241 |
|
241 | |||
242 | return _ApplicationSettingsForm |
|
242 | return _ApplicationSettingsForm | |
243 |
|
243 | |||
244 |
|
244 | |||
245 | def ApplicationUiSettingsForm(): |
|
245 | def ApplicationUiSettingsForm(): | |
246 | class _ApplicationUiSettingsForm(formencode.Schema): |
|
246 | class _ApplicationUiSettingsForm(formencode.Schema): | |
247 | allow_extra_fields = True |
|
247 | allow_extra_fields = True | |
248 | filter_extra_fields = False |
|
248 | filter_extra_fields = False | |
249 | web_push_ssl = v.OneOf(['true', 'false'], if_missing='false') |
|
249 | web_push_ssl = v.OneOf(['true', 'false'], if_missing='false') | |
250 | paths_root_path = All( |
|
250 | paths_root_path = All( | |
251 | v.ValidPath(), |
|
251 | v.ValidPath(), | |
252 | v.UnicodeString(strip=True, min=1, not_empty=True) |
|
252 | v.UnicodeString(strip=True, min=1, not_empty=True) | |
253 | ) |
|
253 | ) | |
254 | hooks_changegroup_update = v.OneOf(['True', 'False'], |
|
254 | hooks_changegroup_update = v.OneOf(['True', 'False'], | |
255 | if_missing=False) |
|
255 | if_missing=False) | |
256 | hooks_changegroup_repo_size = v.OneOf(['True', 'False'], |
|
256 | hooks_changegroup_repo_size = v.OneOf(['True', 'False'], | |
257 | if_missing=False) |
|
257 | if_missing=False) | |
258 | hooks_changegroup_push_logger = v.OneOf(['True', 'False'], |
|
258 | hooks_changegroup_push_logger = v.OneOf(['True', 'False'], | |
259 | if_missing=False) |
|
259 | if_missing=False) | |
260 | hooks_preoutgoing_pull_logger = v.OneOf(['True', 'False'], |
|
260 | hooks_preoutgoing_pull_logger = v.OneOf(['True', 'False'], | |
261 | if_missing=False) |
|
261 | if_missing=False) | |
262 |
|
262 | |||
263 | return _ApplicationUiSettingsForm |
|
263 | return _ApplicationUiSettingsForm | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | def DefaultPermissionsForm(perms_choices, register_choices, create_choices): |
|
266 | def DefaultPermissionsForm(perms_choices, register_choices, create_choices): | |
267 | class _DefaultPermissionsForm(formencode.Schema): |
|
267 | class _DefaultPermissionsForm(formencode.Schema): | |
268 | allow_extra_fields = True |
|
268 | allow_extra_fields = True | |
269 | filter_extra_fields = True |
|
269 | filter_extra_fields = True | |
270 | overwrite_default = v.StringBoolean(if_missing=False) |
|
270 | overwrite_default = v.StringBoolean(if_missing=False) | |
271 | anonymous = v.OneOf(['True', 'False'], if_missing=False) |
|
271 | anonymous = v.OneOf(['True', 'False'], if_missing=False) | |
272 | default_perm = v.OneOf(perms_choices) |
|
272 | default_perm = v.OneOf(perms_choices) | |
273 | default_register = v.OneOf(register_choices) |
|
273 | default_register = v.OneOf(register_choices) | |
274 | default_create = v.OneOf(create_choices) |
|
274 | default_create = v.OneOf(create_choices) | |
275 |
|
275 | |||
276 | return _DefaultPermissionsForm |
|
276 | return _DefaultPermissionsForm | |
277 |
|
277 | |||
278 |
|
278 | |||
279 | def LdapSettingsForm(tls_reqcert_choices, search_scope_choices, |
|
279 | def LdapSettingsForm(tls_reqcert_choices, search_scope_choices, | |
280 | tls_kind_choices): |
|
280 | tls_kind_choices): | |
281 | class _LdapSettingsForm(formencode.Schema): |
|
281 | class _LdapSettingsForm(formencode.Schema): | |
282 | allow_extra_fields = True |
|
282 | allow_extra_fields = True | |
283 | filter_extra_fields = True |
|
283 | filter_extra_fields = True | |
284 | #pre_validators = [LdapLibValidator] |
|
284 | #pre_validators = [LdapLibValidator] | |
285 | ldap_active = v.StringBoolean(if_missing=False) |
|
285 | ldap_active = v.StringBoolean(if_missing=False) | |
286 | ldap_host = v.UnicodeString(strip=True,) |
|
286 | ldap_host = v.UnicodeString(strip=True,) | |
287 | ldap_port = v.Number(strip=True,) |
|
287 | ldap_port = v.Number(strip=True,) | |
288 | ldap_tls_kind = v.OneOf(tls_kind_choices) |
|
288 | ldap_tls_kind = v.OneOf(tls_kind_choices) | |
289 | ldap_tls_reqcert = v.OneOf(tls_reqcert_choices) |
|
289 | ldap_tls_reqcert = v.OneOf(tls_reqcert_choices) | |
290 | ldap_dn_user = v.UnicodeString(strip=True,) |
|
290 | ldap_dn_user = v.UnicodeString(strip=True,) | |
291 | ldap_dn_pass = v.UnicodeString(strip=True,) |
|
291 | ldap_dn_pass = v.UnicodeString(strip=True,) | |
292 | ldap_base_dn = v.UnicodeString(strip=True,) |
|
292 | ldap_base_dn = v.UnicodeString(strip=True,) | |
293 | ldap_filter = v.UnicodeString(strip=True,) |
|
293 | ldap_filter = v.UnicodeString(strip=True,) | |
294 | ldap_search_scope = v.OneOf(search_scope_choices) |
|
294 | ldap_search_scope = v.OneOf(search_scope_choices) | |
295 | ldap_attr_login = All( |
|
295 | ldap_attr_login = All( | |
296 | v.AttrLoginValidator(), |
|
296 | v.AttrLoginValidator(), | |
297 | v.UnicodeString(strip=True,) |
|
297 | v.UnicodeString(strip=True,) | |
298 | ) |
|
298 | ) | |
299 | ldap_attr_firstname = v.UnicodeString(strip=True,) |
|
299 | ldap_attr_firstname = v.UnicodeString(strip=True,) | |
300 | ldap_attr_lastname = v.UnicodeString(strip=True,) |
|
300 | ldap_attr_lastname = v.UnicodeString(strip=True,) | |
301 | ldap_attr_email = v.UnicodeString(strip=True,) |
|
301 | ldap_attr_email = v.UnicodeString(strip=True,) | |
302 |
|
302 | |||
303 | return _LdapSettingsForm |
|
303 | return _LdapSettingsForm | |
304 |
|
304 | |||
305 |
|
305 | |||
306 | def UserExtraEmailForm(): |
|
306 | def UserExtraEmailForm(): | |
307 | class _UserExtraEmailForm(formencode.Schema): |
|
307 | class _UserExtraEmailForm(formencode.Schema): | |
308 | email = All(v.UniqSystemEmail(), v.Email) |
|
308 | email = All(v.UniqSystemEmail(), v.Email) | |
309 |
|
309 | |||
310 | return _UserExtraEmailForm |
|
310 | return _UserExtraEmailForm |
@@ -1,100 +1,100 | |||||
1 | ## -*- coding: utf-8 -*- |
|
1 | ## -*- coding: utf-8 -*- | |
2 | <%inherit file="/base/base.html"/> |
|
2 | <%inherit file="/base/base.html"/> | |
3 |
|
3 | |||
4 | <%def name="title()"> |
|
4 | <%def name="title()"> | |
5 | ${_('Add user')} - ${c.rhodecode_name} |
|
5 | ${_('Add user')} - ${c.rhodecode_name} | |
6 | </%def> |
|
6 | </%def> | |
7 | <%def name="breadcrumbs_links()"> |
|
7 | <%def name="breadcrumbs_links()"> | |
8 | ${h.link_to(_('Admin'),h.url('admin_home'))} |
|
8 | ${h.link_to(_('Admin'),h.url('admin_home'))} | |
9 | » |
|
9 | » | |
10 | ${h.link_to(_('Users'),h.url('users'))} |
|
10 | ${h.link_to(_('Users'),h.url('users'))} | |
11 | » |
|
11 | » | |
12 | ${_('add new user')} |
|
12 | ${_('add new user')} | |
13 | </%def> |
|
13 | </%def> | |
14 |
|
14 | |||
15 | <%def name="page_nav()"> |
|
15 | <%def name="page_nav()"> | |
16 | ${self.menu('admin')} |
|
16 | ${self.menu('admin')} | |
17 | </%def> |
|
17 | </%def> | |
18 |
|
18 | |||
19 | <%def name="main()"> |
|
19 | <%def name="main()"> | |
20 | <div class="box"> |
|
20 | <div class="box"> | |
21 | <!-- box / title --> |
|
21 | <!-- box / title --> | |
22 | <div class="title"> |
|
22 | <div class="title"> | |
23 | ${self.breadcrumbs()} |
|
23 | ${self.breadcrumbs()} | |
24 | </div> |
|
24 | </div> | |
25 | <!-- end box / title --> |
|
25 | <!-- end box / title --> | |
26 | ${h.form(url('users'))} |
|
26 | ${h.form(url('users'))} | |
27 | <div class="form"> |
|
27 | <div class="form"> | |
28 | <!-- fields --> |
|
28 | <!-- fields --> | |
29 | <div class="fields"> |
|
29 | <div class="fields"> | |
30 | <div class="field"> |
|
30 | <div class="field"> | |
31 | <div class="label"> |
|
31 | <div class="label"> | |
32 | <label for="username">${_('Username')}:</label> |
|
32 | <label for="username">${_('Username')}:</label> | |
33 | </div> |
|
33 | </div> | |
34 | <div class="input"> |
|
34 | <div class="input"> | |
35 | ${h.text('username',class_='small')} |
|
35 | ${h.text('username',class_='small')} | |
36 | </div> |
|
36 | </div> | |
37 | </div> |
|
37 | </div> | |
38 |
|
38 | |||
39 | <div class="field"> |
|
39 | <div class="field"> | |
40 | <div class="label"> |
|
40 | <div class="label"> | |
41 | <label for="password">${_('Password')}:</label> |
|
41 | <label for="password">${_('Password')}:</label> | |
42 | </div> |
|
42 | </div> | |
43 | <div class="input"> |
|
43 | <div class="input"> | |
44 | ${h.password('password',class_='small')} |
|
44 | ${h.password('password',class_='small')} | |
45 | </div> |
|
45 | </div> | |
46 | </div> |
|
46 | </div> | |
47 |
|
47 | |||
48 | <div class="field"> |
|
48 | <div class="field"> | |
49 | <div class="label"> |
|
49 | <div class="label"> | |
50 | <label for="password_confirmation">${_('Password confirmation')}:</label> |
|
50 | <label for="password_confirmation">${_('Password confirmation')}:</label> | |
51 | </div> |
|
51 | </div> | |
52 | <div class="input"> |
|
52 | <div class="input"> | |
53 | ${h.password('password_confirmation',class_="small",autocomplete="off")} |
|
53 | ${h.password('password_confirmation',class_="small",autocomplete="off")} | |
54 | </div> |
|
54 | </div> | |
55 | </div> |
|
55 | </div> | |
56 |
|
56 | |||
57 | <div class="field"> |
|
57 | <div class="field"> | |
58 | <div class="label"> |
|
58 | <div class="label"> | |
59 | <label for="name">${_('First Name')}:</label> |
|
59 | <label for="firstname">${_('First Name')}:</label> | |
60 | </div> |
|
60 | </div> | |
61 | <div class="input"> |
|
61 | <div class="input"> | |
62 | ${h.text('name',class_='small')} |
|
62 | ${h.text('firstname',class_='small')} | |
63 | </div> |
|
63 | </div> | |
64 | </div> |
|
64 | </div> | |
65 |
|
65 | |||
66 | <div class="field"> |
|
66 | <div class="field"> | |
67 | <div class="label"> |
|
67 | <div class="label"> | |
68 | <label for="lastname">${_('Last Name')}:</label> |
|
68 | <label for="lastname">${_('Last Name')}:</label> | |
69 | </div> |
|
69 | </div> | |
70 | <div class="input"> |
|
70 | <div class="input"> | |
71 | ${h.text('lastname',class_='small')} |
|
71 | ${h.text('lastname',class_='small')} | |
72 | </div> |
|
72 | </div> | |
73 | </div> |
|
73 | </div> | |
74 |
|
74 | |||
75 | <div class="field"> |
|
75 | <div class="field"> | |
76 | <div class="label"> |
|
76 | <div class="label"> | |
77 | <label for="email">${_('Email')}:</label> |
|
77 | <label for="email">${_('Email')}:</label> | |
78 | </div> |
|
78 | </div> | |
79 | <div class="input"> |
|
79 | <div class="input"> | |
80 | ${h.text('email',class_='small')} |
|
80 | ${h.text('email',class_='small')} | |
81 | </div> |
|
81 | </div> | |
82 | </div> |
|
82 | </div> | |
83 |
|
83 | |||
84 | <div class="field"> |
|
84 | <div class="field"> | |
85 | <div class="label label-checkbox"> |
|
85 | <div class="label label-checkbox"> | |
86 | <label for="active">${_('Active')}:</label> |
|
86 | <label for="active">${_('Active')}:</label> | |
87 | </div> |
|
87 | </div> | |
88 | <div class="checkboxes"> |
|
88 | <div class="checkboxes"> | |
89 | ${h.checkbox('active',value=True,checked='checked')} |
|
89 | ${h.checkbox('active',value=True,checked='checked')} | |
90 | </div> |
|
90 | </div> | |
91 | </div> |
|
91 | </div> | |
92 |
|
92 | |||
93 | <div class="buttons"> |
|
93 | <div class="buttons"> | |
94 | ${h.submit('save',_('save'),class_="ui-button")} |
|
94 | ${h.submit('save',_('save'),class_="ui-button")} | |
95 | </div> |
|
95 | </div> | |
96 | </div> |
|
96 | </div> | |
97 | </div> |
|
97 | </div> | |
98 | ${h.end_form()} |
|
98 | ${h.end_form()} | |
99 | </div> |
|
99 | </div> | |
100 | </%def> |
|
100 | </%def> |
@@ -1,91 +1,91 | |||||
1 | ## -*- coding: utf-8 -*- |
|
1 | ## -*- coding: utf-8 -*- | |
2 | <%inherit file="base/root.html"/> |
|
2 | <%inherit file="base/root.html"/> | |
3 |
|
3 | |||
4 | <%def name="title()"> |
|
4 | <%def name="title()"> | |
5 | ${_('Sign Up')} - ${c.rhodecode_name} |
|
5 | ${_('Sign Up')} - ${c.rhodecode_name} | |
6 | </%def> |
|
6 | </%def> | |
7 |
|
7 | |||
8 | <div id="register"> |
|
8 | <div id="register"> | |
9 |
|
9 | |||
10 | <div class="title top-left-rounded-corner top-right-rounded-corner"> |
|
10 | <div class="title top-left-rounded-corner top-right-rounded-corner"> | |
11 | <h5>${_('Sign Up to')} ${c.rhodecode_name}</h5> |
|
11 | <h5>${_('Sign Up to')} ${c.rhodecode_name}</h5> | |
12 | </div> |
|
12 | </div> | |
13 | <div class="inner"> |
|
13 | <div class="inner"> | |
14 | ${h.form(url('register'))} |
|
14 | ${h.form(url('register'))} | |
15 | <div class="form"> |
|
15 | <div class="form"> | |
16 | <!-- fields --> |
|
16 | <!-- fields --> | |
17 | <div class="fields"> |
|
17 | <div class="fields"> | |
18 | <div class="field"> |
|
18 | <div class="field"> | |
19 | <div class="label"> |
|
19 | <div class="label"> | |
20 | <label for="username">${_('Username')}:</label> |
|
20 | <label for="username">${_('Username')}:</label> | |
21 | </div> |
|
21 | </div> | |
22 | <div class="input"> |
|
22 | <div class="input"> | |
23 | ${h.text('username',class_="medium")} |
|
23 | ${h.text('username',class_="medium")} | |
24 | </div> |
|
24 | </div> | |
25 | </div> |
|
25 | </div> | |
26 |
|
26 | |||
27 | <div class="field"> |
|
27 | <div class="field"> | |
28 | <div class="label"> |
|
28 | <div class="label"> | |
29 | <label for="password">${_('Password')}:</label> |
|
29 | <label for="password">${_('Password')}:</label> | |
30 | </div> |
|
30 | </div> | |
31 | <div class="input"> |
|
31 | <div class="input"> | |
32 | ${h.password('password',class_="medium")} |
|
32 | ${h.password('password',class_="medium")} | |
33 | </div> |
|
33 | </div> | |
34 | </div> |
|
34 | </div> | |
35 |
|
35 | |||
36 | <div class="field"> |
|
36 | <div class="field"> | |
37 | <div class="label"> |
|
37 | <div class="label"> | |
38 | <label for="password">${_('Re-enter password')}:</label> |
|
38 | <label for="password">${_('Re-enter password')}:</label> | |
39 | </div> |
|
39 | </div> | |
40 | <div class="input"> |
|
40 | <div class="input"> | |
41 | ${h.password('password_confirmation',class_="medium")} |
|
41 | ${h.password('password_confirmation',class_="medium")} | |
42 | </div> |
|
42 | </div> | |
43 | </div> |
|
43 | </div> | |
44 |
|
44 | |||
45 | <div class="field"> |
|
45 | <div class="field"> | |
46 | <div class="label"> |
|
46 | <div class="label"> | |
47 | <label for="name">${_('First Name')}:</label> |
|
47 | <label for="firstname">${_('First Name')}:</label> | |
48 | </div> |
|
48 | </div> | |
49 | <div class="input"> |
|
49 | <div class="input"> | |
50 | ${h.text('name',class_="medium")} |
|
50 | ${h.text('firstname',class_="medium")} | |
51 | </div> |
|
51 | </div> | |
52 | </div> |
|
52 | </div> | |
53 |
|
53 | |||
54 | <div class="field"> |
|
54 | <div class="field"> | |
55 | <div class="label"> |
|
55 | <div class="label"> | |
56 | <label for="lastname">${_('Last Name')}:</label> |
|
56 | <label for="lastname">${_('Last Name')}:</label> | |
57 | </div> |
|
57 | </div> | |
58 | <div class="input"> |
|
58 | <div class="input"> | |
59 | ${h.text('lastname',class_="medium")} |
|
59 | ${h.text('lastname',class_="medium")} | |
60 | </div> |
|
60 | </div> | |
61 | </div> |
|
61 | </div> | |
62 |
|
62 | |||
63 | <div class="field"> |
|
63 | <div class="field"> | |
64 | <div class="label"> |
|
64 | <div class="label"> | |
65 | <label for="email">${_('Email')}:</label> |
|
65 | <label for="email">${_('Email')}:</label> | |
66 | </div> |
|
66 | </div> | |
67 | <div class="input"> |
|
67 | <div class="input"> | |
68 | ${h.text('email',class_="medium")} |
|
68 | ${h.text('email',class_="medium")} | |
69 | </div> |
|
69 | </div> | |
70 | </div> |
|
70 | </div> | |
71 |
|
71 | |||
72 | <div class="buttons"> |
|
72 | <div class="buttons"> | |
73 | <div class="nohighlight"> |
|
73 | <div class="nohighlight"> | |
74 | ${h.submit('sign_up',_('Sign Up'),class_="ui-button")} |
|
74 | ${h.submit('sign_up',_('Sign Up'),class_="ui-button")} | |
75 | %if c.auto_active: |
|
75 | %if c.auto_active: | |
76 | <div class="activation_msg">${_('Your account will be activated right after registration')}</div> |
|
76 | <div class="activation_msg">${_('Your account will be activated right after registration')}</div> | |
77 | %else: |
|
77 | %else: | |
78 | <div class="activation_msg">${_('Your account must wait for activation by administrator')}</div> |
|
78 | <div class="activation_msg">${_('Your account must wait for activation by administrator')}</div> | |
79 | %endif |
|
79 | %endif | |
80 | </div> |
|
80 | </div> | |
81 | </div> |
|
81 | </div> | |
82 | </div> |
|
82 | </div> | |
83 | </div> |
|
83 | </div> | |
84 | ${h.end_form()} |
|
84 | ${h.end_form()} | |
85 | <script type="text/javascript"> |
|
85 | <script type="text/javascript"> | |
86 | YUE.onDOMReady(function(){ |
|
86 | YUE.onDOMReady(function(){ | |
87 | YUD.get('username').focus(); |
|
87 | YUD.get('username').focus(); | |
88 | }) |
|
88 | }) | |
89 | </script> |
|
89 | </script> | |
90 | </div> |
|
90 | </div> | |
91 | </div> |
|
91 | </div> |
@@ -1,272 +1,272 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | from rhodecode.tests import * |
|
2 | from rhodecode.tests import * | |
3 | from rhodecode.model.db import User, Notification |
|
3 | from rhodecode.model.db import User, Notification | |
4 | from rhodecode.lib.utils2 import generate_api_key |
|
4 | from rhodecode.lib.utils2 import generate_api_key | |
5 | from rhodecode.lib.auth import check_password |
|
5 | from rhodecode.lib.auth import check_password | |
6 | from rhodecode.lib import helpers as h |
|
6 | from rhodecode.lib import helpers as h | |
7 | from rhodecode.model import validators |
|
7 | from rhodecode.model import validators | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | class TestLoginController(TestController): |
|
10 | class TestLoginController(TestController): | |
11 |
|
11 | |||
12 | def tearDown(self): |
|
12 | def tearDown(self): | |
13 | for n in Notification.query().all(): |
|
13 | for n in Notification.query().all(): | |
14 | self.Session().delete(n) |
|
14 | self.Session().delete(n) | |
15 |
|
15 | |||
16 | self.Session().commit() |
|
16 | self.Session().commit() | |
17 | self.assertEqual(Notification.query().all(), []) |
|
17 | self.assertEqual(Notification.query().all(), []) | |
18 |
|
18 | |||
19 | def test_index(self): |
|
19 | def test_index(self): | |
20 | response = self.app.get(url(controller='login', action='index')) |
|
20 | response = self.app.get(url(controller='login', action='index')) | |
21 | self.assertEqual(response.status, '200 OK') |
|
21 | self.assertEqual(response.status, '200 OK') | |
22 | # Test response... |
|
22 | # Test response... | |
23 |
|
23 | |||
24 | def test_login_admin_ok(self): |
|
24 | def test_login_admin_ok(self): | |
25 | response = self.app.post(url(controller='login', action='index'), |
|
25 | response = self.app.post(url(controller='login', action='index'), | |
26 | {'username': 'test_admin', |
|
26 | {'username': 'test_admin', | |
27 | 'password': 'test12'}) |
|
27 | 'password': 'test12'}) | |
28 | self.assertEqual(response.status, '302 Found') |
|
28 | self.assertEqual(response.status, '302 Found') | |
29 | self.assertEqual(response.session['rhodecode_user'].get('username'), |
|
29 | self.assertEqual(response.session['rhodecode_user'].get('username'), | |
30 | 'test_admin') |
|
30 | 'test_admin') | |
31 | response = response.follow() |
|
31 | response = response.follow() | |
32 | self.assertTrue('%s repository' % HG_REPO in response.body) |
|
32 | self.assertTrue('%s repository' % HG_REPO in response.body) | |
33 |
|
33 | |||
34 | def test_login_regular_ok(self): |
|
34 | def test_login_regular_ok(self): | |
35 | response = self.app.post(url(controller='login', action='index'), |
|
35 | response = self.app.post(url(controller='login', action='index'), | |
36 | {'username': 'test_regular', |
|
36 | {'username': 'test_regular', | |
37 | 'password': 'test12'}) |
|
37 | 'password': 'test12'}) | |
38 |
|
38 | |||
39 | self.assertEqual(response.status, '302 Found') |
|
39 | self.assertEqual(response.status, '302 Found') | |
40 | self.assertEqual(response.session['rhodecode_user'].get('username'), |
|
40 | self.assertEqual(response.session['rhodecode_user'].get('username'), | |
41 | 'test_regular') |
|
41 | 'test_regular') | |
42 | response = response.follow() |
|
42 | response = response.follow() | |
43 | self.assertTrue('%s repository' % HG_REPO in response.body) |
|
43 | self.assertTrue('%s repository' % HG_REPO in response.body) | |
44 | self.assertTrue('<a title="Admin" href="/_admin">' not in response.body) |
|
44 | self.assertTrue('<a title="Admin" href="/_admin">' not in response.body) | |
45 |
|
45 | |||
46 | def test_login_ok_came_from(self): |
|
46 | def test_login_ok_came_from(self): | |
47 | test_came_from = '/_admin/users' |
|
47 | test_came_from = '/_admin/users' | |
48 | response = self.app.post(url(controller='login', action='index', |
|
48 | response = self.app.post(url(controller='login', action='index', | |
49 | came_from=test_came_from), |
|
49 | came_from=test_came_from), | |
50 | {'username': 'test_admin', |
|
50 | {'username': 'test_admin', | |
51 | 'password': 'test12'}) |
|
51 | 'password': 'test12'}) | |
52 | self.assertEqual(response.status, '302 Found') |
|
52 | self.assertEqual(response.status, '302 Found') | |
53 | response = response.follow() |
|
53 | response = response.follow() | |
54 |
|
54 | |||
55 | self.assertEqual(response.status, '200 OK') |
|
55 | self.assertEqual(response.status, '200 OK') | |
56 | self.assertTrue('Users administration' in response.body) |
|
56 | self.assertTrue('Users administration' in response.body) | |
57 |
|
57 | |||
58 | def test_login_short_password(self): |
|
58 | def test_login_short_password(self): | |
59 | response = self.app.post(url(controller='login', action='index'), |
|
59 | response = self.app.post(url(controller='login', action='index'), | |
60 | {'username': 'test_admin', |
|
60 | {'username': 'test_admin', | |
61 | 'password': 'as'}) |
|
61 | 'password': 'as'}) | |
62 | self.assertEqual(response.status, '200 OK') |
|
62 | self.assertEqual(response.status, '200 OK') | |
63 |
|
63 | |||
64 | self.assertTrue('Enter 3 characters or more' in response.body) |
|
64 | self.assertTrue('Enter 3 characters or more' in response.body) | |
65 |
|
65 | |||
66 | def test_login_wrong_username_password(self): |
|
66 | def test_login_wrong_username_password(self): | |
67 | response = self.app.post(url(controller='login', action='index'), |
|
67 | response = self.app.post(url(controller='login', action='index'), | |
68 | {'username': 'error', |
|
68 | {'username': 'error', | |
69 | 'password': 'test12'}) |
|
69 | 'password': 'test12'}) | |
70 |
|
70 | |||
71 | self.assertTrue('invalid user name' in response.body) |
|
71 | self.assertTrue('invalid user name' in response.body) | |
72 | self.assertTrue('invalid password' in response.body) |
|
72 | self.assertTrue('invalid password' in response.body) | |
73 |
|
73 | |||
74 | #========================================================================== |
|
74 | #========================================================================== | |
75 | # REGISTRATIONS |
|
75 | # REGISTRATIONS | |
76 | #========================================================================== |
|
76 | #========================================================================== | |
77 | def test_register(self): |
|
77 | def test_register(self): | |
78 | response = self.app.get(url(controller='login', action='register')) |
|
78 | response = self.app.get(url(controller='login', action='register')) | |
79 | self.assertTrue('Sign Up to RhodeCode' in response.body) |
|
79 | self.assertTrue('Sign Up to RhodeCode' in response.body) | |
80 |
|
80 | |||
81 | def test_register_err_same_username(self): |
|
81 | def test_register_err_same_username(self): | |
82 | uname = 'test_admin' |
|
82 | uname = 'test_admin' | |
83 | response = self.app.post(url(controller='login', action='register'), |
|
83 | response = self.app.post(url(controller='login', action='register'), | |
84 | {'username': uname, |
|
84 | {'username': uname, | |
85 | 'password': 'test12', |
|
85 | 'password': 'test12', | |
86 | 'password_confirmation': 'test12', |
|
86 | 'password_confirmation': 'test12', | |
87 | 'email': 'goodmail@domain.com', |
|
87 | 'email': 'goodmail@domain.com', | |
88 | 'name': 'test', |
|
88 | 'firstname': 'test', | |
89 | 'lastname': 'test'}) |
|
89 | 'lastname': 'test'}) | |
90 |
|
90 | |||
91 | msg = validators.ValidUsername()._messages['username_exists'] |
|
91 | msg = validators.ValidUsername()._messages['username_exists'] | |
92 | msg = h.html_escape(msg % {'username': uname}) |
|
92 | msg = h.html_escape(msg % {'username': uname}) | |
93 | response.mustcontain(msg) |
|
93 | response.mustcontain(msg) | |
94 |
|
94 | |||
95 | def test_register_err_same_email(self): |
|
95 | def test_register_err_same_email(self): | |
96 | response = self.app.post(url(controller='login', action='register'), |
|
96 | response = self.app.post(url(controller='login', action='register'), | |
97 | {'username': 'test_admin_0', |
|
97 | {'username': 'test_admin_0', | |
98 | 'password': 'test12', |
|
98 | 'password': 'test12', | |
99 | 'password_confirmation': 'test12', |
|
99 | 'password_confirmation': 'test12', | |
100 | 'email': 'test_admin@mail.com', |
|
100 | 'email': 'test_admin@mail.com', | |
101 | 'name': 'test', |
|
101 | 'firstname': 'test', | |
102 | 'lastname': 'test'}) |
|
102 | 'lastname': 'test'}) | |
103 |
|
103 | |||
104 | msg = validators.UniqSystemEmail()()._messages['email_taken'] |
|
104 | msg = validators.UniqSystemEmail()()._messages['email_taken'] | |
105 | response.mustcontain(msg) |
|
105 | response.mustcontain(msg) | |
106 |
|
106 | |||
107 | def test_register_err_same_email_case_sensitive(self): |
|
107 | def test_register_err_same_email_case_sensitive(self): | |
108 | response = self.app.post(url(controller='login', action='register'), |
|
108 | response = self.app.post(url(controller='login', action='register'), | |
109 | {'username': 'test_admin_1', |
|
109 | {'username': 'test_admin_1', | |
110 | 'password': 'test12', |
|
110 | 'password': 'test12', | |
111 | 'password_confirmation': 'test12', |
|
111 | 'password_confirmation': 'test12', | |
112 | 'email': 'TesT_Admin@mail.COM', |
|
112 | 'email': 'TesT_Admin@mail.COM', | |
113 | 'name': 'test', |
|
113 | 'firstname': 'test', | |
114 | 'lastname': 'test'}) |
|
114 | 'lastname': 'test'}) | |
115 | msg = validators.UniqSystemEmail()()._messages['email_taken'] |
|
115 | msg = validators.UniqSystemEmail()()._messages['email_taken'] | |
116 | response.mustcontain(msg) |
|
116 | response.mustcontain(msg) | |
117 |
|
117 | |||
118 | def test_register_err_wrong_data(self): |
|
118 | def test_register_err_wrong_data(self): | |
119 | response = self.app.post(url(controller='login', action='register'), |
|
119 | response = self.app.post(url(controller='login', action='register'), | |
120 | {'username': 'xs', |
|
120 | {'username': 'xs', | |
121 | 'password': 'test', |
|
121 | 'password': 'test', | |
122 | 'password_confirmation': 'test', |
|
122 | 'password_confirmation': 'test', | |
123 | 'email': 'goodmailm', |
|
123 | 'email': 'goodmailm', | |
124 | 'name': 'test', |
|
124 | 'firstname': 'test', | |
125 | 'lastname': 'test'}) |
|
125 | 'lastname': 'test'}) | |
126 | self.assertEqual(response.status, '200 OK') |
|
126 | self.assertEqual(response.status, '200 OK') | |
127 | response.mustcontain('An email address must contain a single @') |
|
127 | response.mustcontain('An email address must contain a single @') | |
128 | response.mustcontain('Enter a value 6 characters long or more') |
|
128 | response.mustcontain('Enter a value 6 characters long or more') | |
129 |
|
129 | |||
130 | def test_register_err_username(self): |
|
130 | def test_register_err_username(self): | |
131 | response = self.app.post(url(controller='login', action='register'), |
|
131 | response = self.app.post(url(controller='login', action='register'), | |
132 | {'username': 'error user', |
|
132 | {'username': 'error user', | |
133 | 'password': 'test12', |
|
133 | 'password': 'test12', | |
134 | 'password_confirmation': 'test12', |
|
134 | 'password_confirmation': 'test12', | |
135 | 'email': 'goodmailm', |
|
135 | 'email': 'goodmailm', | |
136 | 'name': 'test', |
|
136 | 'firstname': 'test', | |
137 | 'lastname': 'test'}) |
|
137 | 'lastname': 'test'}) | |
138 |
|
138 | |||
139 | response.mustcontain('An email address must contain a single @') |
|
139 | response.mustcontain('An email address must contain a single @') | |
140 | response.mustcontain('Username may only contain ' |
|
140 | response.mustcontain('Username may only contain ' | |
141 | 'alphanumeric characters underscores, ' |
|
141 | 'alphanumeric characters underscores, ' | |
142 | 'periods or dashes and must begin with ' |
|
142 | 'periods or dashes and must begin with ' | |
143 | 'alphanumeric character') |
|
143 | 'alphanumeric character') | |
144 |
|
144 | |||
145 | def test_register_err_case_sensitive(self): |
|
145 | def test_register_err_case_sensitive(self): | |
146 | usr = 'Test_Admin' |
|
146 | usr = 'Test_Admin' | |
147 | response = self.app.post(url(controller='login', action='register'), |
|
147 | response = self.app.post(url(controller='login', action='register'), | |
148 | {'username': usr, |
|
148 | {'username': usr, | |
149 | 'password': 'test12', |
|
149 | 'password': 'test12', | |
150 | 'password_confirmation': 'test12', |
|
150 | 'password_confirmation': 'test12', | |
151 | 'email': 'goodmailm', |
|
151 | 'email': 'goodmailm', | |
152 | 'name': 'test', |
|
152 | 'firstname': 'test', | |
153 | 'lastname': 'test'}) |
|
153 | 'lastname': 'test'}) | |
154 |
|
154 | |||
155 | response.mustcontain('An email address must contain a single @') |
|
155 | response.mustcontain('An email address must contain a single @') | |
156 | msg = validators.ValidUsername()._messages['username_exists'] |
|
156 | msg = validators.ValidUsername()._messages['username_exists'] | |
157 | msg = h.html_escape(msg % {'username': usr}) |
|
157 | msg = h.html_escape(msg % {'username': usr}) | |
158 | response.mustcontain(msg) |
|
158 | response.mustcontain(msg) | |
159 |
|
159 | |||
160 | def test_register_special_chars(self): |
|
160 | def test_register_special_chars(self): | |
161 | response = self.app.post(url(controller='login', action='register'), |
|
161 | response = self.app.post(url(controller='login', action='register'), | |
162 | {'username': 'xxxaxn', |
|
162 | {'username': 'xxxaxn', | |
163 | 'password': 'Δ ΔΕΊΕΌΔ ΕΕΕΕ', |
|
163 | 'password': 'Δ ΔΕΊΕΌΔ ΕΕΕΕ', | |
164 | 'password_confirmation': 'Δ ΔΕΊΕΌΔ ΕΕΕΕ', |
|
164 | 'password_confirmation': 'Δ ΔΕΊΕΌΔ ΕΕΕΕ', | |
165 | 'email': 'goodmailm@test.plx', |
|
165 | 'email': 'goodmailm@test.plx', | |
166 | 'name': 'test', |
|
166 | 'firstname': 'test', | |
167 | 'lastname': 'test'}) |
|
167 | 'lastname': 'test'}) | |
168 |
|
168 | |||
169 | msg = validators.ValidPassword()._messages['invalid_password'] |
|
169 | msg = validators.ValidPassword()._messages['invalid_password'] | |
170 | response.mustcontain(msg) |
|
170 | response.mustcontain(msg) | |
171 |
|
171 | |||
172 | def test_register_password_mismatch(self): |
|
172 | def test_register_password_mismatch(self): | |
173 | response = self.app.post(url(controller='login', action='register'), |
|
173 | response = self.app.post(url(controller='login', action='register'), | |
174 | {'username': 'xs', |
|
174 | {'username': 'xs', | |
175 | 'password': '123qwe', |
|
175 | 'password': '123qwe', | |
176 | 'password_confirmation': 'qwe123', |
|
176 | 'password_confirmation': 'qwe123', | |
177 | 'email': 'goodmailm@test.plxa', |
|
177 | 'email': 'goodmailm@test.plxa', | |
178 | 'name': 'test', |
|
178 | 'firstname': 'test', | |
179 | 'lastname': 'test'}) |
|
179 | 'lastname': 'test'}) | |
180 | msg = validators.ValidPasswordsMatch()._messages['password_mismatch'] |
|
180 | msg = validators.ValidPasswordsMatch()._messages['password_mismatch'] | |
181 | response.mustcontain(msg) |
|
181 | response.mustcontain(msg) | |
182 |
|
182 | |||
183 | def test_register_ok(self): |
|
183 | def test_register_ok(self): | |
184 | username = 'test_regular4' |
|
184 | username = 'test_regular4' | |
185 | password = 'qweqwe' |
|
185 | password = 'qweqwe' | |
186 | email = 'marcin@test.com' |
|
186 | email = 'marcin@test.com' | |
187 | name = 'testname' |
|
187 | name = 'testname' | |
188 | lastname = 'testlastname' |
|
188 | lastname = 'testlastname' | |
189 |
|
189 | |||
190 | response = self.app.post(url(controller='login', action='register'), |
|
190 | response = self.app.post(url(controller='login', action='register'), | |
191 | {'username': username, |
|
191 | {'username': username, | |
192 | 'password': password, |
|
192 | 'password': password, | |
193 | 'password_confirmation': password, |
|
193 | 'password_confirmation': password, | |
194 | 'email': email, |
|
194 | 'email': email, | |
195 | 'name': name, |
|
195 | 'firstname': name, | |
196 | 'lastname': lastname, |
|
196 | 'lastname': lastname, | |
197 | 'admin': True}) # This should be overriden |
|
197 | 'admin': True}) # This should be overriden | |
198 | self.assertEqual(response.status, '302 Found') |
|
198 | self.assertEqual(response.status, '302 Found') | |
199 | self.checkSessionFlash(response, 'You have successfully registered into rhodecode') |
|
199 | self.checkSessionFlash(response, 'You have successfully registered into rhodecode') | |
200 |
|
200 | |||
201 | ret = self.Session().query(User).filter(User.username == 'test_regular4').one() |
|
201 | ret = self.Session().query(User).filter(User.username == 'test_regular4').one() | |
202 | self.assertEqual(ret.username, username) |
|
202 | self.assertEqual(ret.username, username) | |
203 | self.assertEqual(check_password(password, ret.password), True) |
|
203 | self.assertEqual(check_password(password, ret.password), True) | |
204 | self.assertEqual(ret.email, email) |
|
204 | self.assertEqual(ret.email, email) | |
205 | self.assertEqual(ret.name, name) |
|
205 | self.assertEqual(ret.name, name) | |
206 | self.assertEqual(ret.lastname, lastname) |
|
206 | self.assertEqual(ret.lastname, lastname) | |
207 | self.assertNotEqual(ret.api_key, None) |
|
207 | self.assertNotEqual(ret.api_key, None) | |
208 | self.assertEqual(ret.admin, False) |
|
208 | self.assertEqual(ret.admin, False) | |
209 |
|
209 | |||
210 | def test_forgot_password_wrong_mail(self): |
|
210 | def test_forgot_password_wrong_mail(self): | |
211 | bad_email = 'marcin@wrongmail.org' |
|
211 | bad_email = 'marcin@wrongmail.org' | |
212 | response = self.app.post( |
|
212 | response = self.app.post( | |
213 | url(controller='login', action='password_reset'), |
|
213 | url(controller='login', action='password_reset'), | |
214 | {'email': bad_email, } |
|
214 | {'email': bad_email, } | |
215 | ) |
|
215 | ) | |
216 |
|
216 | |||
217 | msg = validators.ValidSystemEmail()._messages['non_existing_email'] |
|
217 | msg = validators.ValidSystemEmail()._messages['non_existing_email'] | |
218 | msg = h.html_escape(msg % {'email': bad_email}) |
|
218 | msg = h.html_escape(msg % {'email': bad_email}) | |
219 | response.mustcontain() |
|
219 | response.mustcontain() | |
220 |
|
220 | |||
221 | def test_forgot_password(self): |
|
221 | def test_forgot_password(self): | |
222 | response = self.app.get(url(controller='login', |
|
222 | response = self.app.get(url(controller='login', | |
223 | action='password_reset')) |
|
223 | action='password_reset')) | |
224 | self.assertEqual(response.status, '200 OK') |
|
224 | self.assertEqual(response.status, '200 OK') | |
225 |
|
225 | |||
226 | username = 'test_password_reset_1' |
|
226 | username = 'test_password_reset_1' | |
227 | password = 'qweqwe' |
|
227 | password = 'qweqwe' | |
228 | email = 'marcin@python-works.com' |
|
228 | email = 'marcin@python-works.com' | |
229 | name = 'passwd' |
|
229 | name = 'passwd' | |
230 | lastname = 'reset' |
|
230 | lastname = 'reset' | |
231 |
|
231 | |||
232 | new = User() |
|
232 | new = User() | |
233 | new.username = username |
|
233 | new.username = username | |
234 | new.password = password |
|
234 | new.password = password | |
235 | new.email = email |
|
235 | new.email = email | |
236 | new.name = name |
|
236 | new.name = name | |
237 | new.lastname = lastname |
|
237 | new.lastname = lastname | |
238 | new.api_key = generate_api_key(username) |
|
238 | new.api_key = generate_api_key(username) | |
239 | self.Session().add(new) |
|
239 | self.Session().add(new) | |
240 | self.Session().commit() |
|
240 | self.Session().commit() | |
241 |
|
241 | |||
242 | response = self.app.post(url(controller='login', |
|
242 | response = self.app.post(url(controller='login', | |
243 | action='password_reset'), |
|
243 | action='password_reset'), | |
244 | {'email': email, }) |
|
244 | {'email': email, }) | |
245 |
|
245 | |||
246 | self.checkSessionFlash(response, 'Your password reset link was sent') |
|
246 | self.checkSessionFlash(response, 'Your password reset link was sent') | |
247 |
|
247 | |||
248 | response = response.follow() |
|
248 | response = response.follow() | |
249 |
|
249 | |||
250 | # BAD KEY |
|
250 | # BAD KEY | |
251 |
|
251 | |||
252 | key = "bad" |
|
252 | key = "bad" | |
253 | response = self.app.get(url(controller='login', |
|
253 | response = self.app.get(url(controller='login', | |
254 | action='password_reset_confirmation', |
|
254 | action='password_reset_confirmation', | |
255 | key=key)) |
|
255 | key=key)) | |
256 | self.assertEqual(response.status, '302 Found') |
|
256 | self.assertEqual(response.status, '302 Found') | |
257 | self.assertTrue(response.location.endswith(url('reset_password'))) |
|
257 | self.assertTrue(response.location.endswith(url('reset_password'))) | |
258 |
|
258 | |||
259 | # GOOD KEY |
|
259 | # GOOD KEY | |
260 |
|
260 | |||
261 | key = User.get_by_username(username).api_key |
|
261 | key = User.get_by_username(username).api_key | |
262 | response = self.app.get(url(controller='login', |
|
262 | response = self.app.get(url(controller='login', | |
263 | action='password_reset_confirmation', |
|
263 | action='password_reset_confirmation', | |
264 | key=key)) |
|
264 | key=key)) | |
265 | self.assertEqual(response.status, '302 Found') |
|
265 | self.assertEqual(response.status, '302 Found') | |
266 | self.assertTrue(response.location.endswith(url('login_home'))) |
|
266 | self.assertTrue(response.location.endswith(url('login_home'))) | |
267 |
|
267 | |||
268 | self.checkSessionFlash(response, |
|
268 | self.checkSessionFlash(response, | |
269 | ('Your password reset was successful, ' |
|
269 | ('Your password reset was successful, ' | |
270 | 'new password has been sent to your email')) |
|
270 | 'new password has been sent to your email')) | |
271 |
|
271 | |||
272 | response = response.follow() |
|
272 | response = response.follow() |
General Comments 0
You need to be logged in to leave comments.
Login now