Beispiel #1
0
def login_recovery(site, host, netloc, csrf):
    """
    Recovery post url
    """

    # Logout
    session = request.environ.get('beaker.session')
    session['logged_in'] = False
    session['user_id_logged_in'] = None

    # POST parameters
    email = request.POST.getunicode('email')

    # User
    try:
        user = User.get(User.email == email)
    except User.DoesNotExist:
        return dict(status=False, info='Usuário não encontrado')

    # Site
    try:
        site = Site.get(Site.user == user)
    except Site.DoesNotExist:
        return dict(status=False, info='Site não encontrado')

    # Send recovery email
    send_recovery_email(host, DEFAULT_SENDER, user)

    # Return OK
    return dict(status=True, info='Solicitado senha com sucesso. Acesse seu email para recuperar sua senha.')
Beispiel #2
0
def user_recovery_page(site, host, netloc, csrf, user_id, user_hash):
    """
    User recovery page url
    """

    # Logout
    session = request.environ.get('beaker.session')
    session['logged_in'] = False
    session['user_id_logged_in'] = None

    # User
    try:
        user = User.get(User.id == user_id, User.user_hash == user_hash)
    except User.DoesNotExist:
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Site
    try:
        site = Site.get(Site.user == user)
    except Site.DoesNotExist:
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Verify actived user and actived site
    if (not user.active) or (not site.active):
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Login
    session['logged_in'] = True
    session['user_id_logged_in'] = user.get_id()

    # Return OK
    return dict(site=site, host=host, csrf=csrf, recovery=True, user=user)
Beispiel #3
0
def user_recovery_page(site, host, netloc, csrf, user_id, user_hash):
    """
    User recovery page url
    """

    # Logout
    session = request.environ.get('beaker.session')
    session['logged_in'] = False
    session['user_id_logged_in'] = None

    # User
    try:
        user = User.get(User.id == user_id, User.user_hash == user_hash)
    except User.DoesNotExist:
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Site
    try:
        site = Site.get(Site.user == user)
    except Site.DoesNotExist:
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Verify actived user and actived site
    if (not user.active) or (not site.active):
        return dict(site=site, host=host, csrf=csrf, recovery=False)

    # Login
    session['logged_in'] = True
    session['user_id_logged_in'] = user.get_id()

    # Return OK
    return dict(site=site, host=host, csrf=csrf, recovery=True, user=user)
Beispiel #4
0
def user_recovery(site, host, netloc, csrf, logged_in, user_id_logged_in):
    """
    User recovery post url
    """

    # POST parameters
    user_id = int(request.POST.getunicode('id'))
    password1 = request.POST.getunicode('password1')
    password2 = request.POST.getunicode('password2')

    # Verify user
    if user_id_logged_in != user_id:
        # Logout
        session = request.environ.get('beaker.session')
        session['logged_in'] = False
        session['user_id_logged_in'] = None

        # Return error
        return dict(status=False, info='Sem permissão para acessar')

    # Verify password
    if password1 != password2:
        return dict(status=False, info='Senhas não coincidem')

    # User
    try:
        user = User.get(User.id == user_id)
    except User.DoesNotExist:
        return dict(status=False, info='Usuário não encontrado')

    # Site
    try:
        site = Site.get(Site.user == user)
    except Site.DoesNotExist:
        return dict(status=False, info='Site não encontrado')

    # Update user password
    try:
        if len(password1) > 0:
            user.password = md5(password1.encode('utf-8')).hexdigest()
        user.save()
    except IntegrityError as exp:
        # Return error
        return dict(status=False, info='%s' % exp)

    # Return OK
    return dict(status=True, info='Atualizado com sucesso')
Beispiel #5
0
def user_recovery(site, host, netloc, csrf, logged_in, user_id_logged_in):
    """
    User recovery post url
    """

    # POST parameters
    user_id = int(request.POST.getunicode('id'))
    password1 = request.POST.getunicode('password1')
    password2 = request.POST.getunicode('password2')

    # Verify user
    if user_id_logged_in != user_id:
        # Logout
        session = request.environ.get('beaker.session')
        session['logged_in'] = False
        session['user_id_logged_in'] = None

        # Return error
        return dict(status=False, info='Sem permissão para acessar')

    # Verify password
    if password1 != password2:
        return dict(status=False, info='Senhas não coincidem')

    # User
    try:
        user = User.get(User.id == user_id)
    except User.DoesNotExist:
        return dict(status=False, info='Usuário não encontrado')

    # Site
    try:
        site = Site.get(Site.user == user)
    except Site.DoesNotExist:
        return dict(status=False, info='Site não encontrado')

    # Update user password
    try:
        if len(password1) > 0:
            user.password = md5(password1.encode('utf-8')).hexdigest()
        user.save()
    except IntegrityError as exp:
        # Return error
        return dict(status=False, info='%s' % exp)

    # Return OK
    return dict(status=True, info='Atualizado com sucesso')
Beispiel #6
0
        def wrapper(*args, **kwargs):
            # Request host
            scheme = request.urlparts.scheme
            netloc = request.urlparts.netloc

            # Normalized host
            host = '%s://%s' % (scheme, netloc)
            if netloc.startswith('www.'):
                netloc = netloc[4:]
            normalized_host = 'http://%s' % netloc

            # Get site information
            try:
                site = Site.get(Site.id == 1)
            except Site.DoesNotExist:
                msg = 'Site %s não existe neste servidor' % host
                if json_response:
                    return dict(status=False, info=msg)
                else:
                    abort(404, msg)

            # callback function with site and host arguments injected
            kwargs.update({'site': site, 'host': host, 'netloc': netloc})
            return func(*args, **kwargs)
Beispiel #7
0
        def wrapper(*args, **kwargs):
            # Request host
            scheme = request.urlparts.scheme
            netloc = request.urlparts.netloc

            # Normalized host
            host = '%s://%s' % (scheme, netloc)
            if netloc.startswith('www.'):
                netloc = netloc[4:]
            normalized_host = 'http://%s' % netloc

            # Get site information
            try:
                site = Site.get(Site.id == 1)
            except Site.DoesNotExist:
                msg = 'Site %s não existe neste servidor' % host
                if json_response:
                    return dict(status=False, info=msg)
                else:
                    abort(404, msg)

            # callback function with site and host arguments injected
            kwargs.update({'site': site, 'host': host, 'netloc': netloc})
            return func(*args, **kwargs)
Beispiel #8
0
 def test_Create_Site(self):
   site = create_dummy_site()
   test_title = site.title
   site.save()
   site = Site.get(Site.title == test_title)
   self.assertEqual(site.uuid, site.uuid)
Beispiel #9
0

"""
Dinamic data
"""
modules_list = None
templates_dict = None

"""
Create Main Site Data
"""
MAIN_USER = None
MAIN_SITE = None
try:
    MAIN_USER = User.get(User.email == MAIN_EMAIL)
    MAIN_SITE = Site.get(Site.user == MAIN_USER)
except (User.DoesNotExist, Site.DoesNotExist) as e:
    with db.transaction():
        try:
            if not MAIN_USER:
                MAIN_USER = User.create(email=MAIN_EMAIL,
                                        password=md5(MAIN_PASSWORD.encode('utf-8')).hexdigest(),
                                        name=MAIN_NAME,
                                        active=True)
            if not MAIN_SITE:
                MAIN_SITE = Site.create(user=MAIN_USER,
                                        site_email=MAIN_EMAIL,
                                        active=True)
        except IntegrityError as ex:
            print("Main Data Fail:", ex)
Beispiel #10
0
from utils import import_modules, import_templates, send_contact_email

__author__ = 'João Neto'
"""
Dinamic data
"""
modules_list = None
templates_dict = None
"""
Create Main Site Data
"""
MAIN_USER = None
MAIN_SITE = None
try:
    MAIN_USER = User.get(User.email == MAIN_EMAIL)
    MAIN_SITE = Site.get(Site.user == MAIN_USER)
except (User.DoesNotExist, Site.DoesNotExist) as e:
    with db.transaction():
        try:
            if not MAIN_USER:
                MAIN_USER = User.create(
                    email=MAIN_EMAIL,
                    password=md5(MAIN_PASSWORD.encode('utf-8')).hexdigest(),
                    name=MAIN_NAME,
                    active=True)
            if not MAIN_SITE:
                MAIN_SITE = Site.create(user=MAIN_USER,
                                        site_email=MAIN_EMAIL,
                                        active=True)
        except IntegrityError as ex:
            print("Main Data Fail:", ex)