-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#33 Defined username and password for webservice components. Improve …
…auth tests
- Loading branch information
1 parent
675adb1
commit 06f6941
Showing
11 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from webservice.properties import WSProperties | ||
|
||
|
||
class UsersDatabase(object): | ||
""" | ||
Management of username | ||
""" | ||
|
||
def __init__(self, controller): | ||
""" | ||
:param ComponentDataController controller: | ||
""" | ||
self._controller = controller | ||
|
||
self._users = self._read_data(controller) | ||
|
||
def _read_data(self, controller): | ||
if WSProperties.USER not in controller[WSProperties.DATA_KEY]: | ||
self._save_users({'pedal pi': 'pedal pi'}) | ||
|
||
return controller[WSProperties.DATA_KEY][WSProperties.USER] | ||
|
||
def _save_users(self, users): | ||
data = self._controller[WSProperties.DATA_KEY] | ||
data[WSProperties.USER] = users | ||
self._controller[WSProperties.DATA_KEY] = data | ||
|
||
def auth(self, username, password): | ||
return username in self._users \ | ||
and self._users[username] == password | ||
|
||
def update(self, username, new_password): | ||
""" | ||
Updates the user password | ||
:param string username: | ||
:param string new_password: | ||
""" | ||
if username in self._users: | ||
raise KeyError('Username "{}" not registered'.format(username)) | ||
|
||
self._users[username] = new_password | ||
self._save_users(self._users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters