def recover_step1_post(json): try: data = CurrentUserSchema(only=("email", )).load(json).data except ValidationError as e: return jsonify(error="validation-failed", fields=e.messages), 422 user = User.by_email_address(data["email_address"]) if not user: return jsonify(error="email-unknown"), 422 user.generate_recover_key(request.remote_addr) current_user = User.get(request.user_id) if request.user_id else None if current_user.admin: url = u"http://skylines.aero/users/recover?key=%x" % user.recover_key return jsonify(url=url) try: send_recover_mail(user) except ServiceUnavailable: return jsonify(error="mail-service-unavailable"), 503 db.session.commit() return jsonify()
def recover_step1_post(form): user = User.by_email_address(form.email_address.data) if not user: abort(404) user.generate_recover_key(request.remote_addr) send_recover_mail(user) flash( 'Check your email, we have sent you a link to recover your password.') db.session.commit() return redirect(url_for('index'))
def register_user(self, email, first_name, last_name, password, verify_password=None): form = self.open_and_fill_register_form( email, first_name, last_name, password, verify_password=verify_password ) form.submit() user = User.by_email_address(email) assert user is not None, \ "The user could not be found: %s" % email assert user.email_address == email assert user.first_name == first_name assert user.last_name == last_name
def recover_step1_post(json): try: data = CurrentUserSchema(only=("email", )).load(json).data except ValidationError as e: return jsonify(error="validation-failed", fields=e.messages), 422 user = User.by_email_address(data["email_address"]) if not user: return jsonify(error="email-unknown"), 422 user.generate_recover_key(request.remote_addr) try: send_recover_mail(user) except ServiceUnavailable: return jsonify(error="mail-service-unavailable"), 503 db.session.commit() return jsonify()
def expect_error(self, response, email='*****@*****.**', first_name='Functional', last_name='Test', password='******', verify_password=None, check_user_exists=True): form = self.open_and_fill_register_form( email, first_name, last_name, password, verify_password=verify_password ) form.submit() if check_user_exists: user = User.by_email_address(email) assert user is None, \ "The user has been created by mistake: %s" % email assert response in self.browser.contents, \ "String not found in response: %s\n%s" % \ (response, self.browser.contents)
def test_getting_by_email(test_user): """Users should be fetcheable by their email addresses""" him = User.by_email_address(test_user.email_address) assert him == test_user
if json is None: return jsonify(error='invalid-request'), 400 if 'recoveryKey' in json: return recover_step2_post(json) else: return recover_step1_post(json) def recover_step1_post(json): try: data = CurrentUserSchema(only=('email', )).load(json).data except ValidationError, e: return jsonify(error='validation-failed', fields=e.messages), 422 user = User.by_email_address(data['email_address']) if not user: return jsonify(error='email-unknown'), 422 user.generate_recover_key(request.remote_addr) try: send_recover_mail(user) except ServiceUnavailable: return jsonify(error='mail-service-unavailable'), 503 db.session.commit() return jsonify() def send_recover_mail(user):