Example #1
0
def reset_request():
    form = RequestResetForm()
    validated = form.validate_on_submit()

    if request.method == 'POST':
        for error, messages in form.errors.iteritems():
            for message in messages:
                flash(message, 'danger')

        if validated:
            userdoc = get_or_create_userdoc(form.email.data)

            log = get_mongoconn().Log({
                'email': userdoc['email'],
                'created': datetime.now(tz=tzutc()),
                'message': 'Requested password reset.',
                'level': 'info',
            })
            log.save()

            reset_token = uuid.uuid4().hex
            userdoc['reset_token'] = reset_token
            userdoc.save()
            send_password_reset_email(userdoc)
            flash(
                'Password reset request has been submitted successfully. '
                'Check your email.', 'success')

    return render_template('request-pw-reset.html', form=form)
Example #2
0
    def post(self):
        args = self.parser.parse_args()
        try:
            assert args.amount in data.PRICE_MAP, \
                "%s is not a valid amount" % args.amount
            assert u"id" in args.card, "missing strip transaction id"
        except AssertionError as e:
            abort(400, message=e.message)

        charge = stripe.Charge.create(
            amount=args.amount * 100,
            currency="usd",
            source=args.card['id'],
            description="Recharge for user %s" % current_user['email']
        )
        if not charge['captured']:
            log = get_mongoconn().Log({
                'created': datetime.now(tz=tzutc()),
                'email': current_user['email'],
                'level': 'error',
                'message': 'Charge error: %s' % charge
            })
            log.save()
            abort(402, message="failed to charge")

        userdoc = get_or_create_userdoc(current_user['email'])
        userdoc['transactions'].append(charge)
        userdoc['messages_remaining'] += data.PRICE_MAP[args.amount]
        userdoc.save()
        return {'message': 'successful'}
Example #3
0
 def post(self):
     self._validate()
     if not validators.validate_phone_number(self.args.number):
         abort(400, message='Number must be a US or a Canadian')
     userdoc = get_or_create_userdoc(current_user['email'])
     userdoc['phone_numbers'].append('+1%s' % self.args.number)
     userdoc.save()
     return {'message': 'saved'}
Example #4
0
 def delete(self):
     self._validate()
     userdoc = get_or_create_userdoc(current_user['email'])
     if self.args.number not in userdoc['phone_numbers']:
         abort(404, message='Number not found.')
     while self.args.number in userdoc['phone_numbers']:
         userdoc['phone_numbers'].remove(self.args.number)
     userdoc.save()
     return {'message': 'removed'}
Example #5
0
 def get(self):
     userdoc = get_or_create_userdoc(current_user['email'])
     return {
         'metadata': validators.user_model_response(userdoc),
         'administrative': {
             'full_name': ("%s %s" % (current_user['first_name'],
                                      current_user['last_name'])).title(),
             'username': current_user['email'],
             'created_at': None
         }
     }
Example #6
0
 def post(self):
     userdoc = get_or_create_userdoc(current_user['email'])
     try:
         delete_mailgun_route_by_id(userdoc['mailgun_route_id'])
     except MailgunError:
         pass
     userdoc['mailgun_route_id'] = None
     userdoc['mailhook_id'] = uuid.uuid4().hex
     resp = create_mailgun_route(**userdoc)
     userdoc['mailgun_route_id'] = resp['route']['id']
     delete_mailgun_route(**userdoc)
     userdoc['enabled'] = False
     userdoc.save()
     return {'message': 'ok'}
Example #7
0
def login_register():
    login_form = LoginForm()
    login_form_valid = login_form.validate_on_submit()
    registration_form = RegistrationForm()
    registration_form_valid = registration_form.validate_on_submit()

    if request.endpoint == 'login':
        for error, messages in login_form.errors.iteritems():
            for message in messages:
                flash("Login form - %s" % message, 'danger')

        if login_form_valid:
            user = process_login(login_form.email.data,
                                 login_form.password.data)
            if user is None:
                flash(
                    'Please check your username and password and try '
                    'again.', 'danger')
            else:
                return redirect(url_for('index'))

    if request.endpoint == 'register':
        for error, messages in registration_form.errors.iteritems():
            for message in messages:
                flash("Registration form - %s" % message, 'danger')

        if registration_form_valid:
            user_doc = get_or_create_userdoc(
                registration_form.registration_email.data)
            if user_doc.get('password') is not None:
                flash('This email address already has an account.', 'danger')
                return render_template('login-register.html',
                                       login_form=login_form,
                                       registration_form=registration_form)

            password = bytes(registration_form.password.data)
            user_doc['password'] = bcrypt.hashpw(password, bcrypt.gensalt())
            user_doc['first_name'] = registration_form.first_name.data
            user_doc['last_name'] = registration_form.last_name.data
            user_doc.save()
            user_obj = User(user_doc)
            login_user(user_obj)
            return redirect(url_for('index'))

    return render_template('login-register.html',
                           login_form=login_form,
                           registration_form=registration_form)
Example #8
0
def index():
    get_or_create_userdoc(current_user['email'])
    return render_template('user.html')
Example #9
0
 def delete(self):
     userdoc = get_or_create_userdoc(current_user['email'])
     delete_mailgun_route(**userdoc)
     userdoc['enabled'] = False
     userdoc.save()
     return {'message': 'ok'}
Example #10
0
 def post(self):
     userdoc = get_or_create_userdoc(current_user['email'])
     create_mailgun_route(**userdoc)
     userdoc['enabled'] = True
     userdoc.save()
     return {'message': 'ok'}
Example #11
0
 def get(self):
     userdoc = get_or_create_userdoc(current_user['email'])
     return {'active': userdoc['enabled']}