示例#1
0
    def signup(self):
        form = SignUpForm(country=get_country_code_by_remote_addr(request.remote_addr))
        if request.method == 'POST':
            if not form.validate_on_submit():
                flash_error(form.errors)
                return render_template('home/register.html', form=form)

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

            existing_user = ProviderUser.get_by_email(email)
            if existing_user:
                return redirect(url_for('HomeView:signin'))

            new_user = ProviderUser.make_provider(email=email, first_name=form.first_name.data,
                                                       last_name=form.last_name.data, password=form.password.data,
                                                       country=form.country.data,
                                                       language=form.language.data)
            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='Confirm Email', recipients=[email], html=html)
            mail.send(msg)
            flash_success('Please check email: {0}.'.format(email))
            return redirect(url_for('HomeView:signin'))

        return render_template('home/register.html', form=form)
示例#2
0
    def provider_remove(self, sid):
        data = request.get_json()
        pid = data['pid']
        provider = ProviderUser.objects(id=pid).first()
        server = ServiceSettings.objects(id=sid).first()
        if provider and server:
            server.remove_provider(provider)
            provider.remove_server(server)
            return jsonify(status='ok'), 200

        return jsonify(status='failed'), 404
示例#3
0
    def provider_add(self, sid):
        form = UserServerForm()
        if request.method == 'POST' and form.validate_on_submit():
            user = ProviderUser.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_provider(admin)
                user.add_server(server)
                return jsonify(status='ok'), 200

        return render_template('service/provider/add.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 = ProviderUser.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 == ProviderUser.Status.NO_ACTIVE:
        flash_error(gettext(u'User not active.'))
        return render_template('home/login.html', form=form)

    if not ProviderUser.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('ProviderView:dashboard'))
示例#5
0
def post_login(form: SignInForm):
    if not form.validate_on_submit():
        flash_error(form.errors)
        return render_template('home/login.html', form=form)

    email = form.email.data.lower()
    check_user = ProviderUser.get_by_email(email)
    if not check_user:
        flash_error('User not found.')
        return render_template('home/login.html', form=form)

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

    if not ProviderUser.check_password_hash(check_user.password, form.password.data):
        flash_error('Invalid password.')
        return render_template('home/login.html', form=form)

    check_user.login()
    return redirect(url_for('ProviderView:dashboard'))
示例#6
0
    def provider_remove(self, sid):
        data = request.get_json()
        pid = data['pid']
        provider = ProviderUser.get_by_id(ObjectId(pid))
        server = ServiceSettings.get_by_id(ObjectId(sid))
        if provider and server:
            server.remove_provider(provider)
            server.save()

            provider.remove_server(server)
            provider.save()
            return jsonify(status='ok'), 200

        return jsonify(status='failed'), 404
示例#7
0
 def confirm_email(self, token):
     try:
         email = self._confirm_link_generator.loads(token, salt=HomeView.SALT_LINK,
                                                    max_age=HomeView.CONFIRM_LINK_TTL)
         confirm_user = ProviderUser.get_by_email(email)
         if confirm_user:
             confirm_user.status = ProviderUser.Status.ACTIVE
             confirm_user.save()
             confirm_user.login()
             return redirect(url_for('HomeView:signin'))
         else:
             return '<h1>We can\'t find user.</h1>'
     except SignatureExpired:
         return '<h1>The token is expired!</h1>'
示例#8
0
    def provider_add(self, sid):
        form = ServerProviderForm()
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data.lower()
            provider = ProviderUser.get_by_email(email)
            server = ServiceSettings.get_by_id(ObjectId(sid))
            if server and provider:
                admin = ProviderPair(provider.id, form.role.data)
                server.add_provider(admin)
                server.save()

                provider.add_server(server)
                provider.save()
                return jsonify(status='ok'), 200

        return render_template('service/provider/add.html', form=form)
示例#9
0
def import_resellers_to_server(db, server: ServiceSettings):
    cursor = db.cursor(dictionary=True)
    sql = 'SELECT username,email,password from reg_users'
    cursor.execute(sql)
    sql_providers = cursor.fetchall()

    for sql_entry in sql_providers:
        new_user = ProviderUser.make_provider(email=sql_entry['email'],
                                              password=sql_entry['email'],
                                              country='US')
        new_user.status = ProviderUser.Status.ACTIVE
        new_user.save()

        admin = ProviderPair(new_user.id, ProviderPair.Roles.ADMIN)
        server.add_provider(admin)
        new_user.add_server(server)

    cursor.close()
示例#10
0
PROJECT_NAME = 'create_provider'

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='Provider email')
    parser.add_argument('--password', help='Provider password')
    parser.add_argument('--country', help='Provider country', default='US')
    parser.add_argument('--language', help='Provider language', default='en')

    argv = parser.parse_args()
    email = argv.email
    password = argv.password

    mongo = connect(host=argv.mongo_uri)
    if not mongo:
        sys.exit(1)

    new_user = ProviderUser.make_provider(email=email,
                                          password=password,
                                          country=argv.country,
                                          language=argv.language)
    new_user.status = ProviderUser.Status.ACTIVE
    new_user.save()
    print('Successfully created provider email: {0}, password: {1}'.format(
        email, password))
示例#11
0
def load_user(user_id):
    return ProviderUser.objects(pk=user_id).first()
示例#12
0
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='Provider email')
    parser.add_argument('--first_name', help='First name')
    parser.add_argument('--last_name', help='Last name')
    parser.add_argument('--password', help='Provider password')
    parser.add_argument('--country', help='Provider country', default='US')
    parser.add_argument('--language', help='Provider language', default='en')

    argv = parser.parse_args()
    email = argv.email.lower()
    first_name = argv.first_name
    last_name = argv.last_name
    password = argv.password

    connect(mongodb_uri=argv.mongo_uri)
    new_user = ProviderUser.make_provider(email=email,
                                          first_name=first_name,
                                          last_name=last_name,
                                          password=password,
                                          country=argv.country,
                                          language=argv.language)
    new_user.status = ProviderUser.Status.ACTIVE
    new_user.save()
    print('Successfully created provider email: {0}, password: {1}'.format(
        email, password))
示例#13
0
def load_user(user_id):
    return ProviderUser.get_by_id(ObjectId(user_id))
示例#14
0
import argparse
import os
import sys
from mongoengine import connect

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

from app.home.entry import ProviderUser

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')
    parser.add_argument('--country', help='User country', default='US')

    argv = parser.parse_args()

    mongo = connect(host=argv.mongo_uri)
    if mongo:
        new_user = ProviderUser.make_provider(email=argv.email,
                                              password=argv.password,
                                              country=argv.country)
        new_user.status = ProviderUser.Status.ACTIVE
        new_user.save()