Пример #1
0
 def update_entry(self, subscriber: SubscriberUser) -> SubscriberUser:
     subscriber.email = self.email.data.lower()
     subscriber.first_name = self.first_name.data
     subscriber.last_name = self.last_name.data
     subscriber.password = SubscriberUser.make_md5_hash_from_password(
         self.password.data)
     subscriber.country = self.country.data
     subscriber.language = self.language.data
     subscriber.status = self.status.data
     subscriber.exp_date = self.exp_date.data
     subscriber.max_devices_count = self.max_devices_count.data
     return subscriber
Пример #2
0
def post_login(form: SigninForm):
    if not form.validate_on_submit():
        flash_error(form.errors)
        return render_template('home/signin.html', form=form)

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

    if check_user.status == SubscriberUser.Status.NOT_ACTIVE:
        flash_error('User not active.')
        return render_template('home/signin.html', form=form)

    if check_user.status == SubscriberUser.Status.DELETED:
        flash_error('User removed.')
        return render_template('home/signin.html', form=form)

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

    check_user.login()
    return redirect(url_for('SubscriberView:profile'))
Пример #3
0
    def remove(self):
        data = request.get_json()
        sid = data['sid']
        subscriber = SubscriberUser.objects(id=sid).first()
        if subscriber:
            subscriber.delete()
            return jsonify(status='ok'), 200

        return jsonify(status='failed'), 404
Пример #4
0
    def edit(self, sid):
        subscriber = SubscriberUser.objects(id=sid).first()
        form = SignupForm(obj=subscriber)
        if request.method == 'POST' and form.validate_on_submit():
            subscriber = form.update_entry(subscriber)
            subscriber.save()
            return jsonify(status='ok'), 200

        return render_template('subscriber/edit.html', form=form)
Пример #5
0
    def remove(self):
        data = request.get_json()
        sid = data['sid']
        subscriber = SubscriberUser.get_by_id(ObjectId(sid))
        if subscriber:
            subscriber.delete()
            return jsonify(status='ok'), 200

        return jsonify(status='failed'), 404
Пример #6
0
    def wedit(self, sid):
        subscriber = SubscriberUser.get_by_id(ObjectId(sid))
        form = SignupForm(obj=subscriber)
        if request.method == 'POST':
            old_password = subscriber.password
            form.validate_password(False)
            if form.validate_on_submit():
                subscriber = form.update_entry(subscriber)
                subscriber.password = old_password
                subscriber.save()
                return jsonify(status='ok'), 200

        return render_template('subscriber/wedit.html', form=form)
Пример #7
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/signup.html', form=form)

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

            existing_user = _get_subscriber_by_email(email)
            if existing_user:
                return redirect(url_for('HomeView:signin'))

            new_user = SubscriberUser.make_subscriber(email, form.first_name.data, form.last_name.data,
                                                      form.password.data, form.country.data, form.language.data)
            new_user.save()

            servers = ServiceSettings.objects()
            for serv in servers:
                new_user.add_server(serv)
                serv.add_subscriber(new_user)

            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/signup.html', form=form)
Пример #8
0
 def make_entry(self) -> SubscriberUser:
     return self.update_entry(SubscriberUser())
Пример #9
0
 def show(self):
     return render_template('subscriber/show.html',
                            subscribers=SubscriberUser.objects())
Пример #10
0
from pyfastocloud_models.subscriber.login.entry import SubscriberUser

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='Subscriber email')
    parser.add_argument('--first_name', help='First name')
    parser.add_argument('--last_name', help='Last name')
    parser.add_argument('--language', help='Language')
    parser.add_argument('--password', help='Subscriber password')
    parser.add_argument('--country', help='Subscriber country', default='US')

    argv = parser.parse_args()

    mongo = connect(argv.mongo_uri)
    if mongo:
        new_user = SubscriberUser.make_subscriber(email=argv.email.lower(),
                                                  first_name=argv.first_name,
                                                  last_name=argv.last_name,
                                                  password=argv.password,
                                                  country=argv.country,
                                                  language=argv.language)
        new_user.status = SubscriberUser.Status.ACTIVE
        new_user.save()