Beispiel #1
0
    def handle(self, token):
        email = confirm_token(token)
        if not email:
            user_logger.debug('Password reset link expired for user {}'.format(session['user']['username']))
            flash('Password reset link is invalid or has expired.', 'danger')
            return redirect(url_for('ui.index'))

        users = self.kqueen_request('user', 'list', service=True)
        # TODO: this logic realies heavily on unique emails, this is not the case on backend right now
        # change this logic after unique contraint is introduced to backend
        filtered = [u for u in users if u.get('email', None) == email]
        if len(filtered) == 1:
            user = filtered[0]
            form = PasswordResetForm()
            if form.validate_on_submit():
                password = {'password': form.password_1.data}
                self.kqueen_request('user', 'updatepw', fnargs=(user['id'], password), service=True)
                user['active'] = True
                self.kqueen_request('user', 'update', fnargs=(user['id'], user), service=True)
                user_logger.debug('Password setted for user {}'.format(user['username']))
                flash('Password successfully updated.', 'success')
                return redirect(url_for('ui.login'))
            return render_template('ui/user_reset_password.html', form=form)
        else:
            flash('Could not match user to given e-mail.', 'danger')
        return redirect(url_for('ui.index'))
Beispiel #2
0
    def handle(self, token):
        email = confirm_token(token)
        if not email:
            user_logger.debug('Password reset link expired for user {}'.format(session['user']['username']))
            flash('Password reset link is invalid or has expired.', 'danger')
            return redirect(url_for('ui.index'))

        users = self.kqueen_request('user', 'list', service=True)
        filtered = [u for u in users if u.get('email', None) == email]
        if not filtered:
            flash('Could not match user to a given e-mail.'
                  ' Maybe invitation is canceled and user is deleted', 'danger')
            return redirect(url_for('ui.index'))

        user = filtered[0]
        form = PasswordResetForm()
        if form.validate_on_submit():
            password = {'password': form.password_1.data}
            self.kqueen_request('user', 'updatepw', fnargs=(user['id'], password), service=True)
            user['active'] = True
            self.kqueen_request('user', 'update', fnargs=(user['id'], user), service=True)
            user_logger.debug('Password is set for the {} user'.format(user['username']))
            flash('Password successfully updated.', 'success')
            return redirect(url_for('ui.login'))
        return render_template('ui/user_reset_password.html', form=form)
Beispiel #3
0
    def handle(self, token):
        email = confirm_token(token)
        if not email:
            flash('Verification link is invalid or has expired.', 'danger')
            return redirect(url_for('ui.index'))

        users = self.kqueen_request('user', 'list', service=True)
        # TODO: this logic realies heavily on unique emails, this is not the case on backend right now
        filtered = [u for u in users if u.get('email', None) == email]
        if len(filtered) == 1:
            user = filtered[0]
            if user.get('active', None):
                flash('Account already verified. Please login.', 'success')
            else:
                user['active'] = True
                self.kqueen_request('user',
                                    'update',
                                    fnargs=(user['id'], user),
                                    service=True)
                flash('You have confirmed your account. Thanks!', 'success')
        else:
            flash('No user found based on given e-mail.', 'danger')
        return redirect(url_for('ui.index'))