Exemplo n.º 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.objects(email=email).first()
            if existing_user:
                return redirect(url_for('HomeView:signin'))

            new_user = ProviderUser.make_provider(email=email, 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 4
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.objects(email=email).first()
         if confirm_user:
             confirm_user.status = ProviderUser.Status.ACTIVE
             confirm_user.save()
             login_user_wrap(confirm_user)
             return redirect(url_for('HomeView:signin'))
         else:
             return '<h1>We can\'t find user.</h1>'
     except SignatureExpired:
         return '<h1>The token is expired!</h1>'
Exemplo n.º 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)

    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'))
Exemplo n.º 6
0
def load_user(user_id):
    return ProviderUser.objects(pk=user_id).first()