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.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)
Exemplo n.º 2
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>'
Exemplo n.º 3
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)
Exemplo n.º 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)

    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'))