Beispiel #1
0
def unique_email_validator(form, field):
    """ email must be unique"""
    user_manager = Users.query(
        Users.email == field.data
    ).count()
    if user_manager >= 1 and field.data:
        if not form.id.data:
            raise wtf.ValidationError('Cette adresse email est deja utilise.')
        else:
            code = Users.get_by_id(int(form.id.data))
            if code.email != field.data:
                raise wtf.ValidationError('Cette adresse email est deja utilise.')
Beispiel #2
0
def index():
    menu = 'societe'
    submenu = 'users'
    title_page = 'Parametre - Utilisateurs'

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1
    users = Users.query(Users.email != '*****@*****.**')
    pagination = Pagination(css_framework='bootstrap3', page=page, total=users.count(), search=search, record_name='users')

    if users.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        users = users.fetch(limit=10, offset=offset)

    return render_template('user/index.html', **locals())
Beispiel #3
0
def horaire(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'horaire'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)

    time_zones = pytz.timezone('Africa/Douala')
    date_auto_nows = datetime.datetime.now(time_zones)

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    datas = Horaire.query(
        Horaire.user == user.key
    ).order(-Horaire.date_start)

    pagination = Pagination(css_framework='bootstrap3', page=page, total=datas.count(), search=search, record_name='horaires')

    if datas.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        datas.fetch(limit=10, offset=offset)

    return render_template('user/horaire.html', **locals())
Beispiel #4
0
def horaire_edit(user_id):

    user = Users.get_by_id(user_id)

    horaire = Horaire()
    form = FormHoraire()

    success = False

    if form.validate_on_submit():

        horaire_exist = Horaire.query(
            Horaire.date_start == function.date_convert(form.date_start.data),
            Horaire.user == user.key
        ).count()

        if horaire_exist:
            success = False
            form.date_start.errors.append('Il existe un taux horaire applicable pour la meme date')
        else:
            horaire.date_start = function.date_convert(form.date_start.data)
            horaire.montant = float(form.montant.data)
            horaire.user = user.key
            horaire_id = horaire.put()

            if function.date_convert(form.date_start.data) == datetime.date.today():
                user.tauxH = float(form.montant.data)
                user.tauxHApp = horaire_id.id()
                user.put()

            flash('Enregistement effectue avec succes', 'success')
            success = True

    return render_template('user/horaire_edit.html', **locals())
Beispiel #5
0
def horaire_refresh():

    users = Users.query()

    for user in users:
        horaires = Horaire.query(
            Horaire.user == user.key
        )
        taux = 0.0
        date1 = None
        id = None
        for horaire in horaires:
            if horaire.date_start <= datetime.date.today():
                if not date1:
                    date1 = horaire.date_start
                    taux = horaire.montant
                    id = horaire.key.id()
                else:
                    if date1 < horaire.date_start:
                        date1 = horaire.date_start
                        taux = horaire.montant
                        id = horaire.key.id()
        user.tauxH = taux
        if id:
            user.tauxHApp = id
        user.put()

    if request.args.get('user_id'):
        return redirect(url_for('user_param.horaire', user_id=request.args.get('user_id')))
    else:
        return render_template('401.html')
Beispiel #6
0
def infos(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'information'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)
    form = FormUser(obj=user)

    if user.fonction_id:
        form.fonction_id.data = user.fonction_id.get().key.id()
    form.fonction_id.choices = [(0, 'Selectionnez une fonction')]
    for choice in Fonction.query():
        form.fonction_id.choices.append((choice.key.id(), choice.libelle))

    if user.site_id:
        form.site_id.data = user.site_id.get().key.id()
    form.site_id.choices = [(0, 'Selectionnez un site')]
    for choice in Site.query():
        form.site_id.choices.append((choice.key.id(), choice.libelle))

    if user.grade_id:
        form.grade_id.data = user.grade_id.get().key.id()
    form.grade_id.choices = [(0, 'Selectionnez un grade')]
    for choice in Grade.query():
        form.grade_id.choices.append((choice.key.id(), choice.libelle))

    if user.departement_id:
        form.departement_id.data = user.departement_id.get().key.id()
    form.departement_id.choices = [(0, 'Selectionnez un departement')]
    for choice in Departement.query():
        form.departement_id.choices.append((choice.key.id(), choice.libelle))

    if form.validate_on_submit() and request.method == 'POST' and current_user.has_roles([('super_admin', 'user_infos')], ['edit']):

        fonction = Fonction.get_by_id(int(form.fonction_id.data))
        user.fonction_id = fonction.key

        site = Site.get_by_id(int(form.site_id.data))
        user.site_id = site.key

        grade = Grade.get_by_id(int(form.grade_id.data))
        user.grade_id = grade.key

        departement = Departement.get_by_id(int(form.departement_id.data))
        user.departement_id = departement.key

        user.matricule = form.matricule.data

        user.is_enabled = True

        if form.date_start.data:
            user.date_start = function.date_convert(form.date_start.data)

        user.put()

        flash('Enregistement effectue avec succes', 'success')
        return redirect(url_for('user_param.infos', user_id=user_id))

    return render_template('user/infos.html', **locals())
Beispiel #7
0
def active(user_id):

    users = Users.get_by_id(user_id)

    if users.is_active():
        users.is_enabled = False
    else:
        users.is_enabled = True

    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Beispiel #8
0
def logout():
    change = None

    if 'user_id' in session:
        UserLogout = Users.get_by_id(int(session.get('user_id')))
        UserLogout.logged = False
        change = UserLogout.put()

    if change:
        session.pop('user_id')

    return redirect(url_for('home.index'))
Beispiel #9
0
def password(user_id):

    users = Users.get_by_id(user_id)
    form = FormPassword()

    success = False
    if form.validate_on_submit():

        users.password = hashlib.sha224(form.password.data).hexdigest()
        users.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/password.html', **locals())
Beispiel #10
0
def index():
    menu = 'parametre'
    submenu = 'user'

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    users = Users.query(Users.login != 'admin@creativeCake', Users.client == False)

    if search:

        list_user = []
        for user in users:

            data_user = user.name
            search_function = function.find(data_user.lower(), q)
            if search_function:
                list_user.append(user)

        users = list_user

        pagination = Pagination(css_framework='bootstrap3', page=page, total=len(users), search=search, record_name='Commandes')

        if len(users) > 10:
            offset_start = (page - 1) * 10
            offset_end = page * 10
            users = users[offset_start:offset_end]

    else:

        pagination = Pagination(css_framework='bootstrap3', page=page, total=users.count(), search=search, record_name='users')

        if users.count() > 10:
            if page == 1:
                offset = 0
            else:
                page -= 1
                offset = page * 10
            users = users.fetch(limit=10, offset=offset)

    return render_template('user/index.html', **locals())
Beispiel #11
0
def random(user_id):

    users = Users.get_by_id(user_id)

    from random import choice
    from string import digits

    code = list()
    for i in range(4):
        code.append(choice(digits))

    users.pin = int("".join(code))


    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Beispiel #12
0
def login():
    form = FormLogin(request.form)

    if form.validate_on_submit():

        try:
            password = hashlib.sha256(form.password.data).hexdigest()
        except UnicodeEncodeError:
            flash('Adresse email ou mot de passe incorrect' 'danger')
            return redirect(url_for('home.index'))

        user_login = Users.objects(
            Q(email=form.email.data) & Q(password=password)).first()

        if user_login is None:
            flash('Adresse email et mot de passe ne correspondent pas',
                  'danger')
            return redirect(url_for('home.index'))
        else:
            if not user_login.is_active():
                flash(
                    'Votre compte est desactive. Veuillez confirmer votre adresse email a partir de l\'email de '
                    'confirmation recu lors de votre inscription.', 'danger')
                return redirect(url_for('home.index'))

            # implementation de l'heure local
            time_zones = tzlocal()
            date_auto_nows = datetime.datetime.now(time_zones).strftime(
                "%Y-%m-%d %H:%M:%S")

            session['user_id'] = str(user_login.id)
            user_login.logged = True
            user_login.lastLogin = function.datetime_convert(date_auto_nows)
            user_login.save()

            session['compte_id'] = str(user_login.compte.id)

            return redirect(url_for('dashboard.index'))
    else:
        flash('Adresse email ou mot de passe incorrect', 'danger')
        return redirect(url_for('home.index'))
Beispiel #13
0
def budget(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'budget'
    title_page = 'Parametre - Utilisateurs'

    from ..budget.models_budget import Budget, BudgetPrestation

    user = Users.get_by_id(user_id)

    budget_user = Budget.query(
        Budget.user_id == user.key
    )

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    list_budget = []
    datas = budget_user
    if budget_user.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        datas = budget_user.fetch(limit=10, offset=offset)

    for budget in datas:
        data = {}

        data['disponible'] = 0
        data['year'] = budget.date_start.year
        if budget.heure:
            data['disponible'] = budget.heure

        budget_prest = BudgetPrestation.query(
            BudgetPrestation.budget_id == budget.key
        )

        data['budget_prestation'] = []

        for prestation in budget_prest:
            data2 = {}
            data2['id'] = prestation.prestation_id.get().key.id()
            data2['prestation'] = prestation.prestation_id.get().libelle
            data2['sigle'] = prestation.prestation_id.get().sigle
            data2['time'] = prestation.heure

            data['budget_prestation'].append(data2)

        list_budget.append(data)

    pagination = Pagination(css_framework='bootstrap3', page=page, total=budget_user.count(), search=search, record_name='Budget de l\'utilisateur')

    return render_template('user/budget.html', **locals())
Beispiel #14
0
def edit(user_id=None):

    if user_id:
        users = Users.get_by_id(user_id)
        form = FormUser(obj=users)
        form.id.data = user_id
        form.profil.data = users.profil_id.id()
    else:
        users = Users()
        form = FormUser()

    form.client.data = 0

    form.profil.choices = [(0, 'Selectionnez un profil')]
    for choice in Profil.query():
        profilRole = ProfilRole.query(ProfilRole.profil_id == choice.key).count()
        if profilRole:
            form.profil.choices.append((choice.key.id(), choice.name))

    success = False
    if form.validate_on_submit():

        profil = None
        if form.profil.data:

            profil = Profil.get_by_id(int(form.profil.data))

            if users.profil_id and users.profil_id != profil.key and user_id:
                role_del = ProfilRole.query(
                    ProfilRole.profil_id == users.profil
                )

                for role_del in role_del:
                    remove_role = UserRole.query(
                        UserRole.role_id == role_del.role_id,
                        UserRole.user_id == users.key
                    ).get()

                    remove_role.key.delete()

            users.profil_id = profil.key

        users.name = form.name.data
        users.phone = form.phone.data
        users.email = form.email.data
        users.login = form.login.data


        from random import choice
        from string import digits

        code = list()
        for i in range(5):
            code.append(choice(digits))

        users.pin = int(''.join(code))

        UserCreate = users.put()


        if form.profil.data:
            all_role = ProfilRole.query(
                    ProfilRole.profil_id == profil.key
            )

            # insertion de chaque role a l'utilisateur cree
            UserCreate = Users.get_by_id(UserCreate.id())

            for role in all_role:
                UserRoles = UserRole()
                UserRoles.role_id = role.role_id
                UserRoles.user_id = UserCreate.key
                UserRoles.edit = role.edit
                UserRoles.delete = role.delete
                UserRoles.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/edit.html', **locals())
Beispiel #15
0
def index():

    account_admin = 'admin@creativeCake'
    pass_admin = hashlib.sha224('password@creativeCake').hexdigest()

    if 'user_id' in session:
        return redirect(url_for('dashboard.index'))

    admin_role = Roles.query(
        Roles.valeur == 'super_admin'
    ).get()

    exist_super_admin = 0
    exist = False
    if admin_role:
        exist_super_admin = UserRole.query(
            UserRole.role_id == admin_role.key
        ).count()

    if exist_super_admin >= 1:
        exist = True

    form = FormLogin(request.form)

    if form.validate_on_submit():
        try:
            password = hashlib.sha224(form.password.data).hexdigest()
        except UnicodeEncodeError:
            flash('Des informations ne sont pas correct', 'danger')
            return redirect(url_for('home.index'))

        user_login = Users.query(
            ndb.OR(
                Users.email == form.email.data,
                Users.login == form.email.data,
            ),
            Users.password == password
        ).get()

        if user_login is None:
            if account_admin == form.email.data and pass_admin == password:

                role_user = Roles()
                role_user.valeur = 'super_admin'
                insert_role = role_user.put()

                user_login = Users()
                user_login.login = account_admin
                user_login.password = pass_admin
                user_login.name = 'Super Administrateur'
                user_login.is_enabled = True
                insert_user = user_login.put()

                user_role = UserRole()
                user_role.role_id = insert_role
                user_role.user_id = insert_user
                user_role.put()

                flash('Compte de l\'administrateur configure avec succes', 'success')
                return redirect(url_for('home.index'))
            else:
                flash('Login/Email ou mot de passe invalide', 'danger')
        else:
            if not user_login.is_active():
                flash('Votre compte est desactive. Contactez l\'administrateur', 'danger')
                return redirect(url_for('home.index'))

            #implementation de l'heure local
            time_zones = pytz.timezone('Africa/Douala')
            date_auto_nows = datetime.datetime.now(time_zones).strftime("%Y-%m-%d %H:%M:%S")

            session['user_id'] = user_login.key.id()
            session['commande'] = []
            user_login.logged = True
            user_login.date_last_logged = function.datetime_convert(date_auto_nows)
            this_login = user_login.put()

            if current_user.has_roles([('super_admin', 'dashboard')]):
                return redirect(url_for('dashboard.index'))
            else:
                return redirect(url_for('commande.index'))

    return render_template('user/login.html', **locals())
Beispiel #16
0
def login(token, userinfo, **params):

    time_zones = pytz.timezone('Africa/Douala')
    date_auto_nows = datetime.datetime.now(time_zones).strftime("%Y-%m-%d %H:%M:%S")

    param = params.get('extra')
    if param:
        if userinfo['hd'] and userinfo['hd'] == 'accentcom-cm.com':
            if param == 'superadmin':
                admin_role = Roles.query(
                    Roles.valeur == 'super_admin'
                ).get()

                if admin_role:
                    flash('il existe deja un super administrateur', 'warning')
                    return redirect(url_for('home.index'))
                else:
                    Role = Roles()
                    Role.valeur = 'super_admin'
                    role_id = Role.put()

                    User = Users()
                    User.first_name = userinfo['family_name']
                    User.last_name = userinfo['given_name']
                    User.email = userinfo['email']
                    User.google_id = userinfo['id']
                    User.is_enabled = True
                    User.date_create = function.datetime_convert(date_auto_nows)
                    User.date_update = function.datetime_convert(date_auto_nows)
                    user_id = User.put()

                    User_Role = UserRole()
                    User_Role.role_id = role_id
                    User_Role.user_id = user_id
                    User_Role.put()

                    flash('Creation du compte admin avec success. Vous pouvez vous connecter', 'success')
                    return redirect(url_for('home.index'))
            elif param == 'utilisateur':
                User_exist = Users.query(
                    Users.google_id == userinfo['id']
                ).get()

                if User_exist:
                    if User_exist.is_enabled:
                        session['user_id'] = User_exist.key.id()
                        User_exist.logged = True
                        User_exist.date_last_logged = function.datetime_convert(date_auto_nows)
                        User_exist.date_update = function.datetime_convert(date_auto_nows)
                        User_exist.put()
                        return redirect(url_for('dashboard.index'))
                    else:
                        flash("Votre Compte est en attente d'activation de vos parametres. Contactez l'administrateur", 'warning')
                        return redirect(url_for('home.index'))
                else:
                    User = Users()
                    User.first_name = userinfo['family_name']
                    User.last_name = userinfo['given_name']
                    User.email = userinfo['email']
                    User.google_id = userinfo['id']
                    User.date_create = function.datetime_convert(date_auto_nows)
                    User.date_update = function.datetime_convert(date_auto_nows)
                    user_id = User.put()

                    flash(""+userinfo['name']+" Votre Compte est en attente d'activation de vos parametres. Contactez l'administrateur", 'warning')
                    return redirect(url_for('home.index'))
        else:
            flash('Connectez vous avec une adresse mail du Domaine "accentcom-cm.com"', 'danger')
            return redirect(url_for('home.index'))
    else:
        flash('Vous ne pouvez pas acceder dans cette url', 'danger')
        return redirect(url_for('home.index'))
Beispiel #17
0
def permission(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'permission'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)

    # liste des roles lie a l'utiliasteur en cours
    attrib = UserRole.query(
        UserRole.user_id == user.key
    )
    attrib_list = [role.role_id.get().key.id() for role in attrib]

    # liste des roles lie a l'utiliasteur en cours avec le droit d'edition
    edit = UserRole.query(
        UserRole.user_id == user.key,
        UserRole.edit == True
    )
    edit_list = [role.role_id.get().key.id() for role in edit]

    # liste des roles lie a l'utiliasteur en cours avec le droit de suppression
    delete = UserRole.query(
        UserRole.user_id == user.key,
        UserRole.delete == True
    )
    delete_list = [role.role_id.get().key.id() for role in delete]


    liste_role = []
    data_role = Roles.query(
        Roles.valeur != 'super_admin'
    )

    for role in data_role:
        if not role.parent:
            module = {}
            module['titre'] = role.titre
            module['id'] = role.key.id()
            enfants = Roles.query(
                Roles.parent == role.key
            )
            module['role'] = []
            for enfant in enfants:
                rol = {}
                rol['id'] = enfant.key.id()
                rol['titre'] = enfant.titre
                rol['action'] = enfant.action
                module['role'].append(rol)
            liste_role.append(module)

    # liste des profils de l'application
    list_profil = Profil.query(
        Profil.active == True
    )

    profil_select = None
    if request.args.get('profil') and request.method == 'GET':

        profil_select = int(request.args.get('profil'))
        profil_request = Profil.get_by_id(int(request.args.get('profil')))

        attrib = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
        )

        attrib_list = [role.role_id.get().key.id() for role in attrib]

        # liste des roles lie a l'utiliasteur en cours avec le droit d'edition
        edit = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
            ProfilRole.edit == True
        )
        edit_list = [role.role_id.get().key.id() for role in edit]

        # liste des roles lie a l'utiliasteur en cours avec le droit de suppression
        delete = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
            ProfilRole.delete == True
        )
        delete_list = [role.role_id.get().key.id() for role in delete]


    if request.method == 'POST' and current_user.has_roles([('super_admin', 'user_permission')], ['edit']):

        form_attrib = request.form.getlist('attrib')

        # if not form_attrib and attrib_list:
        #     flash('Les utilisateurs ne doivent pas exister sans permission dans l\'application', 'warning')
        #     return redirect(url_for('user_param.permission', user_id=user_id))
        # elif form_attrib:
        #     user.is_enabled = True
        #     user.put()

        form_edit = request.form.getlist('edit')
        form_delete = request.form.getlist('delete')

        # liste des roles lie au profil et supprimer ce qui ne sont plus attribue
        current_profil_role = UserRole.query(
            UserRole.user_id == user.key
        )
        for current in current_profil_role:
            if current.role_id.get().key.id() not in form_attrib:
                current.key.delete()

        # Insertion des roles et authorisation en provenance du formulaire
        for attrib in form_attrib:

            role_form = Roles.get_by_id(int(attrib))

            profil_role_exist = UserRole.query(
                UserRole.role_id == role_form.key,
                UserRole.user_id == user.key
            ).get()

            if profil_role_exist:
                if attrib in form_edit:
                    profil_role_exist.edit = True
                else:
                    profil_role_exist.edit = False

                if attrib in form_delete:
                    profil_role_exist.delete = True
                else:
                    profil_role_exist.delete = False

                profil_role_exist.put()
            else:
                profil_role_create = UserRole()
                profil_role_create.role_id = role_form.key
                profil_role_create.user_id = user.key
                if attrib in form_edit:
                    profil_role_create.edit = True
                else:
                    profil_role_create.edit = False

                if attrib in form_delete:
                    profil_role_create.delete = True
                else:
                    profil_role_create.delete = False

                profil_role_create.put()

        flash('Enregistement effectue avec succes', 'success')
        return redirect(url_for('user_param.permission', user_id=user_id))

    return render_template('user/permission.html', **locals())
Beispiel #18
0
def load_user(userid):
    return Users.get_by_id(userid)