Skip to content

Commit

Permalink
[AdminTL#83] Login: fix email insensitive case and show error when up…
Browse files Browse the repository at this point in the history
…date password

- use lower case when store password
- show status or error to user when add/update password
  • Loading branch information
mathben committed Apr 1, 2018
1 parent 8f9d704 commit cf75db8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
6 changes: 6 additions & 0 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def post(self):
# self.redirect("/login?invalid=signup")
# return
# TODO comment when need to validate email
if email:
email = email.lower()

user = self._db.create_user(username, name=name, email=email, password=password, postal_code=postal_code)
if user:
self.give_cookie(user.get("user_id"))
Expand Down Expand Up @@ -705,6 +708,9 @@ def get(self):
return

email = self.get_argument("email", default=None)
if email:
email = email.lower()

print("Request validate auth from %s. Username %s email %s" % (self.request.remote_ip, username, email))

# TODO return a json instead of a string number
Expand Down
9 changes: 5 additions & 4 deletions src/web/partials/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ <h2>Information personnel</h2>
<div>
<div ng-show="model_profile.info && model_profile.info.password">
<h3>Modifier son mot de passe</h3>
<input type="password" ng-model="dct_profile_password.old_password" placeholder="Vieux password" required>
<input type="password" ng-model="dct_profile_password.new_password" placeholder="Nouveau password" required>
<input type="password" ng-model="model_profile.add_password.old_password" placeholder="Vieux password" required>
<input type="password" ng-model="model_profile.add_password.new_password" placeholder="Nouveau password" required>
<a ng-click="save_password()" class="btn btn-lg btn-default" role="button">Sauvegarder</a>
</div>
<div ng-show="model_profile.info && !model_profile.info.password">
<h3>Ajouter un mot de passe</h3>
<input type="password" ng-model="dct_profile_new_password.password" placeholder="Mot de passe" required>
<input type="password" ng-model="dct_profile_new_password.check_password" placeholder="Confirmation du mot de passe" required>
<input type="password" ng-model="model_profile.update_password.password" placeholder="Mot de passe" required>
<input type="password" ng-model="model_profile.update_password.check_password" placeholder="Confirmation du mot de passe" required>
<a ng-click="add_new_password()" class="btn btn-lg btn-default" role="button">Ajouter le mot de passe</a>
</div>
<a ng-show="model_profile.status_password.enabled" ng-style="model_profile.status_password.is_error ? {'color': 'red'} : {'color': 'green'}">{{! model_profile.status_password.text }}</a>
</div>
</div>
{% else %}
Expand Down
70 changes: 50 additions & 20 deletions src/web/resources/js/tl_module/profile_ctrl/profile_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

characterApp.controller("profile_ctrl", ["$scope", "$q", "$http", "$window", /*"$timeout",*/ function ($scope, $q, $http, $window) {
$scope.model_profile = {
info: {}
};

$scope.dct_profile_password = {
"old_password": "",
"new_password": ""
};

$scope.dct_profile_new_password = {
"password": "",
"check_password": ""
info: {},
add_password: {
old_password: "",
new_password: ""
},
update_password: {
password: "",
check_password: ""
},
status_password: {
text: "",
enabled: true,
is_error: false
}
};

// Get profile info
Expand All @@ -31,10 +34,10 @@ characterApp.controller("profile_ctrl", ["$scope", "$q", "$http", "$window", /*"
$scope.update_profile();

$scope.save_password = function (e) {
if ($scope.dct_profile_password.old_password != "" && $scope.dct_profile_password.new_password) {
if ($scope.model_profile.add_password.old_password != "" && $scope.model_profile.add_password.new_password) {
var data = {
"old_password": hashSha256($scope.dct_profile_password.old_password),
"new_password": hashSha256($scope.dct_profile_password.new_password)
"old_password": hashSha256($scope.model_profile.add_password.old_password),
"new_password": hashSha256($scope.model_profile.add_password.new_password)
};
// send command to server
$http({
Expand All @@ -45,16 +48,30 @@ characterApp.controller("profile_ctrl", ["$scope", "$q", "$http", "$window", /*"
timeout: 5000
}).then(function (response/*, status, headers, config*/) {
console.info(response.data);
$scope.dct_profile_password.old_password = "";
$scope.dct_profile_password.new_password = "";
$scope.model_profile.add_password.old_password = "";
$scope.model_profile.add_password.new_password = "";

$scope.model_profile.status_password.enabled = true;
if ("error" in response.data) {
$scope.model_profile.status_password.is_error = true;
$scope.model_profile.status_password.text = response.data.error;
} else if ("status" in response.data) {
$scope.model_profile.status_password.is_error = false;
$scope.model_profile.status_password.text = response.data.status;
} else {
$scope.model_profile.status_password.is_error = true;
$scope.model_profile.status_password.text = "Unknown error";
}
});
}
};

$scope.add_new_password = function (e) {
if ($scope.dct_profile_new_password.password != "" && $scope.dct_profile_new_password.password == $scope.dct_profile_new_password.check_password) {
if ($scope.model_profile.update_password.password != "" &&
$scope.model_profile.update_password.password == $scope.model_profile.update_password.check_password) {

var data = {
"password": hashSha256($scope.dct_profile_new_password.password)
"password": hashSha256($scope.model_profile.update_password.password)
};
// send command to server
$http({
Expand All @@ -65,8 +82,21 @@ characterApp.controller("profile_ctrl", ["$scope", "$q", "$http", "$window", /*"
timeout: 5000
}).then(function (response/*, status, headers, config*/) {
console.info(response.data);
$scope.dct_profile_new_password.password = "";
$scope.dct_profile_new_password.check_password = "";
$scope.model_profile.update_password.password = "";
$scope.model_profile.update_password.check_password = "";

$scope.model_profile.status_password.enabled = true;
if ("error" in response.data) {
$scope.model_profile.status_password.is_error = true;
$scope.model_profile.status_password.text = response.data.error;
} else if ("status" in response.data) {
$scope.model_profile.status_password.is_error = false;
$scope.model_profile.status_password.text = response.data.status;
} else {
$scope.model_profile.status_password.is_error = true;
$scope.model_profile.status_password.text = "Unknown error";
}

// Update profile to change view
$scope.update_profile();
});
Expand Down

0 comments on commit cf75db8

Please sign in to comment.