Пример #1
0
def add_user():
    if request.method == 'GET' or request.method == 'POST':
        user_name = session['user']
        manage_user = ManageUser()
        user_roles = manage_user.get_roles()
        result = ""
        if list_err in session:

            result = session[list_err]
            session.pop(list_err)
            return render_template('admin/user/add_user.html',
                                   err=result,
                                   roles=user_roles,
                                   form=request.form)
        elif list_warning in session:
            result = session[list_warning]
            session.pop(list_warning)
            return render_template('admin/user/add_user.html',
                                   warning=result,
                                   roles=user_roles,
                                   form=request.form)
        elif list_success in session:
            result = session[list_success]
            session.pop(list_success)
            return render_template('admin/user/add_user.html',
                                   success=result,
                                   roles=user_roles,
                                   form=request.form)
        else:
            form1 = AddUserForm()
            return render_template('admin/user/add_user.html',
                                   roles=user_roles,
                                   form=form1)
Пример #2
0
def save_user():
    if request.method == 'POST':
        try:
            user = User()
            user.name = request.form['name']
            user.user_name = request.form['userName']
            user.role_id = int(request.form['role'])
            user.password = request.form['userPassword']
            user.email = str(request.form['email'])
            try:
                if request.form['notify_mail'] == 'Notify':
                    user.notfiy = True
            except Exception as ex:
                user.notfiy = False
                logger.error("notify err")
            manage_user = ManageUser()
            status = manage_user.add_user(user)
            if status == ManageUserStatus.done:
                session['success'] = "ui_admin_add_user_suc"
                return redirect(url_for('user_controller.user_list'))
            elif status == ManageUserStatus.exists:
                session['err'] = "ui_admin_add_user_err_exists"
                return redirect(url_for('user_controller.add_user'), 307)
            elif status == ManageUserStatus.error:
                session['err'] = "ui_admin_add_user_err"
                return redirect(url_for('user_controller.add_user'), 307)
        except Exception as e:
            session['err'] = "ui_admin_add_user_err_exception"
            logger.error(e)
            return redirect(url_for('user_controller.add_user'), 307)
Пример #3
0
def user_list():
    mesg_err = ""
    mesg_success = ""
    mesg_warning = ""
    available_user_list = None
    user_roles = None
    user_name = session['user']
    try:
        manage_user = ManageUser()
        available_user_list = manage_user.get_users()
        user_roles = manage_user.get_roles()
        if "err" in session:
            mesg_err = session["err"]
            session.pop("err")
        elif "success" in session:
            mesg_success = session["success"]
            session.pop("success")
        elif "warning" in session:
            mesg_warning = session["warning"]
            session.pop("warning")
    except Exception as e:
        mesg_err = "error in loading page"

    return render_template('admin/user/list.html',
                           user_list=available_user_list,
                           user_roles=user_roles,
                           err=mesg_err,
                           success=mesg_success,
                           warning=mesg_warning)
Пример #4
0
def edit_user(user_id):
    if request.method == 'GET' or request.method == 'POST':
        manage_user = ManageUser()
        selected_user = manage_user.get_user(user_id)
        user_roles = manage_user.get_roles()
        return render_template('admin/user/edit_user.html',
                               roles=user_roles,
                               user=selected_user)
Пример #5
0
def remove_user(user_id):
    if request.method == 'GET' or request.method == 'POST':
        manage_user = ManageUser()
        status = manage_user.delete_user(user_id)
        if (status == ManageUserStatus.done):
            session['success'] = "ui_admin_remove_user_suc"
        else:
            session['err'] = "ui_admin_remove_user_err"

        return redirect(url_for('user_controller.user_list'))
Пример #6
0
def save_change_password():
    if request.method == 'POST':
        try:
            user_name = session['user']
            user_password = request.form['newPassword']
            manage_user = ManageUser()
            status = manage_user.update_password(user_name, user_password)
            if status == ManageUserStatus.done:
                # session['success']="Password updated successfully ."
                return redirect('/')
                return redirect(url_for('user_controller.change_password'))
            elif status == ManageUserStatus.not_exists:
                session['err'] = "ui_admin_change_password_err_not_exists"
                return redirect(url_for('user_controller.change_password'),
                                307)
            elif status == ManageUserStatus.error:
                session['err'] = "ui_admin_change_password_err"
                return redirect(url_for('user_controller.change_password'),
                                307)
        except Exception as e:
            session['err'] = "ui_admin_change_password_err_exception"
            logger.error(e)
            return redirect(url_for('user_controller.change_password'), 307)
Пример #7
0
def get_selected_user_info(user_id):
    manage_user = ManageUser()
    selected_user = manage_user.get_user(user_id)

    json_data = json.dumps(selected_user.__dict__, sort_keys=True)
    return json_data