From 90599d9566c31c257193ad4458bffd507ae52672 Mon Sep 17 00:00:00 2001 From: James Case Date: Mon, 13 Feb 2017 14:20:17 -0500 Subject: [PATCH] Adds check for valid user email for password reset. --- ooiui/core/routes/common.py | 7 +++++++ ooiui/static/js/models/common/LoginModel.js | 21 +++++++++++++++++++++ ooiui/static/js/views/common/LoginView.js | 8 ++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ooiui/core/routes/common.py b/ooiui/core/routes/common.py index b9b38b67f..0d5d31c07 100644 --- a/ooiui/core/routes/common.py +++ b/ooiui/core/routes/common.py @@ -253,6 +253,13 @@ def submit_user(): response = requests.post(app.config['SERVICES_URL'] + '/user', headers={'X-Csrf-Token' : api_key}, data=request.data) return response.text, response.status_code + +@app.route('/api/user/check_valid_email', methods=['GET']) +def check_valid_email(): + response = requests.get(app.config['SERVICES_URL'] + '/user/check_valid_email', params=request.args) + return response.text, response.status_code + + @app.route('/api/user_scope', methods=['GET']) def get_user_scopes(): token = get_login() diff --git a/ooiui/static/js/models/common/LoginModel.js b/ooiui/static/js/models/common/LoginModel.js index 9ccf074b3..4465bd20f 100644 --- a/ooiui/static/js/models/common/LoginModel.js +++ b/ooiui/static/js/models/common/LoginModel.js @@ -32,6 +32,27 @@ var LoginModel = Backbone.Model.extend({ // var self = this; // return true; //}, + checkValidEmail: function(email) { + var output = false; + $.ajax('/api/user/check_valid_email?email='+email, { + type: 'GET', + dataType: 'json', + timeout: 5000, + async: false, + success: function (resp) { + // console.log('Success getting check valid email'); + // console.log(resp); + if(resp.email !== undefined && resp.email !== ""){ + output = true + } + }, + + error: function( req, status, err ) { + console.log(req); + } + }); + return output; + }, loggedIn: function() { if(this.get('token') != '') { return true; diff --git a/ooiui/static/js/views/common/LoginView.js b/ooiui/static/js/views/common/LoginView.js index eb6a21941..6a61223a1 100644 --- a/ooiui/static/js/views/common/LoginView.js +++ b/ooiui/static/js/views/common/LoginView.js @@ -61,7 +61,7 @@ var LoginView = Backbone.View.extend({ sendResetEmail: function(e) { //console.log('hit reset inside LoginView.js'); var emailAddr = this.$el.find('#usrInput').val(); - if(emailAddr != null && emailAddr != ""){ + if(emailAddr != null && emailAddr != "" && this.model.checkValidEmail(emailAddr)){ var userEmail = {email: this.$el.find('#usrInput').val()}; //console.log(userEmail); $.ajax( '/password-reset-request', { @@ -75,7 +75,7 @@ var LoginView = Backbone.View.extend({ var m = new ModalDialogView(); m.show({ - message: "Sent password reset email successfully.", + message: "Please check your inbox for a password reset link.", type: "success" }); @@ -99,8 +99,8 @@ var LoginView = Backbone.View.extend({ } else { var errorEmailModal = new ModalDialogView(); errorEmailModal.show({ - message: "Please enter an email address above.", - type: "danger" + message: "Please check your inbox for a password reset link.", + type: "success" }); }