Пример #1
0
def remove_entry(us: User, mid: str):
    for entry in us.entries:
        if str(entry.id) == mid:
            us.entries.remove(entry)
            us.save()
            break

        __remove_from_scheduler(mid)
Пример #2
0
def sign():
    if request.method == 'POST':
        email = request.form['inputEmail']
        password = request.form['inputPassword']
        user = mongo.db.users.find_one({'email': email})
        if user:
            if User.validate_login(user['password'], password):
                user_obj = User(email)
                login_user(user_obj)
                return redirect(url_for('user.profile'))
            else:
                print('Incorrect Credentials')
        else:
            return redirect(url_for('home.register'))
    return render_template('home/sign.html')
Пример #3
0
    def signup(self):
        form = SignupForm()
        if request.method == 'POST':
            if not form.validate_on_submit():
                return render_template('home/register.html', form=form)

            email = form.email.data
            if not is_valid_email(email, False):
                flash_error(gettext(u'Invalid email.'))
                return render_template('home/register.html', form=form)

            existing_user = User.objects(email=email).first()
            if existing_user:
                return redirect(url_for('HomeView:signin'))

            hash_pass = generate_password_hash(form.password.data,
                                               method='sha256')
            new_user = User(email=email, password=hash_pass)
            new_user.save()

            token = self._confirm_link_generator.dumps(email,
                                                       salt=HomeView.SALT_LINK)

            confirm_url = url_for('HomeView:confirm_email',
                                  token=token,
                                  _external=True)
            config = app.config['PUBLIC_CONFIG']
            html = render_template(
                'home/email/activate.html',
                confirm_url=confirm_url,
                contact_email=config['support']['contact_email'],
                title=config['site']['title'],
                company=config['company']['title'])
            msg = Message(subject=gettext(u'Confirm Email'),
                          recipients=[email],
                          html=html)
            mail.send(msg)
            flash_success(gettext(u'Please check email: {0}.'.format(email)))
            return redirect(url_for('HomeView:signin'))

        return render_template('home/register.html', form=form)
Пример #4
0
def post_login(form: SigninForm):
    if not form.validate_on_submit():
        flash_error(form.errors)
        return render_template('home/login.html', form=form)

    check_user = User.objects(email=form.email.data).first()
    if not check_user:
        flash_error(gettext(u'User not found.'))
        return render_template('home/login.html', form=form)

    if check_user.status == User.Status.NO_ACTIVE:
        flash_error(gettext(u'User not active.'))
        return render_template('home/login.html', form=form)

    if not User.check_password_hash(check_user['password'],
                                    form.password.data):
        flash_error(gettext(u'Invalid password.'))
        return render_template('home/login.html', form=form)

    login_user_wrap(check_user)
    return redirect(url_for('UserView:dashboard'))
Пример #5
0
    def user_add(self, sid):
        form = UserServerForm()
        if request.method == 'POST' and form.validate_on_submit():
            user = User.objects(email=form.email.data).first()
            server = ServiceSettings.objects(id=sid).first()
            if server and user:
                admin = UserPair(user.id, form.role.data)
                server.add_user(admin)
                user.add_server(server)
                return jsonify(status='ok'), 200

        return render_template('service/user/add.html', form=form)
Пример #6
0
def __add_to_scheduler_pending_entry(us: User, entry: MoneyEntry):
    if entry.state == MoneyEntry.State.PENDING:
        __add_to_scheduler(us.id, entry)
        return

    assert (entry.state == MoneyEntry.State.APPROVED
            ), "Entry state should be APPROVED!"
    rel = __relativedelta_from_recurring(entry.recurring)
    if not rel:
        return

    date = entry.date + rel
    if date < datetime.now():
        return

    cloned = entry.clone()
    cloned.date = date
    cloned.state = MoneyEntry.State.PENDING

    us.entries.append(cloned)
    us.save()
    __add_to_scheduler(us.id, cloned)
Пример #7
0
def __recurring(uid: ObjectId, mid: str):
    us = User.objects(id=uid).first()
    if not us:
        return

    for entry in us.entries:
        if str(entry.id) == mid:
            if entry.state == MoneyEntry.State.PENDING:
                entry.state = MoneyEntry.State.APPROVED
                entry.save()

            __add_to_scheduler_pending_entry(us, entry)
            return
Пример #8
0
def confirm_email(token):
    try:
        email = confirm_link_generator.loads(token,
                                             salt=SALT_LINK,
                                             max_age=CONFIRM_LINK_TTL)
        confirm_user = User.objects(email=email).first()
        if confirm_user:
            confirm_user.status = User.Status.ACTIVE
            confirm_user.save()
            login_user(confirm_user)
            return redirect(url_for('home.login'))
        else:
            return '<h1>We can\'t find user.</h1>'
    except SignatureExpired:
        return '<h1>The token is expired!</h1>'
Пример #9
0
def sign():
    if request.method == 'POST':
        email = request.form['inputEmail']
        user_name = request.form['inputUserName']
        password = request.form['inputPassword']
        corona_table = parser()

        user = mongo.db.users.find_one({'email': email})
        if user:
            if User.validate_login(user['password'], password):
                image_location = mongo.db.users.find_one(
                    {'email': email})['image'].split('/')[-1]
                session['user-email'] = email
                session['user-name'] = user_name
                session['table-data'] = corona_table
                session['user-image'] = image_location
                user_obj = User(email)
                login_user(user_obj)
                return redirect(url_for('user.profile'))
            else:
                print('Incorrect Credentials')
        else:
            return redirect(url_for('home.register'))
    return render_template('home/sign.html')
Пример #10
0
def load_user(user_id):
    return User.objects(pk=user_id).first()
Пример #11
0
#!/usr/bin/env python3
import argparse
import os
import sys
from mongoengine import connect

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from app.home.user_loging_manager import User

PROJECT_NAME = 'test_life'

if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]')
    parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv')
    parser.add_argument('--email', help='User email')
    parser.add_argument('--password', help='User password')

    argv = parser.parse_args()

    mongo = connect(argv.mongo_uri)
    if mongo:
        hash_pass = User.generate_password_hash(argv.password)
        new_user = User(email=argv.email, password=hash_pass)
        new_user.status = User.Status.ACTIVE
        new_user.save()
Пример #12
0
def load_user(email):
    users = mongo.db.users.find_one({'email': email})
    if not users:
        return None
    return User(users['email'])
Пример #13
0
def add_entry(us: User, entry: MoneyEntry):
    us.entries.append(entry)
    us.save()
    __add_to_scheduler_pending_entry(us, entry)