def reset_code(): username = request.form.get("username") user = db.get_user(username) if not user: flash(messages.INVALID_USERNAME, "error") return redirect(url_for("index")) code = accounts.create_reset_code(username) url = "http://{0}{1}".format(request.headers.get("HOST"), url_for("reset", code=code)) tmpl = """ Greetings... Please click the following link to reset your password. {0} If you did not request this reset, please ignore this email and the code will automatically expire. Thanks! {1}""".format( url, config.APP_NAME ) utils.send_mail("Keymaker Password Reset", tmpl, [user.get("email")]) flash(messages.RESET_CODE_SENT, "success") return redirect(url_for("index"))
def test_delete_user_code(self): rds = utils.get_redis_connection() user = self._create_user() self.assertEqual(user.get('username'), self.test_user_username) code = accounts.create_reset_code(self.test_user_username) self.assertNotEqual(code, None) accounts.delete_reset_code(code) self.assertEqual(rds.get(accounts.RESET_CODE_KEY.format(code)), None)
def test_get_user_from_code(self): user = self._create_user() self.assertEqual(user.get('username'), self.test_user_username) code = accounts.create_reset_code(self.test_user_username) self.assertNotEqual(code, None) u = accounts.get_user_from_code(code) self.assertNotEqual(u, None) self.assertTrue(u.has_key('username'))
def reset_code(): username = request.form.get('username') user = db.get_user(username) if not user: flash(messages.INVALID_USERNAME, 'error') return redirect(url_for('index')) code = accounts.create_reset_code(username) url = 'http://{0}{1}'.format(request.headers.get('HOST'), url_for('reset', code=code)) tmpl = """ Greetings... Please click the following link to reset your password. {0} If you did not request this reset, please ignore this email and the code will automatically expire. Thanks! {1}""".format(url, config.APP_NAME) utils.send_mail('Keymaker Password Reset', tmpl, [user.get('email')]) flash(messages.RESET_CODE_SENT, 'success') return redirect(url_for('index'))
def test_create_reset_code(self): user = self._create_user() self.assertEqual(user.get('username'), self.test_user_username) code = accounts.create_reset_code(self.test_user_username) self.assertNotEqual(code, None)