示例#1
0
    def edit(self, sid):
        subscriber = _get_subscriber_by_id(sid)
        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)
示例#2
0
    def subscriber_edit(self, sid):
        subscriber = Subscriber.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('service/subscriber/edit.html', form=form)
示例#3
0
    def add(self):
        form = SignupForm()
        if request.method == 'POST' and form.validate_on_submit():
            new_entry = form.make_entry()
            new_entry.servers = ServiceSettings.objects.all()
            new_entry.save()
            return jsonify(status='ok'), 200

        return render_template('subscriber/add.html', form=form)
示例#4
0
    def subscriber_add(self, sid):
        form = SignupForm()
        if request.method == 'POST' and form.validate_on_submit():
            server = ServiceSettings.objects(id=sid).first()
            if server:
                new_entry = form.make_active_entry()
                new_entry.add_server(server)

                server.add_subscriber(new_entry)
                return jsonify(status='ok'), 200

        return render_template('service/subscriber/add.html', form=form)
示例#5
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(gettext(u'Invalid email.'))
                return render_template('home/signup.html', form=form)

            existing_user = SubscriberUser.objects(email=email,
                                                   class_check=False).first()
            if existing_user:
                return redirect(url_for('HomeView:signin'))

            new_user = SubscriberUser.make_subscriber(email,
                                                      form.password.data,
                                                      form.country.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=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/signup.html', form=form)
示例#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)