Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
618b9b07
Commit
618b9b07
authored
4 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
AccountWizard: Validate host and port
parent
ce419810
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gajim/gtk/account_wizard.py
+70
-32
70 additions, 32 deletions
gajim/gtk/account_wizard.py
with
70 additions
and
32 deletions
gajim/gtk/account_wizard.py
+
70
−
32
View file @
618b9b07
...
...
@@ -22,6 +22,7 @@
from
nbxmpp.client
import
Client
from
nbxmpp.protocol
import
JID
from
nbxmpp.protocol
import
validate_domainpart
from
nbxmpp.const
import
Mode
from
nbxmpp.const
import
StreamError
from
nbxmpp.const
import
ConnectionProtocol
...
...
@@ -61,7 +62,8 @@ def __init__(self):
css_class
=
'
suggested-action
'
)
self
.
add_button
(
'
connect
'
,
_
(
'
Connect
'
),
css_class
=
'
suggested-action
'
)
self
.
add_button
(
'
next
'
,
_
(
'
Next
'
),
css_class
=
'
suggested-action
'
)
self
.
add_button
(
'
login
'
,
_
(
'
Log In
'
),
css_class
=
'
suggested-action
'
)
self
.
add_button
(
'
login
'
,
_
(
'
Log In
'
),
complete
=
True
,
css_class
=
'
suggested-action
'
)
self
.
add_button
(
'
back
'
,
_
(
'
Back
'
))
self
.
add_pages
({
'
login
'
:
Login
(
self
.
_on_button_clicked
),
...
...
@@ -302,7 +304,8 @@ def _test_anonymous_server(self, ignore_all_errors=False):
advanced
,
ignore_all_errors
)
self
.
_client
.
subscribe
(
'
anonymous-supported
'
,
self
.
_on_anonymous_supported
)
self
.
_client
.
subscribe
(
'
anonymous-supported
'
,
self
.
_on_anonymous_supported
)
self
.
_client
.
connect
()
def
_register_with_server
(
self
,
ignore_all_errors
=
False
):
...
...
@@ -675,38 +678,16 @@ def _on_visit_server(self, _widget):
open_uri
(
server
)
return
Gdk
.
EVENT_STOP
def
_check_port_entry
(
self
):
port
=
self
.
_ui
.
custom_port_entry
.
get_text
()
if
port
==
''
:
self
.
_show_icon
(
False
)
return
False
def
_set_complete
(
self
,
*
args
):
try
:
port
=
int
(
port
)
self
.
get_server
(
)
except
Exception
:
self
.
_show_icon
(
True
)
self
.
_ui
.
custom_port_entry
.
set_icon_tooltip_text
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
_
(
'
Must be a port number
'
))
return
False
if
port
not
in
range
(
0
,
65535
):
self
.
_show_icon
(
True
)
self
.
_ui
.
custom_port_entry
.
set_icon_tooltip_text
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
_
(
'
Port must be a number between 0 and 65535
'
))
return
False
self
.
_show_icon
(
False
)
return
True
def
_show_icon
(
self
,
show
):
icon
=
'
dialog-warning-symbolic
'
if
show
else
None
self
.
_ui
.
log_in_address_entry
.
set_icon_from_icon_name
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
icon
)
self
.
complete
=
False
self
.
_ui
.
visit_server_button
.
set_visible
(
False
)
else
:
self
.
complete
=
True
self
.
_ui
.
visit_server_button
.
set_visible
(
True
)
def
_set_complete
(
self
,
*
args
):
server
=
self
.
_ui
.
server_comboboxtext_sign_up_entry
.
get_text
()
self
.
_ui
.
visit_server_button
.
set_visible
(
server
)
self
.
complete
=
server
self
.
get_toplevel
().
update_page_complete
()
def
is_anonymous
(
self
):
...
...
@@ -716,7 +697,8 @@ def is_advanced(self):
return
self
.
_ui
.
sign_up_advanced_checkbutton
.
get_active
()
def
get_server
(
self
):
return
self
.
_ui
.
server_comboboxtext_sign_up_entry
.
get_text
()
return
validate_domainpart
(
self
.
_ui
.
server_comboboxtext_sign_up_entry
.
get_text
())
@staticmethod
def
_on_activate_link
(
_label
,
uri
):
...
...
@@ -730,10 +712,13 @@ class AdvancedSettings(Page):
def
__init__
(
self
):
Page
.
__init__
(
self
)
self
.
title
=
_
(
'
Advanced settings
'
)
self
.
complete
=
False
self
.
_ui
=
get_builder
(
'
account_wizard.ui
'
)
self
.
_ui
.
manage_proxies_button
.
connect
(
'
clicked
'
,
self
.
_on_proxy_manager
)
self
.
_ui
.
custom_host_entry
.
connect
(
'
changed
'
,
self
.
_set_complete
)
self
.
_ui
.
custom_port_entry
.
connect
(
'
changed
'
,
self
.
_set_complete
)
self
.
pack_start
(
self
.
_ui
.
advanced_grid
,
True
,
True
,
0
)
self
.
show_all
()
...
...
@@ -771,6 +756,59 @@ def get_custom_host(self):
protocol
,
ConnectionType
(
con_type
))
def
_show_host_icon
(
self
,
show
):
icon
=
'
dialog-warning-symbolic
'
if
show
else
None
self
.
_ui
.
custom_host_entry
.
set_icon_from_icon_name
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
icon
)
def
_show_port_icon
(
self
,
show
):
icon
=
'
dialog-warning-symbolic
'
if
show
else
None
self
.
_ui
.
custom_port_entry
.
set_icon_from_icon_name
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
icon
)
def
_validate_host
(
self
):
host
=
self
.
_ui
.
custom_host_entry
.
get_text
()
try
:
validate_domainpart
(
host
)
except
Exception
:
self
.
_show_host_icon
(
True
)
self
.
_ui
.
custom_host_entry
.
set_icon_tooltip_text
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
_
(
'
Invalid domain name
'
))
return
False
self
.
_show_host_icon
(
False
)
return
True
def
_validate_port
(
self
):
port
=
self
.
_ui
.
custom_port_entry
.
get_text
()
if
not
port
:
self
.
_show_port_icon
(
False
)
return
False
try
:
port
=
int
(
port
)
except
Exception
:
self
.
_show_port_icon
(
True
)
self
.
_ui
.
custom_port_entry
.
set_icon_tooltip_text
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
_
(
'
Must be a port number
'
))
return
False
if
port
not
in
range
(
0
,
65535
):
self
.
_show_port_icon
(
True
)
self
.
_ui
.
custom_port_entry
.
set_icon_tooltip_text
(
Gtk
.
EntryIconPosition
.
SECONDARY
,
_
(
'
Port must be a number between 0 and 65535
'
))
return
False
self
.
_show_port_icon
(
False
)
return
True
def
_set_complete
(
self
,
*
args
):
port_valid
=
self
.
_validate_port
()
host_valid
=
self
.
_validate_host
()
self
.
complete
=
port_valid
and
host_valid
self
.
get_toplevel
().
update_page_complete
()
class
SecurityWarning
(
Page
):
def
__init__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment